Search code examples
javascriptarcgisarcgis-js-api

Finding Zoom level from ArcGIS WebMap


I am loading a Webmap made with ArcGIS online into a simple viewer app. I want the position and zoom level to match the original.

I can get the center from map.portalItem.extent, but how do I find the zoom?

app.map=new WebMap({ portalItem: { id: myId }});                                                         
app.map.load().then(function() {
   app.center[0]=app.map.portalItem.extent.center.longitude;
   app.center[1]=app.map.portalItem.extent.center.latitude;
   app.zoom=???  
});
...
app.mapView.when(function() { app.activeView.goTo({ center:app.center, zoom: app.zoom }) });

Solution

  • The extent is stored in the WebMap (not the zoom level) - but that's ok because the goTo() function you're using takes many different inputs, including an extent. So just change your code to something like this:

    app.map=new WebMap({ portalItem: { id: myId }});                                                         
    app.map.load().then(function() {
       app.extent=app.map.portalItem.extent;
    });
    ...
    app.mapView.when(function() { app.activeView.goTo(app.extent) });