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
560
Enabling only few states in USA map
posted

In a USA map, I want to enable highlighting and selection in only few states. How I can do that? Do I need to customize something in the map shape file? Or I can handle in code itself? Please help me.

Parents
No Data
Reply
  • 30692
    Offline posted

    Do you mean something like this?

    Markup:

    <UserControl x:Class="SilverlightApplication18.MainPage"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" xmlns:igMap="clr-namespace:Infragistics.Silverlight.Map;assembly=Infragistics.Silverlight.DataVisualization.Map.v9.2">

      <Grid x:Name="LayoutRoot">

            <igMap:XamWebMap x:Name="theMap" ElementClick="theMap_ElementClick">

                <igMap:XamWebMap.Layers>

                    <igMap:MapLayer Imported="MapLayer_Imported">

                        <igMap:MapLayer.Reader>

                            <igMap:ShapeFileReader Uri="ShapeFiles/usa_st" DataMapping="Name = STATE_NAME; Caption = STATE_NAME" />

                        </igMap:MapLayer.Reader>

                    </igMap:MapLayer>

                </igMap:XamWebMap.Layers>

            </igMap:XamWebMap>

        </Grid>

    </UserControl>

    Code:

    public partial class MainPage : UserControl

        {

            private Dictionary<String, Boolean> _allowedNames = new Dictionary<string, bool>();

     

            public MainPage()

            {

                InitializeComponent();

     

                _allowedNames.Add("New Jersey", true);

                _allowedNames.Add("Alaska", true);

            }

     

            private void MapLayer_Imported(object sender, Infragistics.Silverlight.Map.MapLayerImportEventArgs e)

            {

                foreach (MapElement ele in theMap.Layers[0].Elements)

                {

                    if (_allowedNames.ContainsKey(ele.Name))

                    {

                        ele.IsClickable = true;

                        ele.IsSelectable = true;

                    }

                    else

                    {

                        ele.IsClickable = false;

                        ele.IsSelectable = false;

                    }

                }

            }

     

            private void theMap_ElementClick(object sender, MapElementClickEventArgs e)

            {

                MessageBox.Show("You clicked on: " + e.Element.Name);

            }

        }

    Please let me know if you have any questions.

    -Graham

Children