Select to view content in your preferred language

Calculating distance for multiple/different spatial references

786
2
05-06-2011 12:41 PM
MarkCollins
Frequent Contributor
I have an "auto center" feature that basically centers the map on all the visible graphics in a layer. When centering on items it needs to add a buffer to the envelope so that the farthest out items do not appear right on the edge of the map.  The buffer used (0.01) has been a fixed number for us when we were only using WKID 4326 as a spatial reference but now we have also added support for Web Mercator so this means our buffer number must be variable depending on the spatial reference used.

I would like to have a buffer of 1/4 of a mile. What is the best/recommened way to calculate distance for different coordinate systems?
0 Kudos
2 Replies
dotMorten_esri
Esri Notable Contributor
Instead of relying on a specific distance, for this scenario I usually like to have a ratio of space. Ie. 5% space around the contents I center on. So that means that for large elements/layers, the distance is larger than for small ones.
You can easily accomplish that using the Expand method on Envelope:
   MyMap.ZoomTo( myEnvelope.Expand(1.05) );

Note though that you might want to have a minimum size as well (for instance in case it's the envelope of a point it would be an infinitely small area)
0 Kudos
MarkCollins
Frequent Contributor
Excellent suggestion, this worked great. Thank you very much.
0 Kudos