Fix error in view-padding example
An error occured when the buttons are clicked before the source is loaded.
This commit is contained in:
@@ -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
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user