安卓智能地图开发与实施十五:离线与同步 - ArcGIS Runtime SDK for Android(Version 100.0.0)

0
分享 2017-08-21
离线与同步(GeodatabaseSyncTask)
针对编辑,上一节中凡事离线的,各种添加、更新、删除等都是针对终端上存储的离线数据。可以在没有网络的环境下完成,当具备网络时,还需同步到ArcGIS Server服务器中对应的要素服务(Feature Service)。
创建GeodatabaseSyncTask
private void createGeodatabaseSyncTask() {
// Create a GeodatabaseSyncTask and add a done loading listener
geodatabaseSyncTask = new GeodatabaseSyncTask(FEATURE_SERVICE_URL);
geodatabaseSyncTask.addDoneLoadingListener(new Runnable() {
@Override public void run() {
// Check if it failed to load. If its not in the failed state, inside a done loading listener the only other
// valid state is loaded
if (geodatabaseSyncTask.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
dealWithException(geodatabaseSyncTask.getLoadError());
}
else
{
// Now the sync task is loaded, use it to create GenerateGeodatabaseParameters, or sync changes
generateGeodatabaseParameters();
}
}
});
// Load the sync task
geodatabaseSyncTask.loadAsync();
}

设置离线参数
指定范围、只保留第一个图层。
private void generateGeodatabaseParameters() {
// Create GenerateGeodatabaseParameters from the GeodatabaseSyncTask using current map extent
Envelope generateExtent = mapView.getVisibleArea().getExtent();
final ListenableFuture<GenerateGeodatabaseParameters> generateParamsFuture =
geodatabaseSyncTask.createDefaultGenerateGeodatabaseParametersAsync(generateExtent);
generateParamsFuture.addDoneListener(new Runnable() {
@Override
public void run() {
try {
generateParams = generateParamsFuture.get();
// Change GenerateGeodatabaseParameters as required - e.g. removes all layers except first from the sync
for (int i = generateParams.getLayerOptions().size() -1; i >= 1; i--) {
generateParams.getLayerOptions().remove(i);
}
// Now the parameters are prepared, use them with the sync task to generate a geodatabase
generateGeodatabase();
}
catch (InterruptedException | ExecutionException e) {
dealWithException(e);
}
}
});
}

获取离线数据
private void generateGeodatabase() {
// Download a copy of the geodatabase to the specified path, using prepared parameters
generateJob = geodatabaseSyncTask.generateGeodatabaseAsync(generateParams, GDB_PATH);
// Add listener to check and report on the current download status
generateJob.addJobChangedListener(new Runnable() {
@Override
public void run() {
// Deal with any errors found while generating the geodatabase
if (generateJob.getError() != null) {
dealWithException(generateJob.getError());
}
else {
// While job is in progress, review job messages or update progress in logs or user interface...
updateUiWithJobProgress(generateJob);
}
}
});
// Add listener to deal with the completed job
generateJob.addJobDoneListener(new Runnable() {
@Override
public void run() {
// Check the job state is complete, deal with any errors
if ((generateJob.getStatus() != Job.Status.SUCCEEDED) || (generateJob.getError() != null)) {
dealWithException(generateJob.getError());
}
else {
// Get the completed Geodatabase from the job
if (generateJob.getResult() instanceof Geodatabase) {
Geodatabase syncResultGdb = (Geodatabase) generateJob.getResult();
geodatabase = syncResultGdb;
// Use the geodatabase, for example, load it and create FeatureLayers based on the tables it contains
loadGeodatabase();
}
}
}
});
// Start the Job to generate the geodatabase
generateJob.start();
}

设置同步参数
private void createSyncParameters() {
// Create SyncGeodatabaseParameters based on default parameters from the sync tasks
final ListenableFuture<SyncGeodatabaseParameters> syncParamsFuture = geodatabaseSyncTask
.createDefaultSyncGeodatabaseParametersAsync(geodatabase);
syncParamsFuture.addDoneListener(new Runnable() {
@Override
public void run() {
try
{
// Retrieve the SyncGeodatabaseParameters from the future
syncParams = syncParamsFuture.get();
// Continue on to sync the database using the parameters
syncGeodatabase();
}
catch (InterruptedException | ExecutionException e) {
dealWithException(e);
}
}
});
}

同步离线编辑
private void syncGeodatabase() {
// Start the sync operation on the geodatabase
syncJob = geodatabaseSyncTask.syncGeodatabaseAsync(syncParams, geodatabase);
// Add listener to check and report on the current sync status
syncJob.addJobChangedListener(new Runnable() {
@Override
public void run() {
// Deal with any errors found while syncing the geodatabase
if (syncJob.getError() != null) {
dealWithException(syncJob.getError());
}
else {
// While job is in progress, review job messages or update progress in logs or user interface...
updateUiWithJobProgress(syncJob);
}
}
});
// Add listener to deal with the completed job
syncJob.addJobDoneListener(new Runnable() {
@Override
public void run() {
// Check the job state is complete, deal with any errors
if ((syncJob.getStatus() != Job.Status.SUCCEEDED) || (syncJob.getError() != null)) {
dealWithException(syncJob.getError());
}
else {
// Get the SyncLayerResults returned from the sync
List<SyncLayerResult> syncResults = (List<SyncLayerResult>) syncJob.getResult();
if (syncResults != null) {
// Check sync results, for example update the UI to inform the user
dealWithSyncResults(syncResults);
}
}
}
});
// Start the Job to sync the geodatabase

 
 安卓智能地图开发与实施一:配置离线SDK - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3304
 安卓智能地图开发与实施二:开发环境准备 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3303
 安卓智能地图开发与实施三:创建第一个地图程序 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3302
 安卓智能地图开发与实施四:二维地图的MapView与Layers - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3305
 安卓智能地图开发与实施五:在线基础底图 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3309
 安卓智能地图开发与实施六:离线基础底图 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3299
 安卓智能地图开发与实施七:在线业务图层(浏览查询) - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3298
 安卓智能地图开发与实施八:离线业务图层(浏览查询) - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3297
 安卓智能地图开发与实施九:地图缩放与旋转 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3296
 安卓智能地图开发与实施十:图层管理 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3295
 安卓智能地图开发与实施十一:业务数据查询 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3294
 安卓智能地图开发与实施十二:空间查询与模糊搜索 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3293
 安卓智能地图开发与实施十三:空间查询与展示 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3308
 安卓智能地图开发与实施十四:业务数据编辑 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3307
 安卓智能地图开发与实施十五:离线与同步 - ArcGIS Runtime SDK for Android(Version 100.0.0) :http://zhihu.esrichina.com.cn/article/3306
 安卓智能地图开发与实施十六:三维地图 - ArcGIS Runtime SDK for Android(Version 100.1.0) :http://zhihu.esrichina.com.cn/article/3289
 安卓智能地图开发与实施十七:使用天地图 - ArcGIS Runtime SDK for Android(Version 100.1.0) :http://zhihu.esrichina.com.cn/article/3288
 安卓智能地图开发与实施十八:空间要素绘制 - ArcGIS Runtime SDK for Android(Version 100.1.0) :http://zhihu.esrichina.com.cn/article/3287
 安卓智能地图开发与实施十九:符号与渲染器 - ArcGIS Runtime SDK for Android(Version 100.1.0) :http://zhihu.esrichina.com.cn/article/3286
文章来源:http://blog.csdn.net/allenlu2008/article/details/73321258

0 个评论

要回复文章请先登录注册