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!
Solved! Go to Solution.
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)
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)
Excellent, Dominique! That is just what I wanted!
And If not difficult - how do likewise for panTo(geometry) (line or polygon)?
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))
It's clear, but there were doubts that there is a certain algorithm for computing the resolution depending on the size of the object.
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?