Map Shape Labels in WPF Maps (SfMap)

18 Aug 20214 minutes to read

Labels for map shapes can be displayed by using the LabelPath of ShapeFileLayer. The value of LabelPath must be a field name specified in the .dbf file corresponding to the shapefile.

Property Type Description
LabelPath string Gets or sets the field name in the database (.dbf) file.
<syncfusion:SfMap>
            <syncfusion:SfMap.Layers>
                <syncfusion:ShapeFileLayer x:Name="shapeFileLayer"   
                                       Uri="DataMarkers.ShapeFiles.world1.shp"  
                                       LabelPath="NAME" FontSize="14">
                </syncfusion:ShapeFileLayer>
            </syncfusion:SfMap.Layers>
        </syncfusion:SfMap>
SfMap map = new SfMap();          
            ShapeFileLayer shapeFileLayer = new ShapeFileLayer();
            shapeFileLayer.LabelPath = "NAME";
            shapeFileLayer.FontSize = 14;
            shapeFileLayer.Uri = "DataMarkers.ShapeFiles.world1.shp";
            map.Layers.Add(shapeFileLayer);
            this.Content = map;

The labels can also be customized by modifying the ItemsTemplate of ShapeFileLayer. The labels can be accessed by using DBFData as follows:

<Grid.Resources>
            <DataTemplate x:Key="itemtemplate">
                <Grid >
                    <TextBlock Text="{Binding DbfData[NAME]}"
                                       FontSize="14" Margin="10 5"/>
                </Grid>
            </DataTemplate>
        </Grid.Resources>

         <syncfusion:SfMap>
            <syncfusion:SfMap.Layers>
                <syncfusion:ShapeFileLayer Uri="DataMarkers.ShapeFiles.world1.shp"
                                       LabelPath="NAME" ItemsTemplate="{StaticResource itemtemplate}">
                   
                </syncfusion:ShapeFileLayer>
            </syncfusion:SfMap.Layers>
        </syncfusion:SfMap>
SfMap map = new SfMap();          
            ShapeFileLayer shapeFileLayer = new ShapeFileLayer();
            shapeFileLayer.LabelPath = "NAME";
            shapeFileLayer.Uri = "DataMarkers.ShapeFiles.world1.shp";
            shapeFileLayer.ItemsTemplate = grid.Resources["itemTemplate"] as DataTemplate;
            map.Layers.Add(shapeFileLayer);
            this.Content = map;

Maps control Shape labels

NOTE

You can refer to our WPF Map feature tour page for its groundbreaking feature representations. You can also explore our WPF Map example to know how to render and configure the map.