Select to view content in your preferred language

ConstrainExtentBehavior prevents zooming in programmatically on startup

771
3
10-14-2010 02:06 PM
BryanBaker
Regular Contributor
I'm trying to have the map zoom in on startup with the ZoomToResolution(geometry, MapPoint) method. It worked at first, but then failed when I also set a maximum zoom out using the ConstrainExtentBehavior (which I'm doing programmatically). I'm setting all this after the map layers are initialized. The map will center on the MapPoint, but the extent will be zoomed way out, as set in the behavior.

The ZoomToResolution only fails if I have a tiled map service (e.g., the ESRI world street map) in the map. If I only have a dynamic map service, it zooms in fine.

I've tried reversing the order in which the ZoomToResolution and ConstrainExtentBehavior are applied, with same results. I need to set the behavior programmatically because I don't know the envelope until runtime. Can anyone suggest any workarounds?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
ZoomToResolution's first parameter is a double (resolution), not Geometry. You might be confusing it with ZoomTo?

Are you zooming in or out? Adding ConstrainExtentBehavior restricts you from zooming out of the set ConstrainedExtent so zoom in should not at all be affected.

I tried the following call to ZoomToResolution from MouseClick event:
This works
MyMap.ZoomToResolution(MyMap.Resolution/2, e.MapPoint); //  zoom in
while this line does not because zoom would cause the map extent to go beyond the ConstrainedExtent.
MyMap.ZoomToResolution(MyMap.Resolution/0.5, e.MapPoint); // zoom out
0 Kudos
BryanBaker
Regular Contributor
ZoomToResolution's first parameter is a double (resolution), not Geometry. You might be confusing it with ZoomTo?

Are you zooming in or out? Adding ConstrainExtentBehavior restricts you from zooming out of the set ConstrainedExtent so zoom in should not at all be affected.

I tried the following call to ZoomToResolution from MouseClick event:
This works
MyMap.ZoomToResolution(MyMap.Resolution/2, e.MapPoint); //  zoom in
while this line does not because zoom would cause the map extent to go beyond the ConstrainedExtent.
MyMap.ZoomToResolution(MyMap.Resolution/0.5, e.MapPoint); // zoom out


Sorry, I misquoted the signature of ZoomToResolution in my original post. I am passing it the pixel resolution as the first parameter, and it does work OK if I disable the ConstrainExtentBehavior. The resolution value I'm passing is fairly small, which should cause the map to zoom in pretty close (which again it does without the behavior in place).
0 Kudos
BryanBaker
Regular Contributor
Update: ZoomToResolution works the first time after removing the behavior, but fails subsequently. I'm guessing the fact that my map service uses WKT for its spatial reference is involved. I started a new thread since the behavior does not appear to be the real cause:
http://forums.arcgis.com/threads/15650-Map.ZoomToResolution-fails-to-change-map?p=48472#post48472
0 Kudos