c102032f by chiangbt

update1

1 parent 8aced3b1
......@@ -121,4 +121,7 @@
</item>
</group>
</component>
<component name="uidesigner-configuration">
<option name="DEFAULT_LAYOUT_MANAGER" value="CardLayout" />
</component>
</project>
\ No newline at end of file
......
No preview for this file type
......@@ -10,7 +10,9 @@ TiandituDownload tiandituDownload = new TiandituDownload("my.db");
Point pt = new Point(29.76,106.64);
Point pt2 = new Point(35.33, 108.12);
// 下载器
// 2 为最小level,9为最大level,
tiandituDownload.Download(pt, pt2, 2,9, TianDiTuTiledMapServiceType.IMG_C);
// 2 为最小level,9为最大level
// TianDiTuTiledMapServiceType.IMG_C 为下载数据类型
// 最后一个参数为merge,为true时,会将地图及其注记一并下载融合到一张图片中去
tiandituDownload.Download(pt, pt2, 2,9, TianDiTuTiledMapServiceType.IMG_C, true);
```
\ No newline at end of file
......
......@@ -3,7 +3,7 @@ import utils.TianDiTuTiledMapServiceType;
import java.sql.SQLException;
public class Main {
public class Main{
public static void main(String[] args) throws SQLException {
......@@ -12,7 +12,6 @@ public class Main {
TiandituDownload tiandituDownload = new TiandituDownload("my.db");
Point pt = new Point(29.76,106.64);
Point pt2 = new Point(35.33, 108.12);
// tiandituDownload.Download(pt, pt2, 9, utils.TianDiTuTiledMapServiceType.IMG_C);
tiandituDownload.Download(pt, pt2, 2,11, TianDiTuTiledMapServiceType.IMG_C);
tiandituDownload.Download(pt, pt2, 2,9, TianDiTuTiledMapServiceType.VEC_C, true);
}
}
......
......@@ -3,8 +3,13 @@ import utils.Point;
import utils.TDTUrl;
import utils.TianDiTuTiledMapServiceType;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.*;
......@@ -81,7 +86,7 @@ public class TiandituDownload {
return new CalEnv(startX, startY);
}
private void Download(Point minPoint, Point maxPoint, int level, TianDiTuTiledMapServiceType type){
private void Download(Point minPoint, Point maxPoint, int level, TianDiTuTiledMapServiceType type, boolean merge){
try{
CalEnv startEnv = calculateEnv(minPoint, level);
......@@ -108,6 +113,32 @@ public class TiandituDownload {
// 获得地图瓦片
byte[] img = getTile(url);
System.out.println("正在下载 "+url);
// 如果merge为true,则在下载img_c或vec_c时将其注记图片一并下载
if(merge) {
InputStream img_stream = new ByteArrayInputStream(img);
BufferedImage bImageFromConvert = ImageIO.read(img_stream);
String url2 = "";
if(type == TianDiTuTiledMapServiceType.IMG_C) {
url2 = new TDTUrl(level, i, j, TianDiTuTiledMapServiceType.CIA_C).generatUrl();
}else{
url2 = new TDTUrl(level, i, j, TianDiTuTiledMapServiceType.CVA_C).generatUrl();
}
byte[] img2 = getTile(url2);
InputStream img_stream2 = new ByteArrayInputStream(img2);
BufferedImage bImageFromConvert2 = ImageIO.read(img_stream2);
Graphics g = bImageFromConvert.getGraphics();
g.drawImage(bImageFromConvert, 0, 0, null);
g.drawImage(bImageFromConvert2, 0, 0, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bImageFromConvert, "jpg", baos);
baos.flush();
img = baos.toByteArray();
baos.close();
}
// 将数据写入sqlite
String insertSQL = "INSERT INTO "+ type + "(TILELEVEL,TILECOL,TILEROW,TILEDATA) VALUES (?,?,?,?)";
preparedStatement = conn.prepareStatement(insertSQL);
......@@ -128,7 +159,7 @@ public class TiandituDownload {
}
}
public void Download(Point minPoint, Point maxPoint, int minLevel, int maxLevel, TianDiTuTiledMapServiceType type) throws SQLException {
public void Download(Point minPoint, Point maxPoint, int minLevel, int maxLevel, TianDiTuTiledMapServiceType type, boolean merge) throws SQLException {
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:" + this.dbpath);
......@@ -144,7 +175,7 @@ public class TiandituDownload {
stmt.close();
for(int m = minLevel; m<= maxLevel; m++){
this.Download(minPoint, maxPoint, m, type);
this.Download(minPoint, maxPoint, m, type, merge);
}
conn.close();
System.out.println("下载完成");
......