mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-31 00:00:33 +01:00
commit
adc8ed26c1
3 changed files with 37 additions and 0 deletions
|
@ -8,6 +8,7 @@ import style from '../../libs/style.js'
|
||||||
import tokens from '../../config/tokens.json'
|
import tokens from '../../config/tokens.json'
|
||||||
import colors from 'mapbox-gl-inspect/lib/colors'
|
import colors from 'mapbox-gl-inspect/lib/colors'
|
||||||
import Color from 'color'
|
import Color from 'color'
|
||||||
|
import ZoomControl from '../../libs/zoomcontrol'
|
||||||
import { colorHighlightedLayer } from '../../libs/highlight'
|
import { colorHighlightedLayer } from '../../libs/highlight'
|
||||||
import 'mapbox-gl/dist/mapbox-gl.css'
|
import 'mapbox-gl/dist/mapbox-gl.css'
|
||||||
import '../../mapboxgl.css'
|
import '../../mapboxgl.css'
|
||||||
|
@ -109,6 +110,9 @@ export default class MapboxGlMap extends React.Component {
|
||||||
hash: true,
|
hash: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const zoom = new ZoomControl;
|
||||||
|
map.addControl(zoom, 'top-right');
|
||||||
|
|
||||||
const nav = new MapboxGl.NavigationControl();
|
const nav = new MapboxGl.NavigationControl();
|
||||||
map.addControl(nav, 'top-right');
|
map.addControl(nav, 'top-right');
|
||||||
|
|
||||||
|
|
26
src/libs/zoomcontrol.js
Normal file
26
src/libs/zoomcontrol.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,13 @@
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mapboxgl-ctrl-zoom {
|
||||||
|
color: rgb(138, 138, 138);
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 4px 8px;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
.mapboxgl-ctrl-group {
|
.mapboxgl-ctrl-group {
|
||||||
background: rgb(28, 31, 36);
|
background: rgb(28, 31, 36);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue