Fix error in view-padding example

An error occured when the buttons are clicked before the source is loaded.
This commit is contained in:
Maximilian Krög
2021-05-08 02:15:43 +02:00
parent c19ebc72cb
commit dabfe40700

View File

@@ -50,8 +50,9 @@ const map = new Map({
view: view,
});
const zoomtoswitzerland = document.getElementById('zoomtoswitzerland');
zoomtoswitzerland.addEventListener(
vectorLayer.getSource().on('featuresloadend', function () {
const zoomtoswitzerland = document.getElementById('zoomtoswitzerland');
zoomtoswitzerland.addEventListener(
'click',
function () {
const feature = source.getFeatures()[0];
@@ -59,10 +60,10 @@ zoomtoswitzerland.addEventListener(
view.fit(polygon);
},
false
);
);
const centerlausanne = document.getElementById('centerlausanne');
centerlausanne.addEventListener(
const centerlausanne = document.getElementById('centerlausanne');
centerlausanne.addEventListener(
'click',
function () {
const feature = source.getFeatures()[1];
@@ -70,4 +71,5 @@ centerlausanne.addEventListener(
view.setCenter(point.getCoordinates());
},
false
);
);
});