Hi,
For a particular MapElement, we can use map.WindowFit(element).
I'd like to know How i could display a group of MapElement to be shown at the center of xamMap.
Thanks.
NNT
Hi NNT,
I assume this is because some of the countries have sparse territory and they bend the final result. I have tried to center North America Continent with MapWindow GIS and the result is the same.
As a workaround I have tried to filter out part of the countries or to add a point which shifts the center to the right. Try to exclude one or two countries from the group.
Regards,
Ivan Kotev
Hi Ivan,
It works to some extent. But the groups of elements don't show exactly at the center.
For example, the groups of north america (the whole America Continent) cannot be shown at the center.
Could u point out the necessary things to do?
You can use XamMap's WindowRect to get or set the window rectangle used to render the map, e.g.:
In XAML:
<igMap:XamMap x:Name="xamMap" ElementClick="MyMap_ElementClick"> <igMap:XamMap.Layers> <igMap:MapLayer x:Name="States"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="Shapefiles/world/world" DataMapping="Name, Caption, ToolTip=CNTRY_NAME"/> </igMap:MapLayer.Reader> </igMap:MapLayer> </igMap:XamMap.Layers></igMap:XamMap>
In Code behind:
private void MyMap_ElementClick(object sender, MapElementClickEventArgs e){ var group = new[] { "France", "Switzerland", "Italy" };
if (group.Contains(e.Element.Caption)) { var rect = xamMap.Layers[0].Elements["France"].First().WorldRect; rect.Union(xamMap.Layers[0].Elements["Switzerland"].First().WorldRect); rect.Union(xamMap.Layers[0].Elements["Italy"].First().WorldRect);
xamMap.WindowRect = rect; } }
I am using the World shapefile. If you click on France, Switzerland ot Italy XamMap will combine their bounds and will center the map. You could also use XamMap's WindowCenter for that.
Please let me know if that works for you.