Search code examples
uwpuwp-xamluwp-maps

UWP: Refresh MapElementsLayer


I have a MapLayer defined on my MapControl using the following:

<maps:MapControl x:Name=“MyMap”
[…]
Layers=“{x:Bind ViewModel.Layers}”>

I defined a MapElementsLayer and added it to my MapLayer.

I now programmatically create elements and add them to my MapElementsLayer. My issue is that when I add new elements, or delete the elements that are already there, they do not draw/clear on the map. The only way I have been able to get them to update, is to delete the map layer, and re-add it. This process is resource intensive and halts the UI thread for a number of seconds each time.

Is there anyway to update the contents of a MapLayer/MapElementsLayer and trigger a redraw? I have searched the documentation and cannot find a way to trigger a redraw.

Thanks, John


Solution

  • Derive from your description, you may use List to insert Layers, if you want to update the Layers by removing the source data, please use use ObservableCollection to replace List that could represent a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed. For more please refer to this document.

    public ObservableCollection<MapLayer> LandmarkLayer
        { get; } = new ObservableCollection<MapLayer>();