Is it possible to have several map areas in offline map (combine several tpk with tiles)

628
1
05-03-2019 04:24 AM
AnastasiiaChechulina
New Contributor
 

Hi guys,

I spent 2 days searching an answer if I could combine several map areas in an offline Map. I want to have an offline map of Europe with max scale to regions and detailed map of several cities, which means an opportunity to scale down to building there. So in ArcGISOnline I created 2 map areas for my map - "Europe" with range from world to city and "Berlin" with scale from city to buildings. When I download areas from device and create a package, only the last loaded area is on the map, when I list files in directory used for loading both tpk are there, but package.info and 

mobile_map.mmap files only contain data related to last loaded area. I use the following code in 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() 

        var i = 0
        for (mapArea in mapAreas) {
            mapArea.loadAsync()
            mapArea.addDoneLoadingListener({
                val downloadJob = offlineMapTask.downloadPreplannedOfflineMap(mapArea, directory)
                downloadJob.start()

                downloadJob.addJobDoneListener({
                    if (downloadResult.hasErrors()) {
                        val layerErrors = downloadResult.getLayerErrors()
                        val tableErrors = downloadResult.getTableErrors()
                    }

                    i++
                    if (i == mapAreas.size) {                         val  offlineMapPackage = MobileMapPackage(directory)                         offlineMapPackage.addDoneLoadingListener({                            if  (offlineMapPackage.getLoadStatus() === LoadStatus.LOADED) {                               System.out.println("Number of maps = " + offlineMapPackage.getMaps().size)                               mapView.map = offlineMapPackage.getMaps().get(0)
                           } else {                                 println("PACKAGING FAILED")                            }                         })
                        offlineMapPackage.loadAsync()
                    }
                 })
            })
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }

Is it possible at all to do what I want?

0 Kudos
1 Reply
LukeSmallwood
Esri Contributor

Hi Anastasiia,

Currently the OfflineMapTask only supports taking a single map area offline for each download operation. If you want to take 2 distinct map areas offline, you would need to create 2 separate mobile map packages. In your code example above, I think you would need to change this line:

val downloadJob = offlineMapTask.downloadPreplannedOfflineMap(mapArea, directory)

to supply a different directory each time (I'm not an Android expert so I could be wrong). For example, you could append the map area's title onto the directory so you have one package called "Europe" and one called "Berlin" or similar.

However, if you need to be able to transition from the Europe wide scale to Berlin within a single map document that may not work for you. To achieve that, you could consider a workflow along these lines:

- Export a tile package for the Europe scale ahead of time using the "ExportTileCacheTask". Store the resulting .tpk on your device in a well known location.

- Download the preplanned map area for Berlin into your device as now.

- in Runtime code, when you come to load the map from the mobile map package, dynamically insert an ArcGISTiledLayer constructed from your Europe tpk into the map 

Alternatively, depending on your data, you may be able to set up your webmap so that it contains data for both ranges.

I hope that helps,

Luke