How to pan and zoom to selected point correctly?

3985
6
Jump to solution
01-30-2015 01:40 AM
AnatoliiTerentiev
Occasional Contributor III

Dear Gurus!

Excuse for question, but I can't understand why don't work this block:

myMap.PanTo(selectedPoint);

myMap.ZoomToResolution(140, selectedPoint);

when in xaml :

<esri:Map x:Name="myMap" Extent="3200000,8550000,4250000,10100000">

       <esri:OpenStreetMapLayer ID="OSMLayer" Style="Mapnik" />

      <esri:ArcGISDynamicMapServiceLayer ID="RK"

                            Url="http://localhost:6080/ArcGIS/rest/services/karelia/MapServer" />

      <esri:FeatureLayer    ID="routes_osm"

                            Url="http://localhost:6080/ArcGIS/rest/services/karelia/MapServer/1" >                               

                </esri:FeatureLayer>

</esri:Map

>

PanTo - works just as expected, and after the addition of the second line- the result is not clear

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor

Due to animation PanTo and ZoomToResolution are asynchronous operations that give undefined results if they are executed simultaneously.

One option may be to create a method that do both actions at the same time (e.g. centerAndZoom method)

View solution in original post

6 Replies
DominiqueBroux
Esri Frequent Contributor

Due to animation PanTo and ZoomToResolution are asynchronous operations that give undefined results if they are executed simultaneously.

One option may be to create a method that do both actions at the same time (e.g. centerAndZoom method)

View solution in original post

AnatoliiTerentiev
Occasional Contributor III

Excellent, Dominique! That is just what I wanted!

0 Kudos
AnatoliiTerentiev
Occasional Contributor III

And If not difficult - how do likewise for panTo(geometry) (line or polygon)?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

For panning/zooming to a line or polygon, you have the following options:

   - use PanTo if you want to keep the map resolution

   - use the former CenterAndZoom with geometry.Extent.GetCenter() if you want to zoom at a predefined resolution (but not sure the full geometry will be inside the map extent)

   - or most simple, use ZoomTo(geometry) or something like ZoomTo(geometry.Expand(1.2))

AnatoliiTerentiev
Occasional Contributor III

It's clear, but there were doubts that there is a certain algorithm for computing the resolution depending on the size of the object.

0 Kudos
AnatoliiTerentiev
Occasional Contributor III

When I tried to get initial state of the map as follows

        private void setInitialMap()

        {

            centerAndZoom(myMap, initCentrPoint, InitMapResolution);

            Thread.Sleep(100);

        }

        private void centerAndZoom(ESRI.ArcGIS.Client.Map map, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint, double resolution)

        {

            double ratio = 1.0;

            if (map.Resolution != 0.0)

                ratio = resolution / map.Resolution;

            if (ratio == 1.0)

                map.PanTo(mapPoint);

            else

            {

                ESRI.ArcGIS.Client.Geometry.MapPoint mapCenter = map.Extent.GetCenter();

                double X = (mapPoint.X - ratio * mapCenter.X) / (1 - ratio);

                double Y = (mapPoint.Y - ratio * mapCenter.Y) / (1 - ratio);

                map.ZoomToResolution(resolution, new ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y));

            }

        }

the result was negative, as long as I do not put a slight delay 100 ms. What may be the reason?

0 Kudos