goTo, zoom out a bit

160
1
03-05-2024 08:06 PM
JasonWood
New Contributor II

I am using view.goTo to go to an array of geometries (which happen to be the same as all the polygons drawn on a graphics layer `graphicsLayerParcelHighlight`)

The problem is that if I don't specify a zoom level, it's zoomed in too much. I want to back out around 2 or 3 zoom levels from whatever it would be otherwise.

I think I could work out how to expand each of the geometries in the array, but I'm not sure if that's the most sensible way. I'm a beginner.

view.whenLayerView(graphicsLayerParcelHighlight).then(() => {
  view.goTo({
    target: parcelGeometryArray,
    zoom: 16
  });
});

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

You can get the extent of all the graphics, and then expand it a bit:

var extent = null;

graphicsLayer.graphics.forEach(function(graphic) {
	if (graphic.geometry.type == "polygon") {
		if (extent === null)
			extent = graphic.geometry.extent.clone();
		else
			extent.union(graphic.geometry.extent);
	}
});

if (extent !== null)
	view.goTo(extent.expand(1.5));

 

0 Kudos