Skip to content

Commit ac5259d

Browse files
committed
fix: handle Popup can take extent and getCenter from it
1 parent 5f62c5c commit ac5259d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/vendors/helpers/Popup.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Overlay from 'ol/Overlay';
99
export function showPopup(map, coordinates, message) {
1010
let popup = map.getOverlayById('infoPopup');
1111
if (!popup) {
12-
// Create popup overlay logic remains the same
12+
// Create popup overlay logic
1313
let popupElement = document.createElement('div');
1414
popupElement.className = 'ol-popup';
1515

@@ -37,8 +37,13 @@ export function showPopup(map, coordinates, message) {
3737

3838
map.addOverlay(popup);
3939
}
40-
//Show popup on the first coordinates as work arround
41-
if (Array.isArray(coordinates) && coordinates.length >= 2) {
40+
41+
if (Array.isArray(coordinates)) {
42+
// If coordinates have more than two values, assume it's an extent and calculate its center.
43+
if (coordinates.length > 2) {
44+
coordinates = getCenter(coordinates);
45+
}
46+
// Now coordinates will always be a pair here, suitable for setPosition.
4247
let content = popup.getElement().querySelector('.ol-popup-content');
4348
content.innerHTML = message;
4449
popup.setPosition([coordinates[0], coordinates[1]]);

0 commit comments

Comments
 (0)