Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

xamarin.android - Xamarin.Forms and ESRI's MapView

I am having difficulties using a Xamarin.Forms TouchEffect with ESRI's map view on Android. Here are more details regarding the TouchEffect and ESRI's .net Xamarin Forms SDK.

The TouchEffect works on iOS and with other Xamarin.Forms controls but not with the map view on Android. I believe that the problem lies in how the touch event is propagated through the visual tree and is consumed by the map view control before the TouchEffect actually get's notified. I could be wrong with this assumption.
Here is a good post talking about events on Android.

Could anyone think of a workaround how to get the touch event to both the ESRI control and to the TouchEffect?

I have tried a couple of workarounds but to no avail.

  1. I tried to implement a Grid control with a custom renderer that would get notified of the touch events before any of its children. Ideally it would then pass the touch event to the mapview and to the touch efffect. This failed since I could not get a touch event by subscribing to the Touch event of the Android View for some reason. Using a GestureRecognizer instead does not cut it since it does not provide enough information.

  2. Listening to touch events in the Android's MainActivity and pass that information to the TouchEffect. I got the touch events in the MainActivity just fine but then I could not figure out which View was actually touched. This is especially a problem since other views will be overlaid on the map.

Here are some code excerpts showing the problem while the full code can be found here. I have the MapView control on top and a simple BoxView right underneath. When you tap either one of these you should get an alert popup which only works on Android when you are tapping the BoxView

Screenshot

enter image description here

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TouchTrackingEffectDemos"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:tt="clr-namespace:TouchTracking"
             x:Class="TouchTrackingEffectDemos.HomePage"
             Title="Touch Tracking Effect">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- MapView-->
        <Grid>
            <esriUI:MapView x:Name="MyMapView"/>
            <Grid.Effects>
                <tt:TouchEffect Capture="True" TouchAction="TouchEffect_MapView" />
            </Grid.Effects>
        </Grid>

        <!-- BoxView-->
        <Grid Grid.Row="1">
            <BoxView BackgroundColor="Blue"/>

            <Grid.Effects>
                <tt:TouchEffect Capture="True" TouchAction="TouchEffect_BoxView" />
            </Grid.Effects>
        </Grid>
        
    </Grid>
</ContentPage>

Code Behind

using System;
using System.Windows.Input;
using Esri.ArcGISRuntime.Mapping;
using TouchTracking;
using Xamarin.Forms;

    namespace TouchTrackingEffectDemos
    {
        public partial class HomePage : ContentPage
        {
            public HomePage()
            {
                InitializeComponent();
                MyMapView.Map = new Map(BasemapType.Imagery, 42.175131, 9.192313, 8);
                BindingContext = this;
            }
    
            private void TouchEffect_BoxView(object sender, TouchActionEventArgs args)
            {
                DisplayAlert("touch", "box view", "close");
            }
    
            private void TouchEffect_MapView(object sender, TouchActionEventArgs args)
            {
                DisplayAlert("touch", "map view", "close");
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...