UWP Mapcontrol - Binding to collections of different MapElement and arranging them in layers

553 views Asked by At

I am displaying several different types of MapElements on the UWP MapControl and regularly updating their position, size, etc. as the user works with the map. Currently I do all of this in code. I'd like to find a convenient way of binding multiple different collections of MapElements, as then I'd have less code to maintain.

With Creator's fall update 16299 Microsoft has added the MapElementsLayer class, and It appears to be perfect for the job, but I cannot get it to work. When I bind it to an ObservableCollection of MapElement3D I don't see any of them appear on the map. What am I doing wrong?

<Maps:MapControl 
        x:Name="MainMap"           
        MapProjection="Globe"
        ZoomLevel="15.5"

        <Maps:MapElementsLayer x:Name="Cars"  MapElements="{x:Bind _VehicleCollection, Mode=OneWay}"  />

 </Maps:MapControl>
1

There are 1 answers

2
Sunteen Wu On BEST ANSWER

I'd like to find a convenient way of binding multiple different collections of MapElements, as then I'd have less code to maintain.

As you mentioned, map layering APIs can help represent a collection of map data to which you can bind data. Unlike the existing MapControl.MapElements API, this can be used to manipulate groups of elements independently as a unit or to designate a joint purpose.

But you need to bind data collection to the map using MapControl.Layers. This is something that you can't do by using the MapElements collection. More details about map layering APIs and how to do please reference Working with layers. For example:

<Maps:MapControl
    x:Name="myMap"
    Layers="{x:Bind ViewModel.LandmarkLayer}"
    MapProjection="Globe"
    MapServiceToken="Your token" />

You need to bind layers collection to MapControl.Layers property.