Select to view content in your preferred language

Zoom in KM distance

1136
5
08-10-2010 07:57 PM
LakshmananVenkatesan
Frequent Contributor
Hi All

I want to show the zoom in distance in KM whenever user zooms in/out in my status bar. How do I go about. Please give me if I have some samples

SR
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
You can listen to map's ExtentChanged event and use GeometryService Distance (see sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Distance)

In the following code, I used only one MapPoint from each extent, the upper right corner, so I calculate the distance from the upper right corner of previous extent with the upper right corner of the new extent.

 public MainPage()
        {
            InitializeComponent();
            this.MyMap.ExtentChanged += new EventHandler<ExtentEventArgs>(MyMap_ExtentChanged);
            gs = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
            gs.DistanceCompleted += new EventHandler<DistanceEventArgs>(gs_DistanceCompleted);
        }

        void gs_DistanceCompleted(object sender, DistanceEventArgs e)
        {
            double distanceInKm = e.Distance;
        }

        GeometryService gs;
     
        void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
        {
            if (e.OldExtent !=null && e.NewExtent != null)
            {
                gs.DistanceAsync(GetMapPoint(e.OldExtent), GetMapPoint(e.NewExtent), new DistanceParameters()
                {
                    DistanceUnit = LinearUnit.Kilometer,
                    Geodesic = true
                });                
            }
        }

        private MapPoint GetMapPoint(Envelope extent)
        {
            return new MapPoint() { SpatialReference = this.MyMap.SpatialReference, X = extent.XMax, Y = extent.YMax };
        }


Jennifer
0 Kudos
JenniferNery
Esri Regular Contributor
I talked to another developer about this and he proposed to do the following:
1. In the ExtentChanged, if you are only concerned with the zoom, compare the map's previous resolution with its current resolution to rule out the pan because dragging the map also fires this event.
2. Before calling DistanceAsync, it might be a good idea to pass in Polyline instead of MapPoint and also using the map's center as the location and the map's resolution as length of Polyline. You can see the attached image.

In this example, the old extent is the blue rectangle, the new extent is the red rectangle. You get each of their centers to dictate your Polyline's position. The length of these polylines will be the zoom factor (map units divided by pixels). Map units is the distance between your upper left and upper right corners and pixels is 300.

It might be worth to try this approach too.

Jennifer
0 Kudos
JenniferNery
Esri Regular Contributor
distance in KM whenever user zooms in/out in my status bar


Do you mean use ScaleBar like in this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Scalebar If yes, the only change you really have to do is change DisplayUnits from Miles to Kilometers.

Jennifer
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Jennifer,

Thanks for post, am following scale bar sample provided by you. Is there any chance where I can get only values , I do not want scale bar image? Please help.

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Scalebar

SR
0 Kudos
DominiqueBroux
Esri Frequent Contributor
ScaleBar has been deprecated and replaced by the ScaleLine control in the toolkit.

There is a sample here : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Scaleline

You can retemplate the scale line control to get only values without images.
0 Kudos