I want display only a certain area on a map. I tried using WindowRect WindowZoom and WindowScale.
Could any one gives me an example?
thanks in advance
Could any one help me please?
You can determine the outer bounds of the elements you want to display and set that to the window rect. For example, with the states sample if I call this on imported:
private void usaLayer_Imported(object sender, MapLayerImportEventArgs e) { double minY = double.MaxValue; double maxY = double.MinValue; double minX = double.MaxValue; double maxX = double.MinValue; foreach (MapElement ele in (sender as MapLayer).Elements) { if (ele.Name == "Iowa" || ele.Name == "Indiana") { minY = Math.Min(minY, ele.WorldRect.Top); maxY = Math.Max(maxY, ele.WorldRect.Bottom); minX = Math.Min(minX, ele.WorldRect.Left); maxX = Math.Max(maxX, ele.WorldRect.Right); } } if ((sender as MapLayer).Elements.Count > 0) { theMap.WindowRect = new Rect(minX, minY, maxX - minX, maxY - minY); } }
It will snap the screen to contain Iowa and Indiana.
-Graham
Thanks Graham,
I've a problem, I've used your code but in the Imported method, the foreach loop is empty (there are no elements).
This is my xaml:
<igMap:XamWebMap x:Name="map1" ElementClick="map1_ElementClick" >
<igMap:XamWebMap.Layers >
<igMap:MapLayer x:Name="LayerItalia" DataMapping="Name=CountryName; Value=NAME_1" Loaded="map1_Loaded" Imported="map1_Imported">
<igMap:MapLayer.Reader>
<igMap:ShapeFileReader Uri="Shapefiles/ITA_adm2" DataMapping="Name, Caption=NAME_2" >
<igMap:ShapeFileReader.CoordinateSystem>
<igMap:CoordinateSystem>
<igMap:CoordinateSystem.Projection>
<igMap:SphericalMercator/>
</igMap:CoordinateSystem.Projection>
</igMap:CoordinateSystem>
</igMap:ShapeFileReader.CoordinateSystem>
</igMap:ShapeFileReader>
</igMap:MapLayer.Reader>
</igMap:MapLayer>
</igMap:XamWebMap.Layers>
</igMap:XamWebMap>
Thanks
Imported will get called multiple times indicating the status of the mapfile import, so you could display a status bar. It will have an action of
MapLayerImportAction.End
when it is finished importing.
I also found Imported got called multiple times.
Would you please explain why Imported can often get called multiple times?
Imported can often get called multiple times, if you are debugging, its best to wrap your logic in a conditional that the element count is greater than 0.