安卓智能地图开发与实施六:离线基础底图 - ArcGIS Runtime SDK for Android(Version 100.0.0)

xiaoxiao2021-02-27  638

离线基础底图(Offline Tiled Layers)

离线基础底图最传统的方式是直接拷贝ArcGIS Server服务的切片成果,存在的问题是无论使用松散型还是紧凑型都包含太多碎小文件,部署不便。TPK文件便是为了解决多碎小文件问题。但是依然存在文件太大的问题,动辄十G甚至几十G。而矢量切片(VTPK)在于解决文件太大的问题。

TPK

对于TPK的生产,建议使用ArcGIS Desktop进行生成,对于自定义切片级别(Level of Detail)较为自如。ArcGIS Desktop也可以通过模型构建器将两个工具合为一个。使用ArcGIS Pro,若想自定义切片级别(Level of Detail)需要找个地图服务来支持。

TPK和服务切片文件夹调用类似,只是文件路径不同。 TPK:/sdcard/Hymn/basemap/basemap.tpk 服务切片文件夹:/sdcard/Hymn/basemap/gxksl2016

package hymn.esrichina.displayamapusingtpk; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.esri.arcgisruntime.data.TileCache; import com.esri.arcgisruntime.layers.ArcGISTiledLayer; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.Basemap; import com.esri.arcgisruntime.mapping.view.MapView; public class MainActivity extends AppCompatActivity { private MapView mainMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { String theOfflineTiledLayers = "/sdcard/Hymn/basemap/ImageBasemap.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); } catch (Exception e) { } } }

如何生产TPK参考:

ArcGIS Pro

http://pro.arcgis.com/zh-cn/pro-app/tool-reference/data-management/create-map-tile-package.htm

ArcGIS Desktop

http://desktop.arcgis.com/zh-cn/arcmap/latest/tools/data-management-toolbox/create-map-tile-package.htm

VTPK

和上章节“在线矢量切片”使用类似,只是将在线地址更换为了本地文件。例如: /sdcard/nxgt/basemap/dzzhdjfb.vtpk

package hymn.esrichina.displayamapusingvtpk; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.esri.arcgisruntime.layers.ArcGISTiledLayer; import com.esri.arcgisruntime.layers.ArcGISVectorTiledLayer; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.Basemap; import com.esri.arcgisruntime.mapping.view.MapView; public class MainActivity extends AppCompatActivity { private MapView mainMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { String theOfflineTiledLayers = "/sdcard/Hymn/basemap/dzzhdjfb.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); } catch (Exception e) { String eResult = e.getMessage(); } } }

如何生产VTPK参考:

http://pro.arcgis.com/zh-cn/pro-app/tool-reference/data-management/create-vector-tile-package.htm

MMPK(Basemap)

通过ArcGIS Pro可以制作包含基础底图(Basemap)的MMPK,MMPK文件解析后,基础底图(Basemap)中的图层会解析为MobileBasemapLayer,只提供浏览功能。当然,亚洲字符的支持情况在安卓端不是特别好。

package hymn.esrichina.displayamapusingmmpkbasemap; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.esri.arcgisruntime.loadable.LoadStatus; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.Basemap; import com.esri.arcgisruntime.mapping.LayerList; import com.esri.arcgisruntime.mapping.MobileMapPackage; import com.esri.arcgisruntime.mapping.view.MapView; import java.util.List; public class MainActivity extends AppCompatActivity { private MapView mainMapView; private MobileMapPackage mainMobileMapPackage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { String mainMMPKPath = "/sdcard/Hymn/basemap/MobileBasemapLayer.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<ArcGISMap> mainArcGISMapL = mainMobileMapPackage.getMaps(); ArcGISMap mainArcGISMap = mainArcGISMapL.get(0); Basemap mainBasemap = mainArcGISMap.getBasemap(); LayerList mainMMPKLL = mainArcGISMap.getOperationalLayers(); mainMapView.setMap(mainArcGISMap); } } }); } catch (Exception e) { } } }

解析结果以MobileBasemapLayer对象包含在ArcGISMap对象的Basemap中。

如何生产MMPK,可以参考:

http://pro.arcgis.com/zh-cn/pro-app/tool-reference/data-management/create-mobile-map-package.htm

结尾

源程序包含:

DisplayAMapUsingMMPKBasemap DisplayAMapUsingTPK DisplayAMapUsingVTPK 请自行下载: 链接:http://pan.baidu.com/s/1o8BbX1K 密码:0162 若失效,可发邮件给韩源萌(polyline@126.com)索要。

转载请注明原文地址: https://www.6miu.com/read-2106.html

最新回复(0)