To have the same path (starting with `ol/`, without `.js`) as in the documentation. The support was added in the webpack config in #8928
26 lines
488 B
JavaScript
26 lines
488 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 source = new OSM();
|
|
|
|
const layer = new TileLayer();
|
|
|
|
const map = new Map({
|
|
layers: [layer],
|
|
target: 'map',
|
|
view: new View({
|
|
center: [0, 0],
|
|
zoom: 2
|
|
})
|
|
});
|
|
|
|
document.getElementById('set-source').onclick = function() {
|
|
layer.setSource(source);
|
|
};
|
|
|
|
document.getElementById('unset-source').onclick = function() {
|
|
layer.setSource(null);
|
|
};
|