我使用简单的位置选择器功能处理UWP(Win10)应用程序。用户可以在所需位置拖动地图。始终位于“地图”窗口中心的基本图钉充当位置指示器。它就像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(...)方法尝试了这一点,它运行得很好,但拖动地图时不需要点击它就需要它。
奶酪!
答案 0 :(得分:0)
我已经过测试和调试,MapHolding
事件也无法解决。出于您的目的,CenterChanged
Link事件可能会有所帮助,我也对其进行了测试。
以下是我的示例代码的一部分:
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
事件处理,但似乎忽略了此操作。所以请记住,如果用户持有地图而不移动地图,则不会发生任何事情。