about summary refs log tree commit diff
path: root/map/controls.js
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-02-22 22:16:26 +0100
committerRobert Günzler <r@gnzler.io>2026-03-23 11:44:57 -0300
commit8bca0ebd8645bf2714035ed61ac140956a83fc21 (patch)
tree105f92dec40e7ac62f5cbe7d4c359a3343891070 /map/controls.js
parent975bc35109d4ee153da1936f8baaca03a9a1941e (diff)
downloadsite-8bca0ebd8645bf2714035ed61ac140956a83fc21.tar.gz
add map
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--map/controls.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/map/controls.js b/map/controls.js
new file mode 100644
index 0000000..e407a0c
--- /dev/null
+++ b/map/controls.js
@@ -0,0 +1,39 @@
+export class CustomControl {
+    _map = undefined;
+    _container = undefined;
+    _data = undefined;
+
+    constructor(data) {
+        if (Object.hasOwn(data, "label") &&
+            Object.hasOwn(data, "icon") &&
+            Object.hasOwn(data, "onclick")) {
+            this._data = data;
+        } else {
+            throw new Error("missing required property");
+        }
+    }
+
+    onAdd(map) {
+        this._map = map;
+        this._container = document.createElement('div');
+        this._container.className = 'maplibregl-ctrl maplibregl-ctrl-group';
+
+        const button = document.createElement('button');
+        button.type = 'button';
+        button.title = this._data.label;
+        button.textContent = this._data.icon;
+        button.onclick = () => {
+            this._data.onclick();
+        }
+
+        this._container.appendChild(button);
+        // this._map.on('mousedown', () => { });
+        return this._container;
+    }
+
+    onRemove() {
+        this._container.parentNode.removeChild(this._container);
+        // this._map.off('mousedown', () => { });
+        this._map = undefined;
+    }
+}