提交 3503c78b authored 作者: 张航's avatar 张航

添加了坐标错误的校验,Jar包版本基本完成

上级 d70f666b
...@@ -59,13 +59,25 @@ public class DownMap implements ApplicationRunner { ...@@ -59,13 +59,25 @@ public class DownMap implements ApplicationRunner {
es = Executors.newFixedThreadPool(threadNum); es = Executors.newFixedThreadPool(threadNum);
completionService = new ExecutorCompletionService<>(es); completionService = new ExecutorCompletionService<>(es);
// 监听控制台输入下载区域 // 监听控制台输入下载区域
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
System.out.println("经纬度格式如: 110.391,36.527"); System.out.println("经纬度格式如: 110.391,36.527");
String leftbottom = null;
String righttop = null;
while (true) {
System.out.println("请输入要下载地图的左下角经纬度:"); System.out.println("请输入要下载地图的左下角经纬度:");
String leftbottom = sc.next(); leftbottom = sc.next();
System.out.println("请输入要下载地图的右上角经纬度:"); System.out.println("请输入要下载地图的右上角经纬度:");
String righttop = sc.next(); righttop = sc.next();
String errMsg = verify(leftbottom,righttop);
// 简单校验下载是否正确
if (errMsg == null){
break;
}
System.out.println(errMsg);
System.out.println("请重新输入!");
}
System.out.println("开始下载经纬度: {" + leftbottom + "," + righttop + "}"); System.out.println("开始下载经纬度: {" + leftbottom + "," + righttop + "}");
// 左下角经度,纬度,右上角经度,纬度。 // 左下角经度,纬度,右上角经度,纬度。
...@@ -81,12 +93,12 @@ public class DownMap implements ApplicationRunner { ...@@ -81,12 +93,12 @@ public class DownMap implements ApplicationRunner {
for (int z = minLv; z <= maxLv; z++) { // 层级 for (int z = minLv; z <= maxLv; z++) { // 层级
//计算行列号(使用瓦片的中心点经纬度计算) //计算行列号(使用瓦片的中心点经纬度计算)
//四个坐标划定了一个矩形区域 //四个坐标划定了一个矩形区域
int minY = getOSMTileYFromLatitude(Double.valueOf(rightLngLat[0].trim()), z); int minY = getOSMTileYFromLatitude(Double.valueOf(rightLngLat[1].trim()), z);
int maxY = getOSMTileYFromLatitude(Double.valueOf(leftLngLat[1].trim()), z); int maxY = getOSMTileYFromLatitude(Double.valueOf(leftLngLat[1].trim()), z);
int minX = getOSMTileXFromLongitude(Double.valueOf(leftLngLat[0].trim()), z); int minX = getOSMTileXFromLongitude(Double.valueOf(leftLngLat[0].trim()), z);
int maxX = getOSMTileXFromLongitude(Double.valueOf(rightLngLat[0].trim()), z); int maxX = getOSMTileXFromLongitude(Double.valueOf(rightLngLat[0].trim()), z);
for (int y = minY; y <= maxY; y++) { // Y轴 for (int x = minX; x <= maxX; x++) { // Y轴
for (int x = minX; x <= maxX; x++) { // X轴 for (int y = minY; y <= maxY; y++) { // X轴
// 多线程异步执行下载 // 多线程异步执行下载
Future<String> resultFulture = completionService.submit(new DownMapCallable(z, x, y)); Future<String> resultFulture = completionService.submit(new DownMapCallable(z, x, y));
// 加入集合中 // 加入集合中
...@@ -116,6 +128,24 @@ public class DownMap implements ApplicationRunner { ...@@ -116,6 +128,24 @@ public class DownMap implements ApplicationRunner {
System.exit(0); System.exit(0);
} }
// 校验格式是否正确
private String verify(String leftbottom, String righttop) {
String[] leftLngLat = leftbottom.contains(",") ? leftbottom.split(",") : leftbottom.split(",");
String[] rightLngLat = righttop.contains(",") ? righttop.split(",") : righttop.split(",");
// 左下角经纬度
Double leftLng = Double.valueOf(leftLngLat[0].trim());
Double leftLat = Double.valueOf(leftLngLat[1].trim());
// 右上角经纬度
Double rightLng = Double.valueOf(rightLngLat[0].trim());
Double rightLat = Double.valueOf(rightLngLat[1].trim());
if (leftLng > rightLng || leftLat > rightLat){
return "坐标错误,右上角的精度和纬度必须大于左下角的精度和纬度!";
}
return null;
}
/** /**
* 计算分辨率 * 计算分辨率
* *
...@@ -171,10 +201,11 @@ public class DownMap implements ApplicationRunner { ...@@ -171,10 +201,11 @@ public class DownMap implements ApplicationRunner {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
String imgUrl = null; String imgUrl = null;
File file = null;
try { try {
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
imgUrl = CLStringUtil.getImgUrl(z, x, y); imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = appendFlag ? CLStringUtil.getFullFileNotExist(z,x,y):CLStringUtil.getFullFile(z, x, y); file = appendFlag ? CLStringUtil.getFullFileNotExist(z,x,y):CLStringUtil.getFullFile(z, x, y);
// 开始下载地图 // 开始下载地图
if (file != null){ if (file != null){
...@@ -184,6 +215,9 @@ public class DownMap implements ApplicationRunner { ...@@ -184,6 +215,9 @@ public class DownMap implements ApplicationRunner {
return imgUrl + " Loaded"; return imgUrl + " Loaded";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
if (file != null && file.exists()){
file.delete();
}
errResults.add("Failed: " + imgUrl + " ErrorMsg >> " + e.getMessage()); errResults.add("Failed: " + imgUrl + " ErrorMsg >> " + e.getMessage());
return imgUrl + " Down Failed"; return imgUrl + " Down Failed";
} }
......
...@@ -30,8 +30,8 @@ public class DownMapLv3 { ...@@ -30,8 +30,8 @@ public class DownMapLv3 {
**/ **/
public static void downLoad() { public static void downLoad() {
new Thread(() -> { new Thread(() -> {
for (int y = 0; y <= 7; y++) { // Y轴 for (int x = 0; x <= 7; x++) { // Y轴
for (int x = 0; x <= 7; x++) { // X轴 for (int y = 0; y <= 7; y++) { // X轴
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFile(z, x, y); File file = CLStringUtil.getFullFile(z, x, y);
......
...@@ -29,8 +29,8 @@ public class DownMapLv4 { ...@@ -29,8 +29,8 @@ public class DownMapLv4 {
**/ **/
public static void downLoad() { public static void downLoad() {
new Thread(() -> { new Thread(() -> {
for (int y = 0; y <= 9; y++) { // Y轴 for (int x = 0; x <= 15; x++) { // Y轴
for (int x = 0; x <= 15; x++) { // X轴 for (int y = 0; y <= 9; y++) { // X轴
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFile(z, x, y); File file = CLStringUtil.getFullFile(z, x, y);
......
...@@ -25,8 +25,8 @@ public class DownMapLv5 { ...@@ -25,8 +25,8 @@ public class DownMapLv5 {
**/ **/
public static void downLoad() { public static void downLoad() {
new Thread(() -> { new Thread(() -> {
for (int y = 10; y <= 23; y++) { // Y轴 for (int x = 15; x <= 31; x++) { // Y轴
for (int x = 15; x <= 31; x++) { // X轴 for (int y = 10; y <= 23; y++) { // X轴
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFile(z, x, y); File file = CLStringUtil.getFullFile(z, x, y);
......
...@@ -25,8 +25,8 @@ public class DownMapLv6 { ...@@ -25,8 +25,8 @@ public class DownMapLv6 {
**/ **/
public static void downLoad() { public static void downLoad() {
new Thread(() -> { new Thread(() -> {
for (int y = 20; y <= 28; y++) { // Y轴 for (int x = 45; x <= 57; x++) { // Y轴
for (int x = 45; x <= 57; x++) { // X轴 for (int y = 20; y <= 28; y++) { // X轴
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFile(z, x, y); File file = CLStringUtil.getFullFile(z, x, y);
......
...@@ -77,36 +77,4 @@ public class HttpUtil { ...@@ -77,36 +77,4 @@ public class HttpUtil {
} }
public static void writeFromStream(InputStream is, File file) {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
// 下载图片到本地存储
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(new FileOutputStream(file));
byte[] buffer = new byte[1024];
int len = -1;
//while ((len = bis.read(buffer)) != -1) {
while ((len = bis.read(buffer)) > 0) {
bos.write(buffer, 0, len);
bos.flush();
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
// 释放资源
if (bos != null){
bos.close();
}
if (bis != null){
bis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
} }
server:
port: 8081
\ No newline at end of file
# 下载地图的保存路径 # 下载地图的保存路径
file.basepath=E:/gaode-map/img/ file.basepath=E:/gaode-map/jinshui/
# 下载地图的地址 # 下载地图的地址
#天地图服务器t0-t8间选一个 #天地图服务器t0-t8间选一个
...@@ -18,8 +18,8 @@ map.baseurl=http://webrd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1scale=1&s ...@@ -18,8 +18,8 @@ map.baseurl=http://webrd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1scale=1&s
map.type=CUSTOM map.type=CUSTOM
# 下载地图的层级 7 - 18 # 下载地图的层级 7 - 18
map.minLv=14 map.minLv=15
map.maxLv=14 map.maxLv=15
# 线程数 # 线程数
map.threadNum=2000 map.threadNum=2000
...@@ -30,5 +30,5 @@ map.Lv6.flag=false ...@@ -30,5 +30,5 @@ map.Lv6.flag=false
# 是否继续下载 # 是否继续下载
map.download.append=false map.download.append=false
# 这个注释用来备注下下载地图的经纬度 # 这个注释用来备注下下载地图的经纬度(注意: 不要写错了),
# left: 113.587,34.694 right: 113.801,34.799 # left: 113.629,34.750 right: 113.911,34.909
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,6 @@ http.connectTimeout=60000 ...@@ -7,6 +7,6 @@ http.connectTimeout=60000
#从连接池中获取到连接的最长时间 #从连接池中获取到连接的最长时间
http.connectionRequestTimeout=6000000 http.connectionRequestTimeout=6000000
#数据传输的最长时间 #数据传输的最长时间
http.socketTimeout=120000 http.socketTimeout=12000000
#提交请求前测试连接是否可用 #提交请求前测试连接是否可用
http.staleConnectionCheckEnabled=true http.staleConnectionCheckEnabled=true
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论