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,24 +50,26 @@ 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');
|
||||||
'click',
|
zoomtoswitzerland.addEventListener(
|
||||||
function () {
|
'click',
|
||||||
const feature = source.getFeatures()[0];
|
function () {
|
||||||
const polygon = feature.getGeometry();
|
const feature = source.getFeatures()[0];
|
||||||
view.fit(polygon);
|
const polygon = feature.getGeometry();
|
||||||
},
|
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];
|
||||||
const point = feature.getGeometry();
|
const point = feature.getGeometry();
|
||||||
view.setCenter(point.getCoordinates());
|
view.setCenter(point.getCoordinates());
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user