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,
|
view: view,
|
||||||
});
|
});
|
||||||
|
|
||||||
const zoomtoswitzerland = document.getElementById('zoomtoswitzerland');
|
vectorLayer.getSource().on('featuresloadend', function () {
|
||||||
zoomtoswitzerland.addEventListener(
|
const zoomtoswitzerland = document.getElementById('zoomtoswitzerland');
|
||||||
|
zoomtoswitzerland.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
function () {
|
function () {
|
||||||
const feature = source.getFeatures()[0];
|
const feature = source.getFeatures()[0];
|
||||||
@@ -59,10 +60,10 @@ zoomtoswitzerland.addEventListener(
|
|||||||
view.fit(polygon);
|
view.fit(polygon);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
const centerlausanne = document.getElementById('centerlausanne');
|
const centerlausanne = document.getElementById('centerlausanne');
|
||||||
centerlausanne.addEventListener(
|
centerlausanne.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
function () {
|
function () {
|
||||||
const feature = source.getFeatures()[1];
|
const feature = source.getFeatures()[1];
|
||||||
@@ -70,4 +71,5 @@ centerlausanne.addEventListener(
|
|||||||
view.setCenter(point.getCoordinates());
|
view.setCenter(point.getCoordinates());
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user