Feature Partially Obscured after Zoom to Extent

678
4
Jump to solution
03-15-2013 09:14 AM
MattFancher
New Contributor III
I use the following to zoom to a selected feature:

var feature = fset.features[0]; myMap.graphics.add(feature); myMap.setExtent(feature.geometry.getExtent());


Which works, but sometimes the feature is partially obscured by the limits of the map div.  For example, in this map:

http://maps.puc.state.oh.us/exchange/index.asp

If you select "Aberdeen" from the drop down, then the zoom works as I'd like.  If you select "Adamsville", then you'll see what I'm talking about.

Any suggestions to fix that?  Thanks in advance!
0 Kudos
1 Solution

Accepted Solutions
DianaBenedict
Occasional Contributor III
I see what you mean. Here are some thoughts though I am sure there are numerous other solutions out there:

1) setExtent(extent, fit?) note that there is fit? option. If you are using Tiled layers then maybe this would help?  Not sure, never really used this option.  Here is the documentation:
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/map.html#Map/setExtent
NOTE: read the documentation on this. I am not sure if I am correct on my assumption of the fit? param.

2) Generally, I like to expand the extent so that it gives the map a little room/margin around your selected feature.
map.setExtent(extent.expand(expandFactor));

3) Never tired this but it looks like other features beside the one that you pointed out had issues with zoom scale. Try seeing with the following will do for you.
esri.geometry.getExtentForScale(map, scale)
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/namespace_geometry.html#namespace_geometry/...

View solution in original post

0 Kudos
4 Replies
DianaBenedict
Occasional Contributor III
I see what you mean. Here are some thoughts though I am sure there are numerous other solutions out there:

1) setExtent(extent, fit?) note that there is fit? option. If you are using Tiled layers then maybe this would help?  Not sure, never really used this option.  Here is the documentation:
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/map.html#Map/setExtent
NOTE: read the documentation on this. I am not sure if I am correct on my assumption of the fit? param.

2) Generally, I like to expand the extent so that it gives the map a little room/margin around your selected feature.
map.setExtent(extent.expand(expandFactor));

3) Never tired this but it looks like other features beside the one that you pointed out had issues with zoom scale. Try seeing with the following will do for you.
esri.geometry.getExtentForScale(map, scale)
http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/namespace_geometry.html#namespace_geometry/...
0 Kudos
KenBuja
MVP Esteemed Contributor
In my applications where I have a tiled basemap and I perform a zoom to a feature, I check whether the extent of that feature is contained by the extent of the map. If not, then I move out one level.

Although this code is for Flex, you should be able to use the same logic in JavaScript

map.extent = feature.extent;
if (!map.extent.contains(feature.extent))
{
    map.level--;
}
0 Kudos
MattFancher
New Contributor III
Thank you Diana and Ken!  Diana's suggetion to set the optional fit parameter on the setExtent method very quickly solved the problem.
0 Kudos
KenBuja
MVP Esteemed Contributor
That's a good thing to know as I convert my projects to JavaScript!
0 Kudos