0

我尝试使用适用于 Android 100.5.0 的 ArcGIS Runtime SDK 创建离线地图。我按照指南https://developers.arcgis.com/android/latest/guide/take-map-offline-preplanned.htm遵循预先计划的工作流程. 我在 ArcGISOnline 中创建 mapAreas 并尝试从设备下载它们。我想获得一个离线地图,其中包含所有 mapAreas,就像在应用程序 maps.me 中一样(在一张大地图上,您已经下载了具有更详细细节的区域),但我得到的是从上次下载的区域制作的离线地图。所以我创建了具有比例世界的mapArea“欧洲” - 城市和具有比例城市的mapArea“柏林” - 建筑物(底图-openstreetmaps,没有要素图层)并成功下载它们,在文件夹中看到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()
            }

4

1 回答 1

0

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

下载区域:

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/

于 2019-05-15T11:20:39.090 回答