Zoom in on a feature

3533
4
02-08-2011 02:04 AM
JamesBurton
New Contributor
Hi, I'm a beginner with the JS API and this is a really basic question but I couldn't find an example of it in the samples. I have a map which includes shape layer, and a form field that allows the user to select one of those features from a select box. This gives the NAME attribute of the feature -- I want to redraw the map zoomed in on that feature. Thanks,
0 Kudos
4 Replies
JamesGonsoski
New Contributor III
For some examples, check out the user submissions in the ArcGIS API for Javascript Code Gallery. Type 'zoom' in the search box.

To redraw the map zoomed to a feature, you can set the map extent (map.setExtent) to the appropriate geometry.

Two examples in the code gallery offer different ways to accomplish this, along with some other nice stuff:


  1. Zoom to DataGrid example

  2. An easier way to zoom with a Dojo digit

0 Kudos
JamesBurton
New Contributor
For some examples, check out the user submissions in the ArcGIS API for Javascript Code Gallery. Type 'zoom' in the search box.

To redraw the map zoomed to a feature, you can set the map extent (map.setExtent) to the appropriate geometry.

Two examples in the code gallery offer different ways to accomplish this, along with some other nice stuff:


  1. Zoom to DataGrid example

  2. An easier way to zoom with a Dojo digit



Many thanks Jim.
0 Kudos
JaclynGorman
New Contributor
I was wondering if anyone new if it was possible to zoom to a location within a certain distance.  For example, I zoom to an address but want to zoom in a mile around the address and not to the point.  Thanks

Jaclyn
0 Kudos
JamesGonsoski
New Contributor III
I was wondering if anyone new if it was possible to zoom to a location within a certain distance.  For example, I zoom to an address but want to zoom in a mile around the address and not to the point.  Thanks

Jaclyn


A simple way to handle this is the map.centerAndZoom method. It requires a point on the map and depending on the type of service you specify either a fixed map scale or zoom factor for the extent.

You can also set the extent of the map yourself using map.setExtent method. Here, you are in control of the extent you are sending; defined as XMin, XMax, YMin, YMax in map units. If you have a point XY coordinate, your XMin = XMax and YMin = YMax.  Adding/Subtracting map units to the Min and Max values of the X and Y coordinates, gets you a zoomed extent.

See Setting and Using Extents in a Map for more details.
0 Kudos