Win10 App - 按住和释放地图来操作界面上的元素
Win10 App - Holding & Releasing the map to manipulate an element on the interface
我正在开发具有简单位置选择器功能的 UWP (Win10) 应用程序。用户可以将地图拖动到想要的位置。始终位于地图 window 中心的基本图钉用作位置指示器。它的工作原理就像 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
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
事件处理,但似乎这个动作被忽略了。所以请记住,如果用户按住 Map 但不移动它,则什么也不会发生。
我正在开发具有简单位置选择器功能的 UWP (Win10) 应用程序。用户可以将地图拖动到想要的位置。始终位于地图 window 中心的基本图钉用作位置指示器。它的工作原理就像 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
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
事件处理,但似乎这个动作被忽略了。所以请记住,如果用户按住 Map 但不移动它,则什么也不会发生。