I'm using ArcGIS Javascript API 4.20 to retrieve a webmap from ArcGIS online, and I'm able to load and display it by providing its ID, using the following simple script:
import MapView from "https://js.arcgis.com/4.20/@arcgis/core/views/MapView.js"; import WebMap from "https://js.arcgis.com/4.20/@arcgis/core/WebMap.js"; import esriId from "https://js.arcgis.com/4.20/@arcgis/core/identity/IdentityManager.js"; var webmap = new WebMap({ portalItem: { id: "1234567890qwertyuiop" } }); var view = new MapView({ map: webmap, container: "mapFrame", //ID of the HTML element where the map will be displayed });
I need to find a way to programmatically adjust the map's zoom when it gets loaded, so that every layer/feature contained in it is visible in the area displayed in the map.
I've found examples and references using a "fullExtent" function, but as far as I understand this is designed to work with a layer. I've not been able to figure out how to apply the same idea to the full webmap instead and make it work: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#fullExte...JasonModling
webmap.when(function(){ view.extent = webmap.fullExtent; }); //I've tried using this. It doesn't raise any errors, but does nothing.
Could you please let me know what am I doing wrong? Or share any ideas to achieve what I need programmatically using a different approach?
Hey @AaqibJamshed ,
as far as I know you're right - the fullExtent-Function only works with layers.
You could loop each layer in the map to get the extent for each layer.
Then use the union function from GeometryService class