mirror of
https://github.com/maputnik/editor.git
synced 2026-01-06 21:40:01 +00:00
27 lines
722 B
JavaScript
27 lines
722 B
JavaScript
export default class ZoomControl {
|
|
onAdd(map) {
|
|
this._map = map;
|
|
this._container = document.createElement('div');
|
|
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group mapboxgl-ctrl-zoom';
|
|
|
|
this.addEventListeners();
|
|
|
|
return this._container;
|
|
}
|
|
|
|
updateZoomLevel() {
|
|
this._container.innerHTML = `Zoom level: ${this._map.getZoom().toFixed(2)}`;
|
|
}
|
|
|
|
addEventListeners (){
|
|
this._map.on('render', this.updateZoomLevel.bind(this) );
|
|
this._map.on('zoomIn', this.updateZoomLevel.bind(this) );
|
|
this._map.on('zoomOut', this.updateZoomLevel.bind(this) );
|
|
}
|
|
|
|
onRemove() {
|
|
this._container.parentNode.removeChild(this._container);
|
|
this._map = undefined;
|
|
}
|
|
}
|