Files
editor/src/libs/zoomcontrol.ts
T
Harel M 9c1499b805 Replace default export with named exports (#1998)
## Launch Checklist

See title,
Also removed some "_" from some file names.
This is a pure refactoring, no logic changes.


 - [x] Briefly describe the changes in this PR.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-12 14:07:28 +03:00

44 lines
1.1 KiB
TypeScript

import {type Map} from "maplibre-gl";
export class ZoomControl {
_map: Map| undefined = undefined;
_container: HTMLDivElement | undefined = undefined;
_textEl: HTMLSpanElement | null = null;
constructor() {}
onAdd(map: Map) {
this._map = map;
this._container = document.createElement("div");
this._container.className = "maplibregl-ctrl maplibregl-ctrl-group maplibregl-ctrl-zoom";
this._container.setAttribute("data-wd-key", "maplibre:ctrl-zoom");
this.setLabel("Zoom:");
this.addEventListeners();
return this._container;
}
updateZoomLevel() {
this._textEl!.innerHTML = this._map!.getZoom().toFixed(2);
}
setLabel(label: string) {
this._container!.innerHTML = `
${label} <span></span>
`;
this._textEl = this._container!.querySelector("span");
this.updateZoomLevel();
}
addEventListeners (){
this._map!.on("render", () => this.updateZoomLevel());
this._map!.on("zoomIn", () => this.updateZoomLevel());
this._map!.on("zoomOut", () => this.updateZoomLevel());
}
onRemove() {
this._container!.parentNode!.removeChild(this._container!);
this._map = undefined;
}
}