aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-07-22 16:18:59 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-07-22 16:20:05 +0200
commit6804b169a1b744a4bcb983b075ec4280a9b83af6 (patch)
tree97df2c257667e820b14e812ef077ae61657f5db8
parent097eb0d9988105523ec344e4cd64468f74a580ef (diff)
Allow layers to opt-out from legend by setting `legend: null`.
-rw-r--r--main.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/main.js b/main.js
index f4b7bbf..30a1d9c 100644
--- a/main.js
+++ b/main.js
@@ -3305,8 +3305,11 @@ const layerHierarchy = [
console.log(`Could not find symbol for layer ${layer}, skipping`);
return;
}
- const legend = LAYERS[layerGroup][layerName]?.legend ?? {};
- if (canvas == null || !legend.reuse_canvas) {
+ const legend = LAYERS[layerGroup][layerName]?.legend;
+ if (legend === null) {
+ return; /* layer has opted out from legend */
+ }
+ if (canvas == null || !legend?.reuse_canvas) {
canvas = document.createElement('canvas');
div.appendChild(canvas);
render = toContext(canvas.getContext('2d'),
@@ -3324,9 +3327,9 @@ const layerHierarchy = [
else if (mapLayers[layerGroup].getSource() instanceof VectorTile) {
/* vector source */
const style = Array.isArray(LAYERS[layerGroup][layerName].style) ?
- LAYERS[layerGroup][layerName].style[legend.zoomLevel ?? 5] :
+ LAYERS[layerGroup][layerName].style[legend?.zoomLevel ?? 5] :
LAYERS[layerGroup][layerName].style;
- const legend_type = legend.type ?? 'polygon';
+ const legend_type = legend?.type ?? 'polygon';
if (legend_type === 'point' && style.getImage(1) instanceof Icon && style.getImage(1).getSrc()) {
/* use a new <img> element since .setStyle() returns the same one and doesn't work in that case */
const div2 = document.createElement('div');