简体   繁体   中英

How to get MapElement tapped type (MapControl) (Windows 10 universal app)

With the new Windows 10 Family device, visual studio begins to have a new event handler. the MapElementClickEventArgs, that allows to developer to get actions from a MapElement tapped, but i want to give diferent actions for each type of MapElement selected. Ex: an action for MapIcons and a diferent action for MapPolygons

Someone knows how i cant get the type of the entity tapped?

this is the model of this handler:

private void MapControl1_MapElementClick(MapControl sender, MapElementClickEventArgs args) { }

In the Windows 10 map control an array of all MapElements that intersect with where you clicked on the map will be returned. If you loop through each element you can check to see if it is a MapIcon, or other MapElement by using the "is" keyword. Here is an extended version of your code:

private void MapControl1_MapElementClick(MapControl sender, MapElementClickEventArgs args)
{
    foreach (var e in args.MapElements)
    {
        if (e is MapPolygon)
        {
            var poly = e as MapPolygon;
            //Is MapPolygon
        }
        else if (e is MapPolyline)
        {
            var poly = e as MapPolyline;
            //Is MapPolyline
        }
        else if (e is MapIcon)
        {
            var icon = e as MapIcon;
            //Is MapIcon
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM