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?
Solved! Go to Solution.
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()))
}
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()))
}
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.