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
335
How to display a secondary layer by clicking on a layer
posted
I have a map with 4 layers: country, city, village, ...

the goal is that when the user clicks on a country, display city layer (centered in the country). When you click on a city, people look the village, centered in the city, ...

In addition, each layer must have a MapColorSwatchPane  or change the property LayerName of MapColorSwatchPane.

Now to enter the city, village, ... I have checked the property and operates VisibleFromScale to zoom in MapNavigationPane but not by clicking on the map.
Example: The original map is the world. When you click on Europe, the map show the countries layer, with the map centered on Europe. When you click on Spain, the map sohw the layer of autonomous communities, centering the map in Spain, ...
Parents
  • 3255
    Suggested Answer
    posted

    Hi jcsanchezr

    You can attach to XamMap's ElementClick event and then call XamMap's WindowFit method to adjust the window rectangle to fit the clicked element. E.g.:

    In XAML

    <Maps:XamMap x:Name="xamMap" ElementClick="xamMap_ElementClick">
     <Maps:XamMap.Layers>
      <Maps:MapLayer x:Name="worldLayer">
       <Maps:MapLayer.Reader>
        <Maps:ShapeFileReader Uri="ShapeFiles/world/world" DataMapping="Name=CNTRY_NAME; Caption=CNTRY_NAME; Value=POP_CNTRY" />
       </Maps:MapLayer.Reader>
      </Maps:MapLayer>

      <Maps:MapLayer VisibleFromScale="1.7" Brushes="#FF3969A5 #FF71A1DA" x:Name="statesLayer">
       <Maps:MapLayer.Reader>
        <Maps:ShapeFileReader Uri="ShapeFiles/usamap/states" DataMapping="Name=STATE; Caption=STATE" />
       </Maps:MapLayer.Reader>
      </Maps:MapLayer>            

     </Maps:XamMap.Layers>

     <Maps:MapNavigationPane HorizontalAlignment="Left" />

    </Maps:XamMap>

    Code behind:

    private void xamMap_ElementClick(object sender, MapElementClickEventArgs e)
    {
     xamMap.WindowFit(e.Element);
    }

    Please let me know if this works for you.

    Regards,

    Ivan Kotev

Reply Children