We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Multiple markers on the same map layer

Good day,

Can you please assist with a sample on how to add multiple markers on the same shapefile layer.

Thanks.

9 Replies

MK Muneesh Kumar G Syncfusion Team December 10, 2018 10:08 AM UTC

Hi Nico, 
 
Thanks for using Syncfusion products.  
 
We have analyzed your requirement and you can achieve that using Markers collection in SfMaps.  You can add multiple markers to the same shape file layer as per the below code snippet. 
 
Code snippet.  
 
 
       private void SfMap_SizeChanged(object sender, SizeChangedEventArgs e) 
        { 
            var markers = (map.Layers[0] as ShapeFileLayer).Markers; 
            if (markers == null) 
                (map.Layers[0] as ShapeFileLayer).Markers = viewModel.Models;         
        }         
 
 
You can specify the underlying collection as in the below code snippet. 
 
this.Models = new ObservableCollection<Model>(); 
            this.Models.Add(new Model() { Name = "USA ", Latitude = "38.8833N", Longitude = "77.0167W" }); 
            this.Models.Add(new Model() { Name = "Brazil ", Latitude = "15.7833S", Longitude = "47.8667W" }); 
            this.Models.Add(new Model() { Name = "India ", Latitude = "21.0000N", Longitude = "78.0000E" }); 
            this.Models.Add(new Model() { Name = "China ", Latitude = "35.0000N", Longitude = "103.0000E" }); 
            this.Models.Add(new Model() { Name = "Indonesia ", Latitude = "6.1750S", Longitude = "106.8283E" }); 
 
 
We have also prepared a sample for the same. You can download the sample from the below location. 
 
 
 
Output Image: 
 
 
 
Please refer below user documentation for more details about SfMaps Markers.  
 
 
Hope it helps you.  
 
Regards, 
Muneesh Kumar G. 



NI Nico December 11, 2018 12:45 AM UTC

Good day,

Thanks you for the information. I need a bit more information in regards with the markers. 

Would it be possible to use multiple observableCollection models for different markers in the same map layer like the below example does it for multiple sub map layers:

Models1 = new ObservableCollection(); 
Models2 = new ObservableCollection(); 
   SubShapeFileLayer
                            Markers="{Binding Models1}"
                            Opacity="0.6"
                            ShapeIDPath="NAME"
                            ShapeIDTableField="NAME"
                            Uri="ShapeFiles.world1.shp">
     SubShapeFileLayer.ShapeSettings
                                ShapeSetting ShapeFill="Green" ShapeValuePath="Latitude"
                                    ShapeSetting.FillSetting
                                       ShapeFillSetting AutoFillColors="False" 
                                    ShapeSetting.FillSetting
                               ShapeSetting
                            SubShapeFileLayer.ShapeSettings
                            SubShapeFileLayer.MarkerTemplate
                                DataTemplate
                                    Border x:Name="Marker1" Visibility="Visible"
                                       Grid
                                            Polygon
                                                Grid.Row="0"
                                                Grid.Column="0"
                                                Fill="Red"
                                                Points="0,0, 12,8.5, 0,15"
                                                Stroke="Black" />
                                            TextBlock
                                                Margin="1,2.5,0,0"
                                                FontSize="8"
                                                Foreground="White">
                                                1
/TextBlock
                                        /Grid
                                   /Border
                                /DataTemplate
                            /SubShapeFileLayer.MarkerTemplate
                        /SubShapeFileLayer>
                        SubShapeFileLayer
                                                    Markers="{Binding Models2}"
                            Opacity="0.6"
                            ShapeIDPath="NAME"
                            ShapeIDTableField="NAME"
                            Uri="ShapeFiles.world1.shp">
 SubShapeFileLayer.ShapeSettings
                                ShapeSetting ShapeFill="Green" ShapeValuePath="Latitude"
                                    ShapeSetting.FillSetting>
                                        ShapeFillSetting AutoFillColors="False" 
                                    /ShapeSetting.FillSetting
                                /ShapeSetting
                            /SubShapeFileLayer.ShapeSettings
                            SubShapeFileLayer.MarkerTemplate
                                DataTemplate
                                    Border x:Name="Marker2" Visibility="Visible"
                                        Grid
                                            Polygon
                                                                                            Grid.Row="0"
                                                Grid.Column="0"
                                                Fill="Purple"
                                                Points="7,0, 15,15, 0,15"
                                                Stroke="Black" />
 /Grid
                                    /Border
                                /DataTemplate
                            /SubShapeFileLayer.MarkerTemplate
                        /SubShapeFileLayer

