Select to view content in your preferred language

How to get "fullExtent" of Map/WebMap?

395
3
02-21-2023 03:03 PM
TonyGraham
New Contributor III

For any arbitrary Map (e.g., new Map({ basemap: “osm” })) or WebMap (e.g., new WebMap({portalitem: { id: “123” }})), I think I see that the “initialExtent” is returned by the MapView’s “extent”.

How can I most aptly acquire the “fullExtent” for the MapView?

Where “initialExtent” and “fullExtent” are analogous to what gets returned from querying a single layer or MapServer (e.g., https://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer?f=json).

0 Kudos
3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

You can get the fullExtent of the layer once the layer is loaded.

// Get the fullExtent of the layer when layer is loaded
view.whenLayerView(layer).then(()=>{
  console.log(layer.fullExtent);
  view.goTo(layer.fullExtent);
});

Hope this helps

TonyGraham
New Contributor III

That's for an individual layer, which is fine, but I'm asking about the whole Map/WebMap, which is created in the way specified in the original post.  Such a Map/WebMap has multiple layers--and even potentially multiple base layers. 

My goal is to discover this full extent for a generic MapView (without regard to its arbitrary display size) and--essentially--turn that into a MapView constraint (and, further, to capture the maxScale and turn that into a constraint as well).  I want to explicitly cement the extents at which the map may render.

What I'm doing at the moment is unsatisfying for many reasons.  (See below where I fetch these values--ick.)  I'm looking for an approved, generic solution.  (E.g., do I start taking extent unions?)  I ask because I feel like either a way to do this must already exist or there's something quite wrong with my assumptions.

Getting the full extent (and max scale) for a generic Map or Webmap (ick):

const baseLayers = view?.map?.basemap?.baseLayers;
const baseLayer = baseLayers && baseLayers.length > 0 ? baseLayers.getItemAt(0) : null;
const fullExtent: Rect = baseLayer?.fullExtent
? [
baseLayer?.fullExtent.xmin,
baseLayer?.fullExtent.ymin,
baseLayer?.fullExtent.width,
baseLayer?.fullExtent.height,
]
: [0, 0, 0, 0];
const maxScale = (baseLayer as any)?.maxScale ? (baseLayer as any)?.maxScale : 0;
0 Kudos
UndralBatsukh
Esri Regular Contributor

For webmaps you need to use the viewPoint property on https://developers.arcgis.com/javascript/latest/api-reference/esri-WebMap.html#initialViewProperties...

The Viewpoint - has scale and targetGeometry which are used to set the scale, center or extent of the MapView.

0 Kudos