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

Execute a Command on Custom Marker tap

I've got custom markers displaying on an OpenStreetMap, with the following XAML:

                                    <maps:SfMaps Grid.Row="1"
                                                Markers="{Binding MapStations}"
                                                                WindForce="{Binding Station.LatestReading.WindForce}"
                                                                WindDirection="{Binding Station.LatestReading.WindDirectionAsInt}">

The WindIndicator control is a custom control which uses SkiaSharp to draw wind direction and strength.
I want to invoke a Command when the WindIndicator is tapped - how can I do this? I've tried adding a GestureRecognizer to the StackLayout in the DataTemplate, but I think the tap behaviour of the SfMaps control itself is intercepting the tap.

7 Replies

RA Rachel A Syncfusion Team September 9, 2019 10:41 AM UTC

Hi James, 
Greetings from Syncfusion. 
We have analyzed that your requirement is to perform an action when marker is tapped you can use MarkerSelected event in imagery layer. You can refer the below documentation link for more information. 
Also, we can use behavior to invoke the command for specific events using the below link. 
Please let us know if you have any concerns. 

JL James Lavery September 15, 2019 08:44 AM UTC

Thank you for the proposed solution.

I have got the MarkerSelected event working, but unfortunately an ImageryLayer does not have a Behaviors property, so I cannot add an EventToCommandBehavior to the ImageryLayer.

Do you have a suggested workaround?



RA Rachel A Syncfusion Team September 17, 2019 12:39 PM UTC

Hi James, 
Sorry for the inconvenience. 
Currently there is no support to achieve it using behaviors, but we can invoke the command from the selected event as explained in the below link 
Please find the snippet below 
  <maps:ImageryLayer x:Name="OpenStreetMap" 
      <local:CustomMarker  Latitude="50.8088760375977" Longitude= "-1.18579387664795"  /> 
public partial class MainPage : ContentPage 
    public MainPage() 
        this.BindingContext = new ColorMappingsViewModel(); 
    private void Layer_MarkerSelected(object sender, MarkerSelectedEventArgs e) 
        var colorMappingsViewModel = (ColorMappingsViewModel)BindingContext; 
        if (colorMappingsViewModel.TapCommand.CanExecute(e)) 
Please find the sample from the below link. 

JL James Lavery September 17, 2019 12:44 PM UTC

That's how I've worked around it without using Behaviors. Thank you for confirming that my approach is the only/best one.



VR Vignesh Ramesh Syncfusion Team September 18, 2019 07:14 AM UTC

Hi James, 

Thanks for your feedback and we are glad that on resolving your problem. 


CA Caleb January 20, 2023 07:05 PM UTC

Have behaviors been (re)implemented in the MAUI version? I can't seem to add a

map:MapShapeLayer.Behavior except for

map:MapShapeLayer.ZoomPanBehavior, which doesn't help on a MapMarker selected event. The only way I can see to solve this is through the non-MVVM approach of events on the view.


ET Eswaran Thirugnanasambandam Syncfusion Team January 23, 2023 09:22 AM UTC

Hi Caleb,

The MAUI SfMaps control supports behavior. We have prepared a sample to achieve your requirement and please get it from below attachment.



Attachment: MAUIMapSample_5d354c87.zip

Live Chat Icon For mobile
Up arrow icon