Zoom Map to Set Of Points

881
5
03-26-2018 02:46 AM
EssaddekMohammed
New Contributor II

Hello,

I am building an arcgis map based application using the ArcGis javascript web API. I would like to know how to zoom out / in the map to view a full set of points.

Thank you for your help.

Regards,

Mohammed

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

Can you supply some more detail? Is this using the 3.x or 4.x version of the API? Is your point dataset a feature layer?

Here are two reference on getting the full extent from a feature layer, for example:

Layer | API Reference | ArcGIS API for JavaScript 4.6 

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.23 

0 Kudos
EssaddekMohammed
New Contributor II

Hello,

I am using the version 4, i am pushing my points directly into graphic layer.

Hope this help you.

0 Kudos
KenBuja
MVP Esteemed Contributor

The GraphicsLayer also has a fullExtent property

GraphicsLayer | API Reference | ArcGIS API for JavaScript 4.6 

0 Kudos
EssaddekMohammed
New Contributor II

So, in your opinion, if i put this line of code : view.extent = view.graphics.fullExtent; , that will work ?

0 Kudos
KenBuja
MVP Esteemed Contributor

No, that won't work like that. view.graphics returns a Collection of graphics, not a GraphicsLayer, so you can't use the fullExtent method on that. The view's goTo method of the view can take an array of graphics or geometries. You can use something like this after adding the graphics to the view.

setTimeout(function(){
  view.goTo(view.graphics);
},500);‍‍‍

You'd need a timeout, since it takes a little time to add the graphics to the view.

Or you could add the graphics to a GraphicsLayer and watch for it to stop updating and zoom to its fullExtent.