How to create MapIcon event in UWP?

I want to add pushpins to my MapControl, which can be used. Since the pushpin class from Windows 8.1 is no longer available, and UWP offers us something called ImageIcon (imo its kind of crappy). Here is my code:

BasicGeoposition bg = new BasicGeoposition() { Latitude = 52.280, Longitude = 20.972 }; Geopoint snPoint = new Geopoint(bg); MapIcon mapIcon1 = new MapIcon(); mapIcon1.Location = snPoint; mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0); MyMap.MapElements.Add(mapIcon1); 

How can I do event processing (e.g. click or click)?

Thank you in advance

+5
source share
1 answer

In UWP, you can add a lot more elements to the map, and the click event is handled in a completely different way - see MapControl.MapElementClick . Events are handled by MapControl - therefore, you do not need to subscribe to each element of the map - the specified event will return a list of clicked elements. Sample code might look like this:

 <map:MapControl Name="MyMap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MapElementClick="MyMap_MapElementClick"/> 
 private void MyMap_MapElementClick(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapElementClickEventArgs args) { MapIcon myClickedIcon = args.MapElements.FirstOrDefault(x => x is MapIcon) as MapIcon; // do rest } 
+8
source

Source: https://habr.com/ru/post/1238743/


All Articles