Select to view content in your preferred language

How do I find the extent of an array of graphics in JS API 4.x?

7597
3
Jump to solution
03-20-2017 12:01 PM
MattRahr
New Contributor

Is there a 4.x version of esri/graphicsUtils? I'm trying to zoom to the extent of my IdentifyResult after hydrating the graphics into a GraphicsLayer. The GraphicsLayer, by default has an extent of the world, but it's not updated when graphics are added to it. Maybe this ability has moved to somewhere else in the 4.x API? Or, if someone has some code that could manually expand the extent as the response.results come in, I'd be very gracious! 

1 Solution

Accepted Solutions
thejuskambi
Frequent Contributor

You dont need graphicUtils to do that in 4.x. The mapView.goTo method takes Graphic[] as paramter and will zoom to the location of the graphics.

MapView | API Reference | ArcGIS API for JavaScript 4.3 

View solution in original post

3 Replies
thejuskambi
Frequent Contributor

You dont need graphicUtils to do that in 4.x. The mapView.goTo method takes Graphic[] as paramter and will zoom to the location of the graphics.

MapView | API Reference | ArcGIS API for JavaScript 4.3 

BethManghi
Regular Contributor

Don't know if it would be helpful, but I was able use extent.expand() on an array of point graphics using two goTo() calls.  Don't animate the first and call the second after the first resolves.  That way, you can capture the view's extent on the first goTo() and expand on the second.  Could be a workaround until graphicsUtils is added to 4.x.  Hope it helps.

 

view.goTo(results.features, {animate: false}).then(function(response) {

      var zoomView = {};
      zoomView = view.extent.expand(2.0);
      view.goTo(zoomView);

});

ClintonCrick
Emerging Contributor

This is incredibly helpful, thank you!

With ESRI's removal of the ability to ensure a feature set fits the extent on zoom, this works as a great solution.

Truly, truly missing the ability to ensure the set extent fits on zoom.