ArcGIS Runtime API for Android 一直在升级,写法和用法和之前也有很大的变化。这里简单介绍一下使用ArcGIS Runtime API for Android100.13.0加载各类数据源。
加载TPK包
Tile package(TPK):包含地图文档的缓存数据,也就是切片后的数据,TPK一方面便于用户或组织在ArcGIS Online上分享数据,另一方面也为离线条件下访问数据提供一种方案。使用ArcMap就可以生成。
MapView mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
mMapView.setMap(map);
mMapView.setViewpoint(new Viewpoint(31.734, 119.315, 10000));
TileCache tileCache=new TileCache(Environment.getExternalStorageDirectory()+ File.separator + getString(R.string.geopackage_path));
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
Basemap basemap = new Basemap(tiledLayer);
ArcGISMap mMap = new ArcGISMap(basemap);
mMapView.setMap(mMap);
加载Runtime包
Runtime包(geodatabse):是使用ArcMap生成一个矢量要素离线包,专门提供ArcGIS 移动端开发使用,后缀名为.geodatabase 。注意这个不是在目录中创建的个人地理数据库。
Geodatabase geodatabase=new Geodatabase(Environment.getExternalStorageDirectory()+ File.separator + getString(R.string.geopackage_path1));
geodatabase.loadAsync();
geodatabase.addDoneLoadingListener(()->{
if (geodatabase.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
String error = "Geopackage failed to load: " + geodatabase.getLoadError();
Log.e(TAG, error);
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
return;
}else {
for (GeodatabaseFeatureTable geoPackageFeatureTable : geodatabase.getGeodatabaseFeatureTables()) {
FeatureLayer featureLayer = new FeatureLayer(geoPackageFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
}
}
}
);
加载WMS服务
WMS地图服务:是一种遵从OGC标准的地图服务,在开发中经常遇到,ArcGIS Server自己可以发布WMS服务,但这里我调用的是使用GeoServer发布的WMS地图服务。
MapView mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
mMapView.setMap(map);
mMapView.setViewpoint(new Viewpoint(-42.31384, 146.82129, 10000));
List<String> wmsLayerNames = new ArrayList<>();
wmsLayerNames.add("tasmania");
WmsLayer wmsLayer = new WmsLayer("http://192.168.1.121:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetCapabilities", wmsLayerNames);
wmsLayer.setPreferredImageFormat(ArcGISMapImageLayer.ImageFormat.PNG);
wmsLayer.setVisible(true);
wmsLayer.setOpacity(0.5f);
map.getOperationalLayers().add(wmsLayer);
加载GeoPackage
GeoPackage在ArcGIS中支持的不是非常好,但是栅格与矢量数据都可以存储。可以使用QGIS制作gpkg的包
GeoPackage mGeoPackage = new GeoPackage(Environment.getExternalStorageDirectory()+ File.separator + "newGeoPackage.gpkg");
mGeoPackage.loadAsync();
mGeoPackage.addDoneLoadingListener(() -> {
if (mGeoPackage.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
String error = "Geopackage failed to load: " + mGeoPackage.getLoadError();
Log.e(TAG, error);
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
return;
}
for (GeoPackageRaster geoPackageRaster : mGeoPackage.getGeoPackageRasters()) {
RasterLayer rasterLayer = new RasterLayer(geoPackageRaster);
mMapView.getMap().getOperationalLayers().add(rasterLayer);
}
for (GeoPackageFeatureTable geoPackageFeatureTable : mGeoPackage.getGeoPackageFeatureTables()) {
FeatureLayer featureLayer = new FeatureLayer(geoPackageFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
}
});
三维模式
注意三维模式下:
- 很多模拟器不支持,尽量真机
- 设置OpenGL ES版本3.0
<uses-feature
android:glEsVersion="0x00030000"
android:required="true" />
xml
<com.esri.arcgisruntime.mapping.view.SceneView
android:id="@+id/sceneView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.esri.arcgisruntime.mapping.view.SceneView>
java
SceneView sceneView=findViewById(R.id.sceneView);
ArcGISScene scene = new ArcGISScene(BasemapStyle.ARCGIS_IMAGERY);
sceneView.setScene(scene);
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(
"http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
scene.getBaseSurface().getElevationSources().add(elevationSource);
Camera camera = new Camera(28.4, 83.9, 10010.0, 10.0, 80.0, 0.0);
sceneView.setViewpointCamera(camera);
|