在应用ArcGIS Server 的 ExportTiles 功能的时候,System/CachingControllers,System/CachingTools 运行中实例数默认是0,需要设置成1,要不然服务实例启动比较慢,下载切片的时间就会比较长。
这样下载切片的等待时间就会缩短。
相关下载java代码:
String geometryRings=object.optString(("rings"));
String wkid=((JSONObject)object.opt("spatialReference")).optString("wkid");
String featuresParam="\"features\": [{\"geometry\":{\"rings\":"+geometryRings+",\"spatialReference\":{\"wkid\":"+wkid+"}}}]";
String params="exportTiles?tilePackage=true&exportExtent=&optimizeTilesForSize=true&compressionQuality=60&exportBy=levelId&levels=10-16&areaOfInterest={"+featuresParam+"}&f=json";
if(this.getDefaultCity().getBasemap().contains("China5Gather")){
params="exportTiles?tilePackage=true&exportExtent=&optimizeTilesForSize=true&compressionQuality=60&exportBy=levelId&levels=10-17&areaOfInterest={"+featuresParam+"}&f=json";
}
//提交下载任务
Request request = new Request.Builder()
.url(baseUrl+params)
.build();
Response response = client.newCall(request).execute();
if(response.isSuccessful()){
String json=response.body().string();
JSONObject jobok=new JSONObject(json);//{"jobId": "jeeb938cbb2774269a7ca9910df4ee700", "jobStatus": "esriJobSubmitted"}
String jobIdEt=jobok.optString("jobId");
//获取下载的进度,监听完成
//http://serverurl/arcgis/rest/services/World_Street_Map/MapServer/jobs/j1fb60facc9194208929f90a7fd64fc9d_et?f=json
String jobId = createTilesStatus(baseUrl, client, jobIdEt, 0);
if(jobId==null){
return false;
}
//获取tpk的下载路径
//http://serverurl/arcgis/rest/services/World_Street_Map/MapServer/exportTiles/jobs/j1fb60facc9194208929f90a7fd64fc9d/results/out_service_url?f=json
Request request2 = new Request.Builder()
.url(baseUrl+"exportTiles/jobs/"+jobId+"/results/out_service_url?f=json")
.build();
Response response2 = client.newCall(request2).execute();
String json2=response2.body().string();
JSONObject jobok2=new JSONObject(json2);
//下载tpk到指定目录
Request request3 = new Request.Builder()
.url(jobok2.optString("value")+"/Layers.tpk")
.build();
String dSt = DateUtils.getDateTime();
System.out.println(jobId + " ------------------ downloading " + dSt);
Response response3 = client.newCall(request3).execute();
String root = System.getProperty("catalina.home")
+ File.separator + "webapps" + File.separator + "addr_collect";
File folderRoot=new File(root);
// 如果文件夹不存在则创建
if (!folderRoot.exists() && !folderRoot.isDirectory()) {
folderRoot.mkdir();
}
String path = root + File.separator + areaId;
File folder=new File(path);
// 如果文件夹不存在则创建
if (!folder.exists() && !folder.isDirectory()) {
folder.mkdir();
}
File file=new File(path+File.separator+uuid+".tpk");
FileCopyUtils.copy(response3.body().bytes(), file);
System.out.println(jobId + " ------------------ "+ path+File.separator+uuid+".tpk");
System.out.println(jobId + " ------------------ "+ FileSizeHelper.getHumanReadableFileSize(file.length()));
String dEd = DateUtils.getDateTime();
System.out.println(jobId + " ------------------ copy end, " + dEd + ",used "+ DateUtils.getTimeDiffSec(dSt, dEd) +" sec");
//jobStatus
//esriJobSucceeded
/**
* 监听切片生产进度
* @param baseUrl
* @param client
* @param jobIdEt
* @return
* @throws IOException
*/
private String createTilesStatus(String baseUrl, OkHttpClient client,
String jobIdEt,int counts) throws IOException {
Request request1 = new Request.Builder()
.url(baseUrl+"/jobs/"+jobIdEt+"?f=json")
.build();
Response response1 = client.newCall(request1).execute();
String json1=response1.body().string();
JSONObject jobok1=new JSONObject(json1);
String jobStatus=jobok1.optString("jobStatus");
String jobId=jobok1.optString("jobId");
System.out.println(jobId + " ------------------ " + jobStatus);
String str = null;
if("esriJobSucceeded".equals(jobStatus)){
str = jobId.replace("_et", "");
}else{
try {
Thread.sleep(1000);
if(counts < 60){
return createTilesStatus(baseUrl, client, jobIdEt,counts+1);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
return str;
}