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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Execute a Command on Custom Marker tap

Thread ID:

Created:

Updated:

Platform:

Replies:

147376 Sep 8,2019 07:20 PM UTC Sep 18,2019 07:14 AM UTC Xamarin.Forms 5
loading
Tags: SfMaps
James Lavery
Asked On September 8, 2019 07:20 PM UTC

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

                                    <maps:SfMaps Grid.Row="1"
                                                 Grid.Column="0"
                                                 Grid.ColumnSpan="2"
                                                 x:Name="Map"
                                                 MinZoom="11"
                                                 EnableZooming="true"
                                                 ZoomLevel="10"
                                                 MaxZoom="13">
                                        <maps:SfMaps.Layers>
                                            <maps:ImageryLayer
                                                x:Name="OpenStreetMap"
                                                Markers="{Binding MapStations}"
                                                GeoCoordinates="50.8088760375977,-1.18579387664795">
                                                <maps:ShapeFileLayer.MarkerTemplate>
                                                    <DataTemplate>
                                                        <StackLayout>
                                                            <controls:WindIndicator
                                                                WidthRequest="70"
                                                                HeightRequest="70"
                                                                WindForce="{Binding Station.LatestReading.WindForce}"
                                                                WindDirection="{Binding Station.LatestReading.WindDirectionAsInt}">
                                                            </controls:WindIndicator>
                                                        </StackLayout>
                                                    </DataTemplate>
                                                </maps:ShapeFileLayer.MarkerTemplate>
                                                </maps:ImageryLayer>
                                        </maps:SfMaps.Layers>
                                    </maps:SfMaps>

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.

Rachel A [Syncfusion]
Replied On 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. 
 
Thanks, 
Rachel. 


James Lavery
Replied On 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?

Regards,

James

Rachel A [Syncfusion]
Replied On 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 
 
[XAML]: 
 
<maps:SfMaps.Layers> 
  <maps:ImageryLayer x:Name="OpenStreetMap" 
                     GeoCoordinates="50.8088760375977,-1.18579387664795" 
                     MarkerSelected="Layer_MarkerSelected"> 
    <maps:ImageryLayer.Markers> 
      <local:CustomMarker  Latitude="50.8088760375977" Longitude= "-1.18579387664795"  /> 
    </maps:ImageryLayer.Markers> 
    … 
</maps:SfMaps.Layers> 
 
 
[C#]: 
 
public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
        InitializeComponent(); 
        this.BindingContext = new ColorMappingsViewModel(); 
    } 
 
    private void Layer_MarkerSelected(object sender, MarkerSelectedEventArgs e) 
    { 
        var colorMappingsViewModel = (ColorMappingsViewModel)BindingContext; 
 
        if (colorMappingsViewModel.TapCommand.CanExecute(e)) 
        { 
            colorMappingsViewModel.TapCommand.Execute(e); 
        } 
    } 
} 
 
 
Please find the sample from the below link. 
 
Regards, 
Rachel. 


James Lavery
Replied On 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.

Regards,

James

Vignesh Ramesh [Syncfusion]
Replied On September 18, 2019 07:14 AM UTC

Hi James, 

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

Regards, 
Vignesh. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon