mirror of
https://github.com/maputnik/editor.git
synced 2026-07-25 15:27:27 +00:00
@@ -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');
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user