Win10 应用程序 - 按住和释放地图以操作界面上的元素



我正在开发一个具有简单位置选择器功能的UWP(Win10)应用程序。用户可以将地图拖动到所需的位置。始终位于"地图"窗口中心的基本Pushpin充当位置指示器。它的工作原理就像WhatsApp中的免费位置选择一样。为了给用户反馈他正在移动中心销,我想在用户移动地图时升高销,并在释放时再次降低销。

这里的简单代码来提高引脚(和操作阴影):

private void MyMap_MapHolding(MapControl sender, MapInputEventArgs args)
    {
        iconSwitch = true;
        if(iconSwitch == true) {
            centerPin.Margin = new Thickness(0, 0, 0, 60);
            centerPinShadow.Opacity = 0.3;
            centerPinShadow.Width = 25;
     }

但是这个事件似乎没有受到点击的影响;按住或点击&持有我是不是错过了什么?

仅供参考:我用MyMap_MapTapped(…)方法尝试了这个方法,它运行得很好,但当拖动地图而不仅仅是点击地图时,我需要它。

奶酪!

我已经测试和调试过了,MapHolding事件也不能正常工作。出于您的目的,CenterChanged链接事件可能会有所帮助,我也测试过它。

这是我的示例代码的一部分:

RandomAccessStreamReference mapIconStreamReference;
public Maptest()
{
    this.InitializeComponent();            
    myMap.Loaded += MyMap_Loaded;
    myMap.MapTapped += MyMap_MapTapped;
    myMap.MapHolding += MyMap_MapHolding;
    myMap.CenterChanged += MyMap_CenterChanged;
    mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/MapPin.png"));
}
private void MyMap_Loaded(object sender, RoutedEventArgs e)
{
    myMap.Center =
        new Geopoint(new BasicGeoposition()
        {
            //Geopoint for Seattle 
            Latitude = 47.604,
            Longitude = -122.329
        });
    myMap.ZoomLevel = 12;      
}
private void MyMap_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var tappedGeoPosition = args.Location.Position;
    string status = "MapTapped at nLatitude:" + tappedGeoPosition.Latitude + "nLongitude: " + tappedGeoPosition.Longitude;
    rootPage.NotifyUser( status, NotifyType.StatusMessage);
}
private void MyMap_MapHolding(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var holdingGeoPosition = args.Location.Position;
    string status = "MapHolding at nLatitude:" + holdingGeoPosition.Latitude + "nLongitude: " + holdingGeoPosition.Longitude;
    rootPage.NotifyUser(status, NotifyType.StatusMessage);
}
private void MyMap_CenterChanged(Windows.UI.Xaml.Controls.Maps.MapControl sender, object obj)
{
    MapIcon mapIcon = new MapIcon();
    mapIcon.Location = myMap.Center;
    mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
    mapIcon.Title = "Here";
    mapIcon.Image = mapIconStreamReference;
    mapIcon.ZIndex = 0;
    myMap.MapElements.Add(mapIcon);
}

起初我认为,即使在MapHoling事件不能工作的情况下,持有之前的Tapped操作也应该由MapTapped事件处理,但似乎这个操作被忽略了。所以请记住,如果用户持有Map但不移动它,则不会发生任何事情。

最新更新