mirror of
https://github.com/maputnik/editor.git
synced 2026-08-31 17:37:25 +00:00
Initial migration to typescript (#845)
This migrates some utilities classes from javascript to typescript. Nothing special about the migration, mainly added types and made sure the code adheres to the strict mode. I have picked some small files so git doesn't think they are the same since they are "very different". I hope that in later PRs, when migrating lager files this won't be an issues.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import {Map} from 'maplibre-gl';
|
||||
|
||||
export default class ZoomControl {
|
||||
_map: Map| undefined = undefined;
|
||||
_container: HTMLDivElement | undefined = undefined;
|
||||
_textEl: HTMLSpanElement | null = null;
|
||||
|
||||
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._container.innerHTML = `
|
||||
Zoom: <span></span>
|
||||
`;
|
||||
this._textEl = this._container.querySelector("span");
|
||||
|
||||
this.addEventListeners();
|
||||
|
||||
return this._container;
|
||||
}
|
||||
|
||||
updateZoomLevel() {
|
||||
this._textEl!.innerHTML = this._map!.getZoom().toFixed(2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user