Select to view content in your preferred language

How to get the map bounds of a map in a vector tile package?

682
2
Jump to solution
12-05-2018 08:21 AM
MichaelMueller
New Contributor

when loading a vector tile package (vtpk) into a AGSArcGISVectorTiledLayer and setting it as a AGSBasemap to a AGSMap I want to set the initialViewpoint. The initialViewpoint (AGSViewPoint) should be created from the bounds of the vector tile package. But how can I get the bounds of the vector tile package?

0 Kudos
1 Solution

Accepted Solutions
MichaelMueller
New Contributor

got the solution:

let baseLayer = AGSArcGISVectorTiledLayer(url: yourUrl)

let map = AGSMap(basemap: AGSBasemap(baseLayer: baseLayer))

if let mapExtend = baseLayer.fullExtent {                    

   map.initialViewpoint = AGSViewpoint(targetExtent: AGSEnvelope(xMin: mapExtend.xMin, yMin: mapExtend.yMin,    xMax: mapExtend.xMax, yMax: mapExtend.yMax, spatialReference: AGSSpatialReference.wgs84()))

}

View solution in original post

0 Kudos
2 Replies
MichaelMueller
New Contributor

got the solution:

let baseLayer = AGSArcGISVectorTiledLayer(url: yourUrl)

let map = AGSMap(basemap: AGSBasemap(baseLayer: baseLayer))

if let mapExtend = baseLayer.fullExtent {                    

   map.initialViewpoint = AGSViewpoint(targetExtent: AGSEnvelope(xMin: mapExtend.xMin, yMin: mapExtend.yMin,    xMax: mapExtend.xMax, yMax: mapExtend.yMax, spatialReference: AGSSpatialReference.wgs84()))

}

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi Michael Mueller,

One thing to bear in mind is that you need the baseLayer to load before you can read the fullExtent property.

You also don't need to construct a new AGSEnvelope from the one you've already got hold of. Simply pass that into the AGSViewpoint constructor.

Something like this might be more robust:

baseLayer.load() { error in
    guard error == nil else {
        print("Error loading vector tile layer: \(error!.localizedDescription)")
        return
    }
    
    if let extent = baseLayer.fullExtent {
        map.initialViewpoint = AGSViewpoint(targetExtent: extent)
        // Or if the map has already been opened into a mapView
        // in which case the mapView may already have read the
        // map's "initialViewpoint" property…
        // mapView.setViewpoint(AGSViewpoint(targetExtent: extent))
    }
}

Cheers,

Nick.

0 Kudos