Files
openlayers/examples/min-zoom.js
Frederic Junod 79c8afdba8 Simplify import path in examples
To have the same path (starting with `ol/`, without `.js`) as in the documentation.
The support was added in the webpack config in #8928
2018-11-26 17:18:52 +01:00

37 lines
705 B
JavaScript

import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const viewport = document.getElementById('map');
function getMinZoom() {
const width = viewport.clientWidth;
return Math.ceil(Math.LOG2E * Math.log(width / 256));
}
const initialZoom = getMinZoom();
const view = new View({
center: [0, 0],
minZoom: initialZoom,
zoom: initialZoom
});
const map = new Map({
layers: [
new TileLayer({
source: new OSM()
})
],
target: 'map',
view: view
});
window.addEventListener('resize', function() {
const minZoom = getMinZoom();
if (minZoom !== view.getMinZoom()) {
view.setMinZoom(minZoom);
}
});