mirror of
https://github.com/maputnik/editor.git
synced 2026-09-11 23:07:41 +00:00
9c1499b805
## 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>
44 lines
1.1 KiB
TypeScript
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;
|
|
}
|
|
}
|