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
50
Binding a map layer to a collection
posted

The previous post was messy a bit, so here is a cleaner one.

I have a list of elements. I'm trying to create a map layer with elements which are binded that list. In the code below there is a mapLayer called "EndpointsIcon Layer" and the datasource is binded to the list. I'm using dataMapping to place icons on the map according to the location of each element in the list. Unfortunately it doesn't work. When running the program i can see the map but not the icons.

Does anyone know what can cause the problem?

Thanks.

 

 <igMap:XamMap x:Name="theMap" Margin="5" Background="Transparent" ViewportBackground="Transparent">   

   <igMap:XamMap.Layers>

        <igMap:MapLayer LayerName="statesLayer" FillMode="RandomInterpolate" Style="{StaticResource MapStyle}" ToolTip="{}{Name}: Pop. {Value:n0}">

            <igMap:MapLayer.Reader>

              <igMap:ShapeFileReader  Uri="ShapeFiles/world"/>

            </igMap:MapLayer.Reader>

        </igMap:MapLayer>

        <igMap:MapLayer LayerName="EndpointsIconsLayer"  IsAutoWorldRect="True" DataMapping="Value=Val;ToolTip=Str;SymbolOrigin=Poi;"  DataSource="Try">

            <igMap:MapLayer.ValueTemplate>

              <DataTemplate>

                <Image Width="40" Height="40"  Source="/NC.Client.Silverlight.Infra;component/Resources/Images/add_big.png" Stretch="UniformToFill"/>

              </DataTemplate>

            </igMap:MapLayer.ValueTemplate>

          </igMap:MapLayer>

        </igMap:XamMap.Layers>

    <igMap:MapThumbnailPane Width="150" Height="100" HorizontalAlignment="Center" Margin="0,0,0,10" Background="Transparent"  igControls:XamDock.Edge="InsideBottom" Style="{StaticResource MapThumbnailStyle}"/>

    <igMap:MapNavigationPane Margin="5" igControls:XamDock.Edge="InsideRight"  HorizontalAlignment="Center"/>

</igMap:XamMap>

 

Parents
No Data
Reply
  • 28496
    Offline posted

    i was questioning for a while whether this was possible or not ... but it is, for the most part.  however, your DataSource setting will not add MapElements to the layer.  you must do this in code:

    foreach (DataPoint current in myData)

    {

    this.xamMap1.Layers[0].Elements.Add(new SymbolElement() { Name = current.Str });

    }

    notice how I am setting the Name property of each MapElement.  you must also add a "Name=" token to your layer's DataMapping, in order to match this.

    <igMap:MapLayer SymbolType="Pyramid" DataSource="{StaticResource data}" DataMapping="Name=Str;Value=Val;ToolTip=Str;SymbolOrigin=Poi;" />

    you must also ensure that the layer's WorldRect property is set (normally this is done by the ShapeFileReader).

    this.xamMap1.Layers[0].WorldRect = new Rect(0, 0, 100, 100);

    i have attached the sample project.

    SilverlightApplication11.zip
Children
No Data