Skip to content

Commit 4607bb3

Browse files
committed
fix: popup projection and getProjection from map view instead of static "EPSG:3857"
1 parent 2e910b0 commit 4607bb3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/vendors/Geo.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ function Geo(props) {
530530
pedit.getActive() || ledit.getActive() || fedit.getActive()))
531531
&& layer && layer.get("selectable") !== false && feature) { //only fire event if we are not drawing
532532
fireEvent('click:feature', {
533-
extent: transformExtent(feature.getGeometry()?.extent_, 'EPSG:3857', 'EPSG:4326') || [],
533+
extent: transformExtent(feature.getGeometry()?.extent_, olMap.getView().getProjection(), 'EPSG:4326') || [],
534534
properties: feature.getProperties() || {},
535535
layer: layer.get("name")
536536
})
@@ -582,7 +582,7 @@ function Geo(props) {
582582
//On move
583583
olMap.on('moveend', () => {
584584
const extent = olMap.getView().calculateExtent(olMap.getSize()); // Get the current extent
585-
const transformedExtent = transformExtent(extent, 'EPSG:3857', 'EPSG:4326'); // Transform the extent to WGS 84
585+
const transformedExtent = transformExtent(extent, olMap.getView().getProjection(), 'EPSG:4326'); // Transform the extent to WGS 84
586586
fireEvent('bbox:change', transformedExtent); // Call the callback with the updated bbox
587587
}
588588
);

src/vendors/helpers/Popup.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import Overlay from 'ol/Overlay';
77
import { getCenter } from 'ol/extent';
8+
import { fromLonLat, transformExtent } from 'ol/proj';
89

910
// Adjusted to accept a map instance directly
1011
export function showPopup(map, coordinates, message) {
@@ -42,11 +43,14 @@ export function showPopup(map, coordinates, message) {
4243
if (Array.isArray(coordinates)) {
4344
// If coordinates have more than two values, assume it's an extent and calculate its center.
4445
if (coordinates.length > 2) {
45-
coordinates = getCenter(coordinates);
46+
coordinates = getCenter(transformExtent(coordinates, 'EPSG:4326', map.getView().getProjection()));
47+
}
48+
else if (coordinates.length < 3) {
49+
coordinates = fromLonLat(coordinates);
4650
}
4751
// Now coordinates will always be a pair here, suitable for setPosition.
4852
let content = popup.getElement().querySelector('.ol-popup-content');
4953
content.innerHTML = message;
50-
popup.setPosition([coordinates[0], coordinates[1]]);
54+
popup.setPosition(coordinates);
5155
}
5256
}

0 commit comments

Comments
 (0)