Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
712
Showing a group of elements at the center of xamMap
posted

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

 

 

Parents
No Data
Reply
  • 3255
    posted

    Hi NNT,

    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.

    Regards,

    Ivan Kotev

Children