JamesLMilner / terra-draw

A library for drawing on maps that supports Mapbox, MapLibre, Google Maps, OpenLayers and Leaflet out the box
https://terradraw.io
MIT License
457 stars 54 forks source link

[Enhancement] Keep layers on top (Mapbox/Maplibre) #63

Open alanOracle opened 1 year ago

alanOracle commented 1 year ago

If you add layers to the map while you are using terra draw in maplibre or mapbox then those layers could be added above terra draw ones. It would be nice to have them always on top.

One solution could be implemented at the end of render method of mapbox gl adapter

// Make sure terradraw layers are on top of all others
["point", "linestring", "polygon"].forEach(geometryKey => {
    const id = `td-${geometryKey.toLowerCase()}`;
    if (this._map.getLayer(id)) this._map.moveLayer(id);
    if (geometryKey === "polygon") if (this._map.getLayer(id + "-outline")) this._map.moveLayer(id + "-outline");
});
JamesLMilner commented 1 year ago

Hey @alanOracle - thanks for this! Think you are saying you want to keep the Terra Draw layers on top right?

alanOracle commented 1 year ago

Affirmative.