diff options
| author | Robert Günzler <r@gnzler.io> | 2026-02-22 22:16:26 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-03-23 11:44:57 -0300 |
| commit | 8bca0ebd8645bf2714035ed61ac140956a83fc21 (patch) | |
| tree | 105f92dec40e7ac62f5cbe7d4c359a3343891070 /map/controls.js | |
| parent | 975bc35109d4ee153da1936f8baaca03a9a1941e (diff) | |
| download | site-8bca0ebd8645bf2714035ed61ac140956a83fc21.tar.gz | |
add map
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
| -rw-r--r-- | map/controls.js | 39 |
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; + } +} |