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:
Harel M
2023-12-20 22:56:33 +02:00
committed by GitHub
parent 4d1e2e6893
commit e8d07fa694
17 changed files with 76 additions and 68 deletions
+37
View File
@@ -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;
}
}