ArcGIS runtime sdk 移动端常见数据源加载方式

1. 加载在线的ArcGIS Portal webmap资源

// inflate MapView from layout
mMapView = (MapView) findViewById(R.id.mapView);

String theURLString = "webmap url";
ArcGISMap mainArcGISMap = new ArcGISMap(theURLString);
Basemap mainBasemap = mainArcGISMap.getBasemap();
LayerList mainLayerList = mainArcGISMap.getOperationalLayers();
mMapView.setMap(mainArcGISMap);

2. 支持加载离线的tpk文件

String theOfflineTiledLayers =getSDCardPath()+ "/ArcGIS/china.tpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
TileCache mainTileCache = new TileCache(theOfflineTiledLayers);
ArcGISTiledLayer mainArcGISTiledLayer = new ArcGISTiledLayer(mainTileCache);
Basemap mainBasemap = new Basemap(mainArcGISTiledLayer);
ArcGISMap mainArcGISMap = new ArcGISMap(mainBasemap);
mainMapView.setMap(mainArcGISMap);

3. 支持加载离线的矢量切片包vtpk文件

String theOfflineTiledLayers = getSDCardPath()+"/ArcGIS/china.vtpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
ArcGISVectorTiledLayer mainArcGISVectorTiledLayer = new ArcGISVectorTiledLayer(theOfflineTiledLayers);
Basemap mainBasemap = new Basemap(mainArcGISVectorTiledLayer);
ArcGISMap mainArcGISMap = new ArcGISMap(mainBasemap);
mainMapView.setMap(mainArcGISMap);

4. 加载本地shp文件

// 取消本地shapefile文件
String path = getSDCardPath()+"/ArcGIS/Shapefile/China.shp";
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(path);

shapefileFeatureTable.loadAsync();
shapefileFeatureTable.addDoneLoadingListener(() -> {
  if (shapefileFeatureTable.getLoadStatus() == LoadStatus.LOADED) {

    // 利用shapefile文件创建一个FeatureServer文件
    FeatureLayer shapefileFeatureLayer = new FeatureLayer(shapefileFeatureTable);

    // 将shapefile图层添加到业务图层
    mMapView.getMap().getOperationalLayers().add(shapefileFeatureLayer);

    // 缩放到shapefile范围
    mMapView.setViewpointAsync(new Viewpoint(shapefileFeatureLayer.getFullExtent()));
  } else {
    String error = "Shapefile feature table failed to load: " + shapefileFeatureTable.getLoadError().toString();
    Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show();
    Log.e(TAG, error);
  }
});

5. 加载移动地图包mmpk

String mainMMPKPath = getSDCardPath()+"/ArcGIS/China.mmpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
mainMobileMapPackage = new MobileMapPackage(mainMMPKPath);
mainMobileMapPackage.loadAsync();
mainMobileMapPackage.addDoneLoadingListener(new Runnable() {
    @Override
    public void run() {
        LoadStatus mainLoadStatus = mainMobileMapPackage.getLoadStatus();
        if (mainLoadStatus == LoadStatus.LOADED) {
            List mainArcGISMapL = mainMobileMapPackage.getMaps();

            ArcGISMap mainArcGISMap = mainArcGISMapL.get(0);
            //获取mmpk中的基础底图
            Basemap mainBasemap = mainArcGISMap.getBasemap();
            //后去mmpk中的业务图层
            LayerList mainMMPKLL = mainArcGISMap.getOperationalLayers();

            mainMapView.setMap(mainArcGISMap);
        }
    }
});

6. 加载桌面导出的geodatabase文件

// 本地geodatabase文件路径
String path = getSDCardPath() + "/ArcGIS/China.geodatabase";
// 创建geodatabase
final Geodatabase geodatabase = new Geodatabase(path);
//异步加载geodatabase
geodatabase.loadAsync();
// 当geodatabase读取成功后将geodatabase加载到数据库
geodatabase.addDoneLoadingListener(() -> {
  if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {
    List geodatabaseFeatureTables = geodatabase.getGeodatabaseFeatureTables();
    for (int i=0;i {
        if (featureLayer.getLoadStatus() == LoadStatus.LOADED) {
          // set viewpoint to the feature layer's extent
          mMapView.setViewpointAsync(new Viewpoint(featureLayer.getFullExtent()));
        } else {
          Toast.makeText(MainActivity.this, "Feature Layer failed to load!", Toast.LENGTH_LONG).show();
          Log.e(TAG, "Feature Layer failed to load!");
        }
      });
      // 添加到地图
      mMapView.getMap().getOperationalLayers().add(featureLayer);
    }


  } else {
    Toast.makeText(MainActivity.this, "Geodatabase failed to load!", Toast.LENGTH_LONG).show();
    Log.e(TAG, "Geodatabase failed to load!");
  }
});

7. 加载geopackage文件(开源)

//GeoPackage路径
String geoPackagePath =getSDCardPath()+"/ArcGIS/China.gpkg";
Log.d(TAG, geoPackagePath);
// 打开GeoPackage
GeoPackage geoPackage = new GeoPackage(geoPackagePath);
geoPackage.loadAsync();
geoPackage.addDoneLoadingListener(() -> {
  if (geoPackage.getLoadStatus() == LoadStatus.LOADED) {
    List geoPackageFeatureTables = geoPackage.getGeoPackageFeatureTables();
    for (int i = 0; i < geoPackageFeatureTables.size(); i++) {
      // 加载图层
      FeatureTable geoPackageTable = geoPackage.getGeoPackageFeatureTables().get(i);
      // Make sure a feature table was found in the package
      if (geoPackageTable == null) {
        Toast.makeText(MainActivity.this, "No feature table found in the package!", Toast.LENGTH_LONG).show();
        Log.e(TAG, "No feature table found in this package!");
        return;
      }
      // Create a layer to show the feature table
      FeatureLayer featureLayer = new FeatureLayer(geoPackageTable);
      // Add the feature table as a layer to the map (with default symbology)
      mMap.getOperationalLayers().add(featureLayer);
    }
  }else {
    Toast.makeText(MainActivity.this, "GeoPackage failed to load! " + geoPackage.getLoadError(), Toast.LENGTH_LONG).show();
    Log.e(TAG, "GeoPackage failed to load!" + geoPackage.getLoadError());
  }
});

8. 加载slpk

ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer("slpk文件地址");
scene.getOperationalLayers().add(sceneLayer);

 

附录

       欢迎大家关注我的收费课程《ArcGIS Pro 2.6和ArcGIS Enterprise学习》,共8小时,有理论有实操:https://edu.csdn.net/course/detail/31690

课程主要包含:

  1. ArcGIS Pro2.6学习

                    ①GIS中的数据

                    ②GIS中的坐标系

                    ③企业级地理数据库(SDE)设置

                    ④数据编辑及拓扑检查

                    ⑤简单制图

                   ⑥空间分析

     2.ArcGIS Enterprise学习

                  ①环境部署

                  ②二三维服务发布(矢量切片、要素服务、地图切片、地形服务、三维服务等)

                  ③使用及运维(详细介绍如何确定enterprise部署架构,简单介绍相应的运维工具)

      3.开发体系梳理

参考:

https://developers.arcgis.com/arcgis-runtime/

 

你可能感兴趣的:(ArcGIS,Pro,arcgis,runtime,安卓,移动端)