0

I have three base layers in a layer group

var baseLayers = {"Straßenkarte": osmLayer, "Luftbild": bingLayer, "Luftbild mit Straßennamen": bingLabelLayer};

makes my control. After

L.control.layers(baseLayers).addTo(map)

the last layer metioned there is shown on top. I can draw another layer on top with zIndex or for example

bingLayer.bringToFront()

But in this case, the layer marked in the control does not change. How can I alter this (sorry, leaflet-dummy)?

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
wonk
  • 21
  • 5

1 Answers1

0

Welcome to SO!

What you have probably missed is that the visibility of your basemaps should be modified by directly adding them to / removing them from the map, instead of fiddling with their z-index / DOM position with bringToFront.

Then the Leaflet Layers Control automatically syncs its selection when you programmatically add / remove Layers it knows.

ghybs
  • 47,565
  • 6
  • 74
  • 99
  • Hm, I tried adding the layers directly to the map without a layerGroup. This does not alter anything. It does not alter anything, if I change the order of adding the layers to the map. Look here: my tests – wonk Jan 20 '19 at 10:24
  • You are very probably still adding too many basemaps to your map simultaneously (either with addTo, addLayer or with map layers option). Only one should be added at a time, independently from what you pass to the 1st argument of L.control.layers – ghybs Jan 20 '19 at 18:15