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?
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<SPAN class="punctuation token">.</SPAN><SPAN class="token function">load</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> error <SPAN class="keyword token">in</SPAN> guard error <SPAN class="operator token">==</SPAN> nil <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error loading vector tile layer: \(error!.localizedDescription)"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="keyword token">let</SPAN> extent <SPAN class="operator token">=</SPAN> baseLayer<SPAN class="punctuation token">.</SPAN>fullExtent <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN>initialViewpoint <SPAN class="operator token">=</SPAN> <SPAN class="token function">AGSViewpoint</SPAN><SPAN class="punctuation token">(</SPAN>targetExtent<SPAN class="punctuation token">:</SPAN> extent<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">// Or if the map has already been opened into a mapView</SPAN> <SPAN class="comment token">// in which case the mapView may already have read the</SPAN> <SPAN class="comment token">// map's "initialViewpoint" property…</SPAN> <SPAN class="comment token">// mapView.setViewpoint(AGSViewpoint(targetExtent: extent))</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Cheers,
Nick.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.