How to display full extent of a webmap using ArcGIS Javascript API?

11-13-2021 10:29 AM
New Contributor

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 "";
import WebMap from "";
import esriId from "";

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:

    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?

0 Kudos
1 Reply
New Contributor III

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

0 Kudos