是否可以将ArcGISOnline中的mapAreas合并到Android上的一张离线地图中?

时间:2019-05-03 19:29:16

标签: arcgis esri arcgis-runtime arcgis-android-api

我尝试使用适用于Android 100.5.0的ArcGIS Runtime SDK创建离线地图。我按照指南https://developers.arcgis.com/android/latest/guide/take-map-offline-preplanned.htm遵循预定的工作流程。我在ArcGISOnline中创建mapAreas,并尝试从设备下载它们。我想得到一个离线地图,其中包含所有mapAreas,就像在app maps.me中一样(在大地图上,您下载了具有更详细信息的区域),但是相反,我是从最近下载的区域制作的离线地图。因此,我创建了具有比例世界-城市的mapArea“ Europe”和具有比例城市-建筑物(均为底图-openstreetmaps,无要素图层)的mapArea“柏林”,并成功下载了它们,在文件夹中看到了2个tpk文件,但mobile_map.mmpk和package.info文件仅包含与上次加载区域有关的数据。是否有可能完全得到我想要的,将tpk文件合并在一张地图中?

我在Kotlin中的代码:

        val portal = Portal("https://www.arcgis.com/", false)
        val portalItem = PortalItem(portal, itemID)
        val offlineMapTask = OfflineMapTask(portalItem)
        //get all of the preplanned map areas in the web map
        val mapAreasFuture = offlineMapTask.preplannedMapAreasAsync
        mapAreasFuture.addDoneListener {
            try {
                // get the list of areas
                val mapAreas = mapAreasFuture.get()
                val directory = getDirectory()
                prepareDir(directory)
                // loop through the map areas
                var i = 0
                for (mapArea in mapAreas) {
                    mapArea.loadAsync()
                    mapArea.addDoneLoadingListener {
                        val downloadJob = offlineMapTask.downloadPreplannedOfflineMap(mapArea, directory)
                        downloadJob.start()

                        downloadJob.addJobDoneListener {
                            i++
                            if (i == mapAreas.size) {
                                val offlineMapPackage = MobileMapPackage(path)


                             offlineMapPackage.addDoneLoadingListener({
                               if (offlineMapPackage.getLoadStatus() === LoadStatus.LOADED) {

                                   val mobileMap = offlineMapPackage.getMaps().get(0)

                                   myCompletionFuncToShowMap(mobileMap)
                               } else {
                                   println("PACKAGING FAILED")
                               }
                             })
                             offlineMapPackage.loadAsync()
                           }
                        }

                    }

                }

            } catch (e: InterruptedException) {
                e.printStackTrace()
            } catch (e: Exception) {
                e.printStackTrace()
            }

1 个答案:

答案 0 :(得分:0)

由于esri的Luke Smallwood,我在community.esri.com上重复了该问题并得到了答案。所以,是的,有可能。如果将mapView.map设置为Berlin,则必须将“欧洲”地图区域添加为底图图层,并且每个地图区域都必须保存在其自己的目录中。

下载区域:

val portal = Portal("https://www.arcgis.com/", false)
val portalItem = PortalItem(portal, itemID)
val offlineMapTask = OfflineMapTask(portalItem)
//get all of the preplanned map areas in the web map
val mapAreasFuture = offlineMapTask.preplannedMapAreasAsync
mapAreasFuture.addDoneListener {
    try {
        // get the list of areas
        val mapAreas = mapAreasFuture.get()
        val directory = getDirectory() //my function returns String path

        // loop through the map areas
        for (mapArea in mapAreas) {
            mapArea.loadAsync()
            mapArea.addDoneLoadingListener {
                val downloadJob = offlineMapTask.downloadPreplannedOfflineMap(mapArea, directory + "/" + mapArea.portalItem.title)
                downloadJob.start()
                downloadJob.addJobDoneListener {
                    val offlineMapPackage = MobileMapPackage(directory + "/" + mapArea.portalItem.title)
                    offlineMapPackage.addDoneLoadingListener({
                        if (offlineMapPackage.getLoadStatus() != LoadStatus.LOADED) {
                            println("PACKAGING FAILED")
                        }
                    })
                    offlineMapPackage.loadAsync()
                }
            }
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}


下载后的文件:

.../files/maps/Berlin/p13/129294b8-3a70-4d79-a421-24ff14cb19fc.tpk
.../files/maps/Berlin/p13/mobile_map.mmap
.../files/maps/Berlin/package.info
.../files/maps/Europa/p13/2547a985-c98f-49be-a187-5ae3b7a9da09.tpk
.../files/maps/Europa/p13/mobile_map.mmap
.../files/maps/Europa/package.info


显示离线地图:

val path = getDirectory() + "/Berlin"
val offlineMapPackage = MobileMapPackage(path)
offlineMapPackage.addDoneLoadingListener {
    if (offlineMapPackage.getLoadStatus() == LoadStatus.LOADED && !offlineMapPackage.getMaps().isEmpty()) {
        mapView.map = offlineMapPackage.getMaps().get(0)
        val cache = TileCache(getDirectory() + "/Europa/p13/2547a985-c98f-49be-a187-5ae3b7a9da09.tpk")
        val layer = ArcGISTiledLayer(cache)
        mapView.map.basemap.baseLayers.add(layer)
        mapView.map.minScale = 1.8489297737236E7
        mapView.map.maxScale = 2256.994353
    } else {
        println("NO MAP FILES")
    }
}
offlineMapPackage.loadAsync()


调整mapView.map.minScale使其包含欧洲级别非常重要,否则在设备上,地图仅允许在柏林级别之间缩放。比例级别在此处https://www.esri.com/arcgis-blog/products/product/mapping/web-map-zoom-levels-updated/中列出。