I'm trying to add a layer of place labels above a GeoJSON layer, so that these labels remain visible. However when I add the layer per the code below, the tileLayer remains below the GeoJSON layer.
var CartoDB_PositronOnlyLabels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19,
zIndex: 3
});
CartoDB_PositronOnlyLabels.addTo(map);
Adding a few more things that don't work for the future reader:
- According to this leaflet PR you could add a
pane: 'overlayPane'
option upon layer creation. The hack appearing here and here only works if the tileLayer you're adding is of tileJSON format
var topPane = map._createPane('leaflet-top-pane', map.getPanes().mapPane); var topLayer = L.mapbox.tileLayer('lxbarth.map-vtt23b1i').addTo(map); topPane.appendChild(topLayer.getContainer()); topLayer.setZIndex(9);