This project has moved and is read-only. For the latest updates, please go here.

Change TileLayers At Runtime

Jul 11, 2015 at 3:35 PM

here is my map configuration:
<map:Map x:Name="SurpolMap" Grid.Column="0" Grid.ColumnSpan="2"
                 Center="{Binding MapVM.Center, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
                 ZoomLevel="{Binding MapVM.ZoomLevel, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
                 TargetCenter="{Binding MapVM.TargetMapCenter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 TargetZoomLevel="{Binding MapVM.TargetZoomLevel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 MaxZoomLevel="20" MinZoomLevel="1"
                 TileLayers="{Binding MapVM.LayerCollection}"
As you can see i use TileLayers and the property is binded to LayerCollection :
private ObservableCollection<TileLayer> layerCollection = new ObservableCollection<TileLayer>();
        public ObservableCollection<TileLayer> LayerCollection
            get { return layerCollection; }
                layerCollection = value;
In my mind each layer of the layer collection should display and the last index should be on top. Is that right ?

When i clear() the layer collection and add a new one the map doesn't update correctly :
  • the old layer is steel visible
  • the new one is under the second and appears under the old layer.
Could you help me ?

Jul 11, 2015 at 5:11 PM
This works for me. How do you actually change your LayerCollection?
Jul 14, 2015 at 7:45 AM
You were right and thanks for help.

I changed the way i manage layer in Observable collection. I was doing a Clear(); and than i add new layers.
Now i remove layers one by one (if needed) and i add new ones.

Thanks again.
Jul 14, 2015 at 8:19 AM
There is no reason why Clear() shouldn't also work.
Jul 16, 2015 at 2:32 PM
yes thats what i thought.
But at least i don't see what else in my modification list that can explain the behaviour observed.

For now it is ok but i don't know exactly what was wrong in my code.
Maybe i should stop drinking beers :).