diff --git a/packages/geo/src/lib/map/shared/map.utils.ts b/packages/geo/src/lib/map/shared/map.utils.ts index b69a5b1e31..3b568eacc3 100644 --- a/packages/geo/src/lib/map/shared/map.utils.ts +++ b/packages/geo/src/lib/map/shared/map.utils.ts @@ -54,8 +54,8 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu const dmsCoordPattern = `${dmsCoord}([N|S]),?\\s*${dmsCoord}([E|W])`; const dmsRegex = new RegExp(`^${dmsCoordPattern}`, 'gi'); - const patternUtmMtm = '(UTM|MTM)\-?(\\d{1,2})[\\s,.]*(\\d+[\\s.,]?\\d+)[\\s,.]+(\\d+[\\s.,]?\\d+)'; - const utmMtmRegex = new RegExp(`^${patternUtmMtm}`, 'gi'); + const patternUtm = '(UTM)\-?(\\d{1,2})[\\s,.]*(\\d+[\\s.,]?\\d+)[\\s,.]+(\\d+[\\s.,]?\\d+)'; + const utmRegex = new RegExp(`^${patternUtm}`, 'gi'); const ddCoord = '([-+])?(\\d{1,3})[,.](\\d+)'; const patternDd = `${ddCoord}[,.]?\\s*${ddCoord}`; @@ -73,8 +73,9 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu const mmPattern = `${mmCoord}[\\s,.]\\s*${mmCoord}`; const mmRegex = new RegExp(`^${mmPattern}$`, 'g'); - str = str.toLocaleUpperCase(); + let isXYCoords = false; + str = str.toLocaleUpperCase().trim(); // Extract projection if (projectionRegex.test(str)) { [coordStr, projectionStr] = str.split(';'); @@ -111,8 +112,9 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu lon = convertDMSToDD(parseFloat(degreesLon), parseFloat(minutesLon), parseFloat(secondsLon), directionLon); lat = convertDMSToDD(parseFloat(degreesLat), parseFloat(minutesLat), parseFloat(secondsLat), directionLat); - } else if (utmMtmRegex.test(coordStr)) { - [, pattern, timeZone, lon, lat] = coordStr.match(patternUtmMtm); + } else if (utmRegex.test(coordStr)) { + isXYCoords = true; + [, pattern, timeZone, lon, lat] = coordStr.match(patternUtm); const utm = '+proj=' + pattern + ' +zone=' + timeZone; const wgs84 = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'; [lon, lat] = proj4(utm.toLocaleLowerCase(), wgs84, [parseFloat(lon), parseFloat(lat)]); @@ -181,6 +183,7 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu } } else if (mmRegex.test(coordStr)) { + isXYCoords = true; [, lon, decimalLon, lat, decimalLat] = coordStr.match(mmPattern); if (decimalLon) { @@ -195,20 +198,24 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu return {lonLat: undefined, message: '', radius: undefined, conf: undefined}; } - // Set a negative coordinate for North America zone - if (lon > 0 && lat > 0) { - if (lon > lat) { - lon = -lon; - } else { - lat = -lat; + if (!isXYCoords) { + // Set a negative coordinate for North America zone + if (lon > 0 && lat > 0) { + if (lon > lat) { + lon = -lon; + } else { + lat = -lat; + } } - } - // Reverse coordinate to respect lonLat convention - if (lon < lat) { - lonLat = [lon, lat] as [number, number]; + // Reverse coordinate to respect lonLat convention + if (lon < lat) { + lonLat = [lon, lat] as [number, number]; + } else { + lonLat = [lat, lon] as [number, number]; + } } else { - lonLat = [lat, lon] as [number, number]; + lonLat = [lon, lat] as [number, number]; } // Reproject the coordinate if projection parameter have been set and coord is not 4326 diff --git a/packages/geo/src/lib/search/shared/sources/coordinates.ts b/packages/geo/src/lib/search/shared/sources/coordinates.ts index 8a0085b5e9..567291acc0 100644 --- a/packages/geo/src/lib/search/shared/sources/coordinates.ts +++ b/packages/geo/src/lib/search/shared/sources/coordinates.ts @@ -85,7 +85,7 @@ export class CoordinatesReverseSearchSource extends SearchSource extent: undefined, properties: { type: 'point', - coordonnees: String(data[0]) + ', ' + String(data[1]), + coordonnees: String(data[0].toFixed(5)) + ', ' + String(data[1].toFixed(5)), format: 'degrés decimaux', systemeCoordonnees: 'WGS84', GoogleMaps: GoogleLinks.getGoogleMapsLink(data[0], data[1]), @@ -96,13 +96,13 @@ export class CoordinatesReverseSearchSource extends SearchSource }, meta: { id: '1', - title: String(data[0]) + ', ' + String(data[1]) + title: String(data[0].toFixed(5)) + ', ' + String(data[1].toFixed(5)) } }, meta: { dataType: FEATURE, id: '1', - title: String(data[0]) + ', ' + String(data[1]), + title: String(data[0].toFixed(5)) + ', ' + String(data[1].toFixed(5)), icon: 'map-marker' } };