Regards,


MK Muneesh Kumar G Syncfusion Team December 11, 2018 06:30 AM UTC

Hi Nico, 
 
Thanks for your update. We have analyzed your requirement and you can use multiple collections for markers in sublayer as per the below code snippet. 
 
Code snippet 
 
               <syncfusion:ShapeFileLayer.SubShapeFileLayers> 
 
                        <syncfusion:SubShapeFileLayer x:Name="africaLayer"  
                                    MarkerTemplate="{StaticResource markerTemplate}"  
                                                       
                                    Uri="MapsWPF.ShapeFiles.Africa.shp"> 
                            
.. 
                        </syncfusion:SubShapeFileLayer> 
 
                        <syncfusion:SubShapeFileLayer x:Name="australiaLayer"    
                                    Markers="{Binding Australia}"  
                                    MarkerTemplate="{StaticResource markerTemplate}"                                                   
                                                       
                                    Uri="MapsWPF.ShapeFiles.australia.shp"> 
.. 
                            
                        </syncfusion:SubShapeFileLayer> 
 
                    </syncfusion:ShapeFileLayer.SubShapeFileLayers> 
 
private void SfMap_SizeChanged(object sender, SizeChangedEventArgs e) 
        { 
            if (australiaLayer.Markers == null) 
                australiaLayer.Markers = viewModel.Australia; 
            if (africaLayer.Markers == null) 
                africaLayer.Markers = viewModel.Africa;            
        }    
 
 
We have modified our sample based on this, please find the sample from the following location.  
 
 
In the below image highlighted areas are the two sublayers with multiple markers in it. 
 
Output Image:  
 
 
 
Hope it helps you.  
 
Regards, 
Muneesh Kumar G. 



NV Nico van der Merwe December 11, 2018 08:27 AM UTC

Hi,

Is there a way to use the viewmodel.Australia and viewmodel.Africa in the same same subshapefilelayer or can you load marker for a subshapefilelayer without using a URI for it.

Regards,


MK Muneesh Kumar G Syncfusion Team December 11, 2018 10:23 AM UTC

Hi Nico, 
 
Thanks for your update, we have analyzed your query and we would like to inform you that in a single shape file layer must be bind with single markers collection. If you like to use more markers collection with single shape layer, you can set the one markers collection to main shape file and another markers collection to sub shape layer.  
 
And, shape layer will not be rendered without Uri property.  
 
We would like to know your exact scenario of using multiple markers collections in your application, so that we can guide you accordingly. So please update us more information about your requirement that would be helpful for us to give better solution in this.  
 
Regards, 
Muneesh Kumar G. 



NV Nico van der Merwe December 11, 2018 10:54 AM UTC

Hi,

Please see attached an image of the markers I am using for event on the map. Each marker will be driven by a separate collection which I want to put on the map when it need to be there. The reason I am asking is because it seems like some of the makers disappears behind the last loaded uri. Is it possible to load a transparent shapefile in the uri for the markers?




Attachment: MicrosoftTeamsimage_9307bf14.zip


MK Muneesh Kumar G Syncfusion Team December 12, 2018 09:38 AM UTC

Hi Nico, 
 
Thanks for your update, please find the response below.  
 
Query: Is it possible to load a transparent shape file. 
 
Yes. You can fill the shape file and sub shape file with transparent color by setting ShapeFill as Transparent as per the below code snippet.  
 
Sub shape file: 
 
<syncfusion:SubShapeFileLayer.ShapeSettings> 
                                <syncfusion:ShapeSetting ShapeStroke="Transparent"  ShapeFill="Transparent">                                   
                                </syncfusion:ShapeSetting> 
                            </syncfusion:SubShapeFileLayer.ShapeSettings> 
 
By using the above code snippet, you could visible only the Markers you have added. 
 
Also, we would like to inform you that adding markers to both sub layer and the main shape file layer, markers of both the layers will be visible. Sub layers will not be hiding the markers in the main shape layer. 
 
Still, we could not get the exact context of your requirement of having multiple markers collection. Hence, if the provided solution does not meet your requirement or if it different from the above stated please provide us the simple sample depicting your requirement, this would be helpful for us to give better solution in this.  
 
Regards, 
Muneesh Kumar G. 



NV Nico van der Merwe December 13, 2018 06:52 AM UTC

Thanks you for the information


MK Muneesh Kumar G Syncfusion Team December 13, 2018 08:58 AM UTC

Hi Nico, 
 
You are welcome and please let us know if you have any other queries.  
 
Thanks, 
Muneesh Kumar G. 


Loader.
Up arrow icon