From 5b29895173760081e631f409c942706dbe11fe43 Mon Sep 17 00:00:00 2001 From: mahmoud adel <58145645+mahmoudadel54@users.noreply.github.com> Date: Mon, 11 May 2026 11:12:25 +0300 Subject: [PATCH] #12354: fix Issue with mouse coordinates for certain CRS not showing lat, lng for custom geographic CRSs (#12357) - fix the regression issue in editing 'getPosition' function in 'mouseposition/MousePosition.jsx' - add unit test for edits (cherry picked from commit 4602059a3e0869d44181616000c4f4b8257013c0) --- .../mouseposition/MousePosition.jsx | 4 +-- .../__tests__/MousePosition-test.js | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/web/client/components/mapcontrols/mouseposition/MousePosition.jsx b/web/client/components/mapcontrols/mouseposition/MousePosition.jsx index cb7cd6fd7c3..819294ee655 100644 --- a/web/client/components/mapcontrols/mouseposition/MousePosition.jsx +++ b/web/client/components/mapcontrols/mouseposition/MousePosition.jsx @@ -76,10 +76,10 @@ const MousePosition = (props) => { let {x, y, z} = mousePosition ? mousePosition : [null, null]; if (!x && !y && !z) { // if we repoject null coordinates we can end up with -0.00 instead of 0.00 - return {x: 0, y: 0, z}; + ({x, y} = {x: 0, y: 0, z}); } else if (proj4js.defs(mousePosition.crs) !== proj4js.defs(crs)) { const reprojected = reproject([x, y], mousePosition.crs, crs); - return {x: reprojected.x, y: reprojected.y, z}; + ({x, y} = {x: reprojected.x, y: reprojected.y, z}); } let units = getUnits(crs); if (units === "degrees") { diff --git a/web/client/components/mapcontrols/mouseposition/__tests__/MousePosition-test.js b/web/client/components/mapcontrols/mouseposition/__tests__/MousePosition-test.js index edab44829bd..2ecb63db7ce 100644 --- a/web/client/components/mapcontrols/mouseposition/__tests__/MousePosition-test.js +++ b/web/client/components/mapcontrols/mouseposition/__tests__/MousePosition-test.js @@ -11,6 +11,7 @@ import PropTypes from 'prop-types'; import React from 'react'; import ReactDOM from 'react-dom'; import MousePosition from '../MousePosition'; +import ConfigUtils from '../../../../utils/ConfigUtils'; describe('MousePosition', () => { beforeEach((done) => { @@ -46,7 +47,33 @@ describe('MousePosition', () => { const cmpDom = cmp.querySelector('#mouse-position'); expect(cmpDom).toNotExist(); }); + it('handles custom geographic CRS rather than 4326', () => { + // geographic CRS rather than 4326 + ConfigUtils.setConfigProp('projectionDefs', [ + { + code: "EPSG:4258", + def: "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs +type=crs +axis=neu", + extent: [-180, -90, 180, 90], + worldExtent: [-180, -90, 180, 90] + } + ]); + const customCrs = 'EPSG:4326'; + ReactDOM.render( + , + document.getElementById("container") + ); + + const cmpDom = document.getElementById("container"); + const text = cmpDom.textContent; + expect(text).toEqual('Lat: - 122° 25\' 9.839999999985594\'\'Lng: 37° 46\' 29.640000000008513\'\''); + ConfigUtils.removeConfigProp('projectionDefs'); + }); it('checks no position', () => { ReactDOM.render(, document.getElementById("container")); const cmp = document.getElementById("container");