0

令我惊讶的是,ArcGIS 为 iOS 提供了所有教程文档,但没有为 Android 提供。在这里,我得到了我想要的 iOS 示例 -

iOS 中的离线编辑和同步

但没有适用于 Android 的教程。虽然我可以通过以下代码下载 ArcGIS 在线地图并离线显示 -

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMapView = (MapView) findViewById(R.id.mapView);
    imageButton =   (ImageButton)   findViewById(R.id.imageButton);
    onlineBtn   =   (Button)   findViewById(R.id.onlineBtn);
    offlineBtn  =   (Button)   findViewById(R.id.offlineBtn);
    /*ArcGISMap map = new ArcGISMap(Basemap.Type.IMAGERY_WITH_LABELS_VECTOR, 34.056295, -117.195800, 16);
    mMapView.setMap(map);*/
    showOnlineMap();

    offlineBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LoadOfflineMap  loadOffline =   new LoadOfflineMap(mMapView, map, tiledLayer, geodatabase, MainActivity.this);
            loadOffline.loadOfflineMap();
        }
    });

    onlineBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showOnlineMap();
            //startActivity(new Intent(MainActivity.this, OfflineGeocodeActivity.class));
        }
    });

}

private void showOnlineMap() {

    //--- create new Tiled Layer from service url
    tiledLayer = new ArcGISTiledLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
    //--- set tiled layer as basemap
    Basemap basemap = new Basemap(tiledLayer);
    //--- create a map with the basemap
    map = new ArcGISMap(basemap);
    map.setInitialViewpoint(new Viewpoint(37.7749, -122.4194, 1));

    //--- set the map to be displayed in this view
    mMapView.setMap(map);

// this.addFeatureLayersFromURL(" https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/ "); this.addFeatureLayersFromURL(" https://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer/ ");

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DownloadMap dwnMap  =   new DownloadMap(syncTask,MainActivity.this,mMapView,geodatabase);
            dwnMap.downloadMapOverlays();
        }
    });

    /*final Button btnDownload = new Button(cordova.getActivity());
    btnDownload.setText("Download");
    btnDownload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Toast.makeText(cordova.getActivity(), "Download will start", Toast.LENGTH_LONG).show();
            cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    progressDialog.setMessage("Request to server..");
                    progressDialog.show();
                }
            });

            downloadMapOverlays();
        }
    });

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            cordova.getActivity().addContentView(mapView, new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));

            cordova.getActivity().addContentView(btnDownload, new LinearLayout.LayoutParams(500, 100));
        }
    });

    Toast.makeText(cordova.getActivity(), message, Toast.LENGTH_LONG).show();
    callbackContext.success(message);
} else {
    Toast.makeText(cordova.getActivity(), "Plugin Error", Toast.LENGTH_LONG).show();
    callbackContext.error("Expected one non-empty string argument.");
}*/
}

/****
 * Add feature Layer on ArcGIS Map
 * @param url
 */
private void addFeatureLayersFromURL(final String url) {
    syncTask = new GeodatabaseSyncTask(url);
    syncTask.loadAsync();
    syncTask.addDoneLoadingListener(new Runnable() {
        @Override
        public void run() {
            for (int count = 0; count < syncTask.getFeatureServiceInfo().getLayerInfos().size(); count++) {
                IdInfo layerInfo = syncTask.getFeatureServiceInfo().getLayerInfos().get(count);
                String layerURL = url.concat(String.valueOf(count));
                ServiceFeatureTable table = new ServiceFeatureTable(layerURL);
                FeatureLayer layer = new FeatureLayer(table);
                layer.setName(layerInfo.getName());
                map.getOperationalLayers().add(layer);
            }
        }
    });
}

@Override
protected void onPause(){
    mMapView.pause();
    super.onPause();
}

@Override
protected void onResume(){
    super.onResume();
    mMapView.resume();
}

之后我想编辑离线和在线地图并在网络可用时同步数据,但不幸的是我无法做到这一点。请在这种情况下帮助我。

4

0 回答 0