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
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
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
Could any one help me please?