converting zoom level between maps

2561
1
05-02-2013 08:09 PM
RemmieVail
New Contributor
Sorry, noob question here.  How can I convert the zoom level between maps with different spatial references?  For example, if someone zooms into Chicago, and then switch maps I want the new map to be zoomed into Chicago as well.

I've been looking into the spatial reference scale & resolution properties, but haven't been able to get it working.  My other thought was to create an envelope using the 4 points at the corners of the display, and create a new envelope from converted point values when the new map is opened.  Any thoughts? Suggestions?

Thanks in advance,
eimmer
0 Kudos
1 Reply
RemmieVail
New Contributor
Got a solution.  It's a little complicated, but it works.
1) Get & save a polygon enclosing the current display of the MapView. (MapView.getExtent() returns a polygon you can use.)
2) Trash the MapView from the display.
3) Dynamically create a new a new MapView object.
4) Load the new map in the MapView.
5) Get the saved polygon from step 1 and convert it to be in the same spatial reference as the new map.  (GeometryEngine.project() will do this for you.
6) Pass the new polygon to the setExtent method of the new MapView.

*You can replace steps 2 - 4 by loading the new map and resetting the spatial reference and resolution manually.


The GeometryEngine.project method can throw an IndexOutOfBoundsException if you are at a map's maximum resolution.  I have a try/catch listen for this and then just call myMapView.setResolution(myMapView.getMaxResolution) to make sure I'm zoom all the way out.
0 Kudos