-
Is there a way to change the z-order so that PMTiles labels are rendered after any other features are added to the map? I have found a way to do it, by using a Leaflet // Create Leaflet map.
var map = L.map('map')
// Add Protomaps tiles (no labels).
var pm_layer_no_labels = protomapsL.leafletLayer(
url: "my_map.pmtiles",
paint_rules: PAINT_RULES,
label_rules: [])
pm_layer_no_labels.addTo(map)
// Add some other line that must appear underneath the labels, but on top of the the tiles.
var geojsonLayer = new L.GeoJSON.AJAX(...)
geojsonLayer.addTo(map)
// Add PMTiles layer again (this time: labels only).
//
// First, create a new pane for the labels.
// https://leafletjs.com/examples/map-panes/
map.createPane('labels');
// Raise the labels so they will appear above the line feature.
map.getPane('labels').style.zIndex = 650;
// Disable pointer events for the labels, in case they block the line feature.
map.getPane('labels').style.pointerEvents = 'none';
//
// Add the PMTiles layer, but don't give any paint rules, only label rules.
// Be sure to specify the pane.
var pm_layer_labels_only = protomapsL.leafletLayer({
url: "my_map.pmtiles", // Same URL.
paint_rules: [],
label_rules: LABEL_RULES,
pane: 'labels',
})
pm_layer_labels_only.addTo(map) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Adding that enhancement would save on network traffic, but still you'd have duplicate canvas layer elements. Do you think that would make this approach efficient enough for your use case? |
Beta Was this translation helpful? Give feedback.
leafletLayer
can also take a PMTiles object instead of a URL. that means a single data instance will be shared across multiple leaflet layers. Right now this doesn't work ideally because it will combine header/directory requests across those two layers, but will not share the tile data requests. This could be a nice enhancement.Adding that enhancement would save on network traffic, but still you'd have duplicate canvas layer elements. Do you think that would make this approach efficient enough for your use case?