We are using the following method to zoom a specific region. It works most of the time.. But we found that it doesn't work if we call it from Imported event.
private void Zoom() { var mapLocation = MainMap.MapProjection.ProjectToMap(new Point(8.516667, 23.5)); //FocalPoint="8.516667, 23.5" MainMap.WindowCenter = mapLocation; MainMap.WindowScale = 3.5; }
Here is the sample code to reproduce the issue.
XAML
<ig:XamMap x:Name="MainMap" IsAutoWorldRect="true"> <ig:MapNavigationPane Visibility="Collapsed"/> <ig:XamMap.Layers> <ig:MapLayer LayerName="WorldLayer" FillMode="Choropleth" HorizontalContentAlignment="Center" Resolution="0.5" HorizontalAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center"> <ig:MapLayer.Reader> <ig:SqlShapeReader DataMapping="Data=SpatialData; Name=CountryName" > <ig:SqlShapeReader.CoordinateSystem> <ig:CoordinateSystem UnitType="M" FalseEasting="0.0" FalseNorthing="0.0" > <ig:CoordinateSystem.Projection> <ig:MillerCylindrical EllipsoidType="WGS84" CentralMeridian="10.0" /> </ig:CoordinateSystem.Projection> </ig:CoordinateSystem> </ig:SqlShapeReader.CoordinateSystem> </ig:SqlShapeReader> </ig:MapLayer.Reader> <ig:MapLayer.ValueScale> <ig:LinearScale IsAutoRange="True"/> </ig:MapLayer.ValueScale> </ig:MapLayer> </ig:XamMap.Layers> </ig:XamMap> C# public partial class MainPage : UserControl { MapLayer worldLayer; public MainPage() { InitializeComponent(); worldLayer = MainMap.Layers["WorldLayer"] as MapLayer; worldLayer.Imported += new MapLayerImportEventHandler(worldLayer_Imported); Loaded += new RoutedEventHandler(MainPage_Loaded); } void worldLayer_Imported(object sender, MapLayerImportEventArgs e) { Zoom(); } static MemoGeoServiceClient geoService = new MemoGeoServiceClient(); void MainPage_Loaded(object sender, RoutedEventArgs e) { geoService.GetWorldCompleted += GetWorldCompleted; geoService.GetWorldAsync(); } private void GetWorldCompleted(object sender, GetWorldCompletedEventArgs e) { if (e.Error == null) { var sqlReader = worldLayer.Reader as SqlShapeReader; sqlReader.DataSource = e.Result; worldLayer.ImportAsync(); MainMap.WindowFit(); } } private void Zoom() { var mapLocation = MainMap.MapProjection.ProjectToMap(new Point(8.516667, 23.5)); //FocalPoint="8.516667, 23.5" MainMap.WindowCenter = mapLocation; MainMap.WindowScale = 3.5; } }
<ig:XamMap x:Name="MainMap" IsAutoWorldRect="true"> <ig:MapNavigationPane Visibility="Collapsed"/> <ig:XamMap.Layers> <ig:MapLayer LayerName="WorldLayer" FillMode="Choropleth" HorizontalContentAlignment="Center" Resolution="0.5" HorizontalAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center"> <ig:MapLayer.Reader> <ig:SqlShapeReader DataMapping="Data=SpatialData; Name=CountryName" > <ig:SqlShapeReader.CoordinateSystem> <ig:CoordinateSystem UnitType="M" FalseEasting="0.0" FalseNorthing="0.0" > <ig:CoordinateSystem.Projection> <ig:MillerCylindrical EllipsoidType="WGS84" CentralMeridian="10.0" /> </ig:CoordinateSystem.Projection> </ig:CoordinateSystem> </ig:SqlShapeReader.CoordinateSystem> </ig:SqlShapeReader> </ig:MapLayer.Reader> <ig:MapLayer.ValueScale> <ig:LinearScale IsAutoRange="True"/> </ig:MapLayer.ValueScale> </ig:MapLayer> </ig:XamMap.Layers> </ig:XamMap>
C#
public partial class MainPage : UserControl { MapLayer worldLayer; public MainPage() { InitializeComponent(); worldLayer = MainMap.Layers["WorldLayer"] as MapLayer; worldLayer.Imported += new MapLayerImportEventHandler(worldLayer_Imported); Loaded += new RoutedEventHandler(MainPage_Loaded); } void worldLayer_Imported(object sender, MapLayerImportEventArgs e) { Zoom(); } static MemoGeoServiceClient geoService = new MemoGeoServiceClient(); void MainPage_Loaded(object sender, RoutedEventArgs e) { geoService.GetWorldCompleted += GetWorldCompleted; geoService.GetWorldAsync(); } private void GetWorldCompleted(object sender, GetWorldCompletedEventArgs e) { if (e.Error == null) { var sqlReader = worldLayer.Reader as SqlShapeReader; sqlReader.DataSource = e.Result; worldLayer.ImportAsync(); MainMap.WindowFit(); } } private void Zoom() { var mapLocation = MainMap.MapProjection.ProjectToMap(new Point(8.516667, 23.5)); //FocalPoint="8.516667, 23.5" MainMap.WindowCenter = mapLocation; MainMap.WindowScale = 3.5; } }
If you move this Zoom(); method from worldLayer_Imported to somewhere (e.g. GetWorldCompleted event) then it will work.
Let me know if you need more information..
Thanks.
P.S: We reported about one issue related to non-English culture in my account. Please help to take a look at this issue as well. Thanks.
Hi Michael,
In its current version SqlShapeReader's ImportAsync is executed synchronously which means the Zoom method is called first and then MainMap.WindowFit() whicj changes the WindowScale value.
Sorry for any inconvenience.
I am looking into the second issue you mentiond and I will post back here my findings.
Regards,
Ivan Kotev
I'm not using the default Zoom function of XamlMap control.
I called my Zoom function that set the windows scale first.. and I called WindowFit(). But It doesn't work..
XamMap's WindowFit adjusts the window rectangle to fit the map's WorldRect and this can change both WindowCenter and WindowScale. It seems to me that WindowFit does not need to be called, because your Zoom method does all the work.
As you can see,
But it doesn't work.