diff --git a/packages/geo/src/lib/map/shared/controllers/view.ts b/packages/geo/src/lib/map/shared/controllers/view.ts index f307763198..d4395bcaef 100644 --- a/packages/geo/src/lib/map/shared/controllers/view.ts +++ b/packages/geo/src/lib/map/shared/controllers/view.ts @@ -32,6 +32,16 @@ export class MapViewController extends MapController { */ state$ = new BehaviorSubject(undefined); + /** + * View Padding + */ + padding = [0, 0, 0, 0]; + + /** + * Max zoom after set extent + */ + maxZoomOnExtent = 19; + /** * Extent stream */ @@ -52,11 +62,6 @@ export class MapViewController extends MapController { */ private stateIndex: number = 0; - /** - * View Padding - */ - padding = [0, 0, 0, 0]; - /** * Whether the view controller should keep the view's state history */ @@ -326,7 +331,10 @@ export class MapViewController extends MapController { const moySize = (toSize + fromSize) / 2; const xSize = distCenter / moySize; - const maxZoom = action === MapViewAction.Move ? zoom : zoom > 19 ? zoom : 19; + const maxZoom = + action === MapViewAction.Move || zoom > this.maxZoomOnExtent + ? zoom + : this.maxZoomOnExtent; olView.fit(extent, { maxZoom, diff --git a/packages/geo/src/lib/map/shared/map.interface.ts b/packages/geo/src/lib/map/shared/map.interface.ts index 18a32770f4..07ae5353d6 100644 --- a/packages/geo/src/lib/map/shared/map.interface.ts +++ b/packages/geo/src/lib/map/shared/map.interface.ts @@ -3,6 +3,7 @@ export type MapExtent = [number, number, number, number]; export interface MapViewOptions { projection?: string; center?: [number, number]; + maxZoomOnExtent?: number; geolocate?: boolean; buffer?: Buffer; diff --git a/packages/geo/src/lib/map/shared/map.ts b/packages/geo/src/lib/map/shared/map.ts index 7cf9500d7c..7c77c758d8 100644 --- a/packages/geo/src/lib/map/shared/map.ts +++ b/packages/geo/src/lib/map/shared/map.ts @@ -134,6 +134,9 @@ export class IgoMap { ); this.setView(Object.assign(viewOptions, options)); + if (options.maxZoomOnExtent) { + this.viewController.maxZoomOnExtent = options.maxZoomOnExtent; + } } /** @@ -188,8 +191,12 @@ export class IgoMap { baseLayer.visible = true; - this.viewController.olView.setMinZoom(baseLayer.dataSource.options.minZoom || (this.options.view || {}).minZoom); - this.viewController.olView.setMaxZoom(baseLayer.dataSource.options.maxZoom || (this.options.view || {}).maxZoom); + this.viewController.olView.setMinZoom( + baseLayer.dataSource.options.minZoom || (this.options.view || {}).minZoom + ); + this.viewController.olView.setMaxZoom( + baseLayer.dataSource.options.maxZoom || (this.options.view || {}).maxZoom + ); } getBaseLayers(): Layer[] { diff --git a/packages/geo/src/lib/map/shared/map.utils.ts b/packages/geo/src/lib/map/shared/map.utils.ts index 7a6b35453b..cfa19a2b25 100644 --- a/packages/geo/src/lib/map/shared/map.utils.ts +++ b/packages/geo/src/lib/map/shared/map.utils.ts @@ -10,17 +10,23 @@ import { Projection } from './projection.interfaces'; * This method extracts a coordinate tuple from a string. * @param str Any string * @param mapProjection string Map Projection + * @param opts.forceNA boolean Force North America Zone * @returns object: * lonLat: Coordinate, * message: Message of error, * radius: radius of the confience of coordinate, * conf: confidence of the coordinate} */ -export function stringToLonLat(str: string, mapProjection: string): {lonLat: [number, number] | undefined, - message: string, - radius: number | undefined, - conf: number | undefined} { - +export function stringToLonLat( + str: string, + mapProjection: string, + opts: { forceNA?: boolean } = {} +): { + lonLat: [number, number] | undefined; + message: string; + radius: number | undefined; + conf: number | undefined; +} { let lonLat: [number, number]; let coordStr: string; let negativeLon: string; @@ -35,7 +41,6 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu let secondsLat: string; let directionLat: string; let decimalLat: string; - let pattern: string; let zone: string; let radius: string; let conf: string; @@ -47,40 +52,45 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu let projectionStr: string; const projectionRegex = new RegExp(projectionPattern, 'g'); - const lonlatCoord = '([-+])?([\\d]{1,3})([,.](\\d+))?'; - const lonLatPattern = `${lonlatCoord}[\\s,.]+${lonlatCoord}`; + const lonlatCoord = '([-+])?([\\d]{1,3})([,.](\\d+))?'; + const lonLatPattern = `${lonlatCoord}[\\s,]+${lonlatCoord}`; const lonLatRegex = new RegExp(`^${lonLatPattern}$`, 'g'); - const dmsCoord = '([0-9]{1,2})[:|°]?\\s*([0-9]{1,2})?[:|\'|′|’]?\\s*([0-9]{1,2}(?:\.[0-9]+){0,1})?\\s*["|″|”]?\\s*'; - const dmsCoordPattern = `${dmsCoord}([N|S]),?\\s*${dmsCoord}([E|W])`; + const dmsCoord = + '([0-9]{1,2})[:|°]?\\s*([0-9]{1,2})?[:|\'|′|’]?\\s*([0-9]{1,2}(?:.[0-9]+){0,1})?\\s*["|″|”]?\\s*'; + const dmsCoordPattern = `${dmsCoord}([N|S|E|W|O]),?\\s*${dmsCoord}([N|S|E|W|O])`; const dmsRegex = new RegExp(`^${dmsCoordPattern}`, 'gi'); - const patternUtm = '(UTM)\-?(\\d{1,2})[\\s,.]*(\\d+[\\s.,]?\\d+)[\\s,.]+(\\d+[\\s.,]?\\d+)'; - const utmRegex = new RegExp(`^${patternUtm}`, 'gi'); + const patternUtm = + '(UTM)-?(\\d{1,2})[\\s,]*(\\d+[.,]?\\d+)[\\s,]+(\\d+[.,]?\\d+)'; + const utmRegex = new RegExp(`^${patternUtm}`, 'gi'); - const patternMtm = '(MTM)\-?(\\d{1,2})[\\s,.]*(\\d+[\\s.,]?\\d+)[\\s,.]+(\\d+[\\s.,]?\\d+)'; - const mtmRegex = new RegExp(`^${patternMtm}`, 'gi'); + const patternMtm = + '(MTM)-?(\\d{1,2})[\\s,]*(\\d+[.,]?\\d+)[\\s,]+(\\d+[.,]?\\d+)'; + const mtmRegex = new RegExp(`^${patternMtm}`, 'gi'); const ddCoord = '([-+])?(\\d{1,3})[,.](\\d+)'; - const patternDd = `${ddCoord}\\s*[,.]?\\s*${ddCoord}`; - const ddRegex = new RegExp(`^${patternDd}`, 'g'); + const patternDd = `${ddCoord}\\s*[,]?\\s*${ddCoord}`; + const ddRegex = new RegExp(`^${patternDd}`, 'g'); - const dmdCoord = '([-+])?(\\d{1,3})[\\s,.]{1}(\\d{1,2})[\\s,.]{1}(\\d{1,2})[.,]?(\\d{1,5})?'; + const dmdCoord = + '([-+])?(\\d{1,3})[\\s,.]{1}(\\d{1,2})[\\s,.]{1}(\\d{1,2})[.,]?(\\d{1,5})?'; const patternDmd = `${dmdCoord}\\s*[,.]?\\s*${dmdCoord}`; - const dmdRegex = new RegExp(`^${patternDmd}`, 'g'); + const dmdRegex = new RegExp(`^${patternDmd}`, 'g'); // tslint:disable:max-line-length - const patternBELL = 'LAT\\s*[\\s:]*\\s*([-+])?(\\d{1,2})[\\s.,]?(\\d+)?[\\s.,]?\\s*(\\d{1,2}([.,]\\d+)?)?\\s*(N|S|E|W)?\\s*LONG\\s*[\\s:]*\\s*([-+])?(\\d{1,3})[\\s.,]?(\\d+)?[\\s.,]?\\s*(\\d{1,2}([.,]\\d+)?)?\\s*(N|S|E|W)?\\s*UNC\\s*[\\s:]?\\s*(\\d+)\\s*CONF\\s*[\\s:]?\\s*(\\d{1,3})'; - const bellRegex = new RegExp(`^${patternBELL}?`, 'gi'); + const patternBELL = + 'LAT\\s*[\\s:]*\\s*([-+])?(\\d{1,2})[\\s.,]?(\\d+)?[\\s.,]?\\s*(\\d{1,2}([.,]\\d+)?)?\\s*(N|S|E|W)?\\s*LONG\\s*[\\s:]*\\s*([-+])?(\\d{1,3})[\\s.,]?(\\d+)?[\\s.,]?\\s*(\\d{1,2}([.,]\\d+)?)?\\s*(N|S|E|W)?\\s*UNC\\s*[\\s:]?\\s*(\\d+)\\s*CONF\\s*[\\s:]?\\s*(\\d{1,3})'; + const bellRegex = new RegExp(`^${patternBELL}?`, 'gi'); const mmCoord = '([-+]?\\d+)[,.]?(\\d+)?'; - const mmPattern = `${mmCoord}[\\s,.]+${mmCoord}`; - const mmRegex = new RegExp(`^${mmPattern}$`, 'g'); + const mmPattern = `${mmCoord}[\\s,]+${mmCoord}`; + const mmRegex = new RegExp(`^${mmPattern}$`, 'g'); let isXYCoords = false; str = str.toLocaleUpperCase().trim(); - str = str.replace(' ', ''); + // Extract projection if (projectionRegex.test(str)) { [coordStr, projectionStr] = str.split(';').map(s => s.trim()); @@ -88,48 +98,74 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu coordStr = str; } if (lonLatRegex.test(coordStr)) { - - [, - negativeLon, - lon, - , - decimalLon, - negativeLat, - lat, - , - decimalLat] = coordStr.match(lonLatPattern); + [ + , + negativeLon, + lon, + , + decimalLon, + negativeLat, + lat, + , + decimalLat + ] = coordStr.match(lonLatPattern); lon = parseFloat((negativeLon ? negativeLon : '') + lon + '.' + decimalLon); lat = parseFloat((negativeLat ? negativeLat : '') + lat + '.' + decimalLat); - } else if (dmsRegex.test(coordStr)) { - [, - degreesLon, - minutesLon, - secondsLon, - directionLon, - degreesLat, - minutesLat, - secondsLat, - directionLat] = coordStr.match(dmsCoordPattern); - - lon = convertDMSToDD(parseFloat(degreesLon), parseFloat(minutesLon), parseFloat(secondsLon), directionLon); - lat = convertDMSToDD(parseFloat(degreesLat), parseFloat(minutesLat), parseFloat(secondsLat), directionLat); + [ + , + degreesLon, + minutesLon, + secondsLon, + directionLon, + degreesLat, + minutesLat, + secondsLat, + directionLat + ] = coordStr.match(dmsCoordPattern); + + if (directionLon === 'S' || directionLon === 'N') { + degreesLon = [degreesLat, (degreesLat = degreesLon)][0]; + minutesLon = [minutesLat, (minutesLat = minutesLon)][0]; + secondsLon = [secondsLat, (secondsLat = secondsLon)][0]; + directionLon = [directionLat, (directionLat = directionLon)][0]; + } + lon = convertDMSToDD( + parseFloat(degreesLon), + parseFloat(minutesLon), + parseFloat(secondsLon), + directionLon + ); + lat = convertDMSToDD( + parseFloat(degreesLat), + parseFloat(minutesLat), + parseFloat(secondsLat), + directionLat + ); } else if (utmRegex.test(coordStr)) { isXYCoords = true; - [, pattern, zone, lon, lat] = coordStr.match(patternUtm); + [, , zone, lon, lat] = coordStr.match(patternUtm); const epsgUtm = Number(zone) < 10 ? `EPSG:3260${zone}` : `EPSG:326${zone}`; - [lon, lat] = olproj.transform([parseFloat(lon), parseFloat(lat)], epsgUtm, 'EPSG:4326'); - + [lon, lat] = olproj.transform( + [parseFloat(lon), parseFloat(lat)], + epsgUtm, + 'EPSG:4326' + ); } else if (mtmRegex.test(coordStr)) { isXYCoords = true; - [, pattern, zone, lon, lat] = coordStr.match(patternMtm); - const epsgMtm = Number(zone) < 10 ? `EPSG:3218${zone}` : `EPSG:321${80 + Number(zone)}`; - [lon, lat] = olproj.transform([parseFloat(lon), parseFloat(lat)], epsgMtm, 'EPSG:4326'); - + [, , zone, lon, lat] = coordStr.match(patternMtm); + const epsgMtm = + Number(zone) < 10 ? `EPSG:3218${zone}` : `EPSG:321${80 + Number(zone)}`; + [lon, lat] = olproj.transform( + [parseFloat(lon), parseFloat(lat)], + epsgMtm, + 'EPSG:4326' + ); } else if (dmdRegex.test(coordStr)) { - [, + [ + , negativeLon, degreesLon, minutesLon, @@ -139,25 +175,47 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu degreesLat, minutesLat, secondsLat, - decimalLat] = coordStr.match(patternDmd); - - lon = convertDMSToDD(parseFloat((negativeLon ? negativeLon : '') + degreesLon), parseFloat(minutesLon), parseFloat(secondsLon), directionLon); - lat = convertDMSToDD(parseFloat((negativeLat ? negativeLat : '') + degreesLat), parseFloat(minutesLat), parseFloat(secondsLat), directionLat); - + decimalLat + ] = coordStr.match(patternDmd); + + lon = convertDMSToDD( + parseFloat((negativeLon ? negativeLon : '') + degreesLon), + parseFloat(minutesLon), + parseFloat(secondsLon), + directionLon + ); + lat = convertDMSToDD( + parseFloat((negativeLat ? negativeLat : '') + degreesLat), + parseFloat(minutesLat), + parseFloat(secondsLat), + directionLat + ); } else if (ddRegex.test(coordStr)) { - [, - negativeLon, - degreesLon, - decimalLon, - negativeLat, - degreesLat, - decimalLat] = coordStr.match(patternDd); - - lon = convertDMSToDD(parseFloat((negativeLon ? negativeLon : '') + degreesLon), parseFloat(minutesLon), parseFloat(secondsLon), directionLon); - lat = convertDMSToDD(parseFloat((negativeLat ? negativeLat : '') + degreesLat), parseFloat(minutesLat), parseFloat(secondsLat), directionLat); - + [ + , + negativeLon, + degreesLon, + decimalLon, + negativeLat, + degreesLat, + decimalLat + ] = coordStr.match(patternDd); + + lon = convertDMSToDD( + parseFloat((negativeLon ? negativeLon : '') + degreesLon), + parseFloat(minutesLon), + parseFloat(secondsLon), + directionLon + ); + lat = convertDMSToDD( + parseFloat((negativeLat ? negativeLat : '') + degreesLat), + parseFloat(minutesLat), + parseFloat(secondsLat), + directionLat + ); } else if (bellRegex.test(coordStr)) { - [, + [ + , negativeLat, degreesLat, minutesLat, @@ -171,7 +229,8 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu , directionLon, radius, - conf] = coordStr.match(patternBELL); + conf + ] = coordStr.match(patternBELL); // Set default value for North America if (!directionLon) { @@ -180,34 +239,51 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu // Check if real minutes or decimals if (minutesLon && minutesLon.length > 2) { - lon = parseFloat((negativeLon ? negativeLon : '') + degreesLon + '.' + minutesLon); + lon = parseFloat( + (negativeLon ? negativeLon : '') + degreesLon + '.' + minutesLon + ); } else { - lon = convertDMSToDD(parseFloat(degreesLon), parseFloat(minutesLon), parseFloat(secondsLon), directionLon); + lon = convertDMSToDD( + parseFloat(degreesLon), + parseFloat(minutesLon), + parseFloat(secondsLon), + directionLon + ); } if (minutesLat && minutesLat.length > 2) { - lat = parseFloat((negativeLat ? negativeLat : '') + degreesLat + '.' + minutesLat); + lat = parseFloat( + (negativeLat ? negativeLat : '') + degreesLat + '.' + minutesLat + ); } else { - lat = convertDMSToDD(parseFloat(degreesLat), parseFloat(minutesLat), parseFloat(secondsLat), directionLat); + lat = convertDMSToDD( + parseFloat(degreesLat), + parseFloat(minutesLat), + parseFloat(secondsLat), + directionLat + ); } - } else if (mmRegex.test(coordStr)) { - isXYCoords = true; - [, lon, decimalLon, lat, decimalLat] = coordStr.match(mmPattern); - - if (decimalLon) { - lon = parseFloat(lon + '.' + decimalLon); - } + isXYCoords = true; + [, lon, decimalLon, lat, decimalLat] = coordStr.match(mmPattern); - if (decimalLat) { - lat = parseFloat(lat + '.' + decimalLat); - } + if (decimalLon) { + lon = parseFloat(lon + '.' + decimalLon); + } + if (decimalLat) { + lat = parseFloat(lat + '.' + decimalLat); + } } else { - return {lonLat: undefined, message: '', radius: undefined, conf: undefined}; + return { + lonLat: undefined, + message: '', + radius: undefined, + conf: undefined + }; } - if (!isXYCoords) { + if (opts.forceNA && !isXYCoords) { // Set a negative coordinate for North America zone if (lon > 0 && lat > 0) { if (lon > lat) { @@ -218,27 +294,40 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu } // Reverse coordinate to respect lonLat convention - if (lon < lat) { - lonLat = [lon, lat] as [number, number]; - } else { - lonLat = [lat, lon] as [number, number]; + if (lon > lat) { + lon = [lat, (lat = lon)][0]; } - } else { - lonLat = [lon, lat] as [number, number]; } + lonLat = [Number(lon), Number(lat)] as [number, number]; + // Reproject the coordinate if projection parameter have been set and coord is not 4326 - if ((projectionStr !== undefined && projectionStr !== toProjection) || (lonLat[0] > 180 || lonLat[0] < -180) || (lonLat[1] > 90 || lonLat[1] < -90)) { + if ( + (projectionStr !== undefined && projectionStr !== toProjection) || + (lonLat[0] > 180 || lonLat[0] < -180) || + (lonLat[1] > 90 || lonLat[1] < -90) + ) { const source = projectionStr ? 'EPSG:' + projectionStr : mapProjection; const dest = 'EPSG:' + toProjection; try { lonLat = olproj.transform(lonLat, source, dest); } catch (e) { - return {lonLat: undefined, message: 'Projection ' + source + ' not supported', radius: undefined, conf: undefined}; + return { + lonLat: undefined, + message: 'Projection ' + source + ' not supported', + radius: undefined, + conf: undefined + }; } } - return {lonLat, message: '', radius: radius ? parseInt(radius, 10) : undefined, conf: conf ? parseInt(conf, 10) : undefined}; + + return { + lonLat, + message: '', + radius: radius ? parseInt(radius, 10) : undefined, + conf: conf ? parseInt(conf, 10) : undefined + }; } /** @@ -248,13 +337,18 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu * @param seconds Seconds * @param direction Direction */ -function convertDMSToDD(degrees: number, minutes: number, seconds: number, direction: string) { +function convertDMSToDD( + degrees: number, + minutes: number, + seconds: number, + direction: string +) { minutes = minutes || 0; seconds = seconds || 0; - let dd = degrees + (minutes / 60) + (seconds / 3600); + let dd = degrees + minutes / 60 + seconds / 3600; if (direction === 'S' || direction === 'W') { - dd = -dd; + dd = -dd; } // Don't do anything for N or E return dd; } @@ -265,15 +359,22 @@ function convertDMSToDD(degrees: number, minutes: number, seconds: number, direc * @param state2 View state * @returns True if the view states are equal */ -export function viewStatesAreEqual(state1: MapViewState, state2: MapViewState): boolean { +export function viewStatesAreEqual( + state1: MapViewState, + state2: MapViewState +): boolean { if (state1 === undefined || state2 === undefined) { return false; } const tolerance = 1 / 10000; - return state1.zoom === state2.zoom && - Math.trunc(state1.center[0] / tolerance) === Math.trunc(state2.center[0] / tolerance) && - Math.trunc(state1.center[1] / tolerance) === Math.trunc(state2.center[1] / tolerance); + return ( + state1.zoom === state2.zoom && + Math.trunc(state1.center[0] / tolerance) === + Math.trunc(state2.center[0] / tolerance) && + Math.trunc(state1.center[1] / tolerance) === + Math.trunc(state2.center[1] / tolerance) + ); } /** @@ -283,10 +384,14 @@ export function viewStatesAreEqual(state1: MapViewState, state2: MapViewState): */ export function formatScale(scale) { scale = Math.round(scale); - if (scale < 10000) { return scale + ''; } + if (scale < 10000) { + return scale + ''; + } scale = Math.round(scale / 1000); - if (scale < 1000) { return scale + 'K'; } + if (scale < 1000) { + return scale + 'K'; + } scale = Math.round(scale / 1000); return scale + 'M'; @@ -298,7 +403,10 @@ export function formatScale(scale) { * @param dpi DPI * @returns Resolution */ -export function getResolutionFromScale(scale: number, dpi: number = 96): number { +export function getResolutionFromScale( + scale: number, + dpi: number = 96 +): number { const inchesPerMeter = 39.3701; return scale / (inchesPerMeter * dpi); } @@ -308,7 +416,11 @@ export function getResolutionFromScale(scale: number, dpi: number = 96): number * @param Scale denom * @returns Resolution */ -export function getScaleFromResolution(resolution: number, unit: string = 'm', dpi: number = 96): number { +export function getScaleFromResolution( + resolution: number, + unit: string = 'm', + dpi: number = 96 +): number { const inchesPerMeter = 39.3701; return resolution * olproj.METERS_PER_UNIT[unit] * inchesPerMeter * dpi; } @@ -328,10 +440,7 @@ export function ctrlKeyDown(event: OlMapBrowserPointerEvent): boolean { } export function roundCoordTo(coord: [number, number], decimal: number = 3) { - return [ - coord[0].toFixed(decimal), - coord[1].toFixed(decimal) - ]; + return [coord[0].toFixed(decimal), coord[1].toFixed(decimal)]; } /** @@ -342,9 +451,15 @@ export function roundCoordTo(coord: [number, number], decimal: number = 3) { * @param projections Projection[] Array of destination projection. * @returns Returns an array of converted coordinates. */ -export function lonLatConversion(lonLat: [number, number], projections: Projection[]): -{ code: string; alias: string, coord: [number, number], igo2CoordFormat: string }[] { - +export function lonLatConversion( + lonLat: [number, number], + projections: Projection[] +): { + code: string; + alias: string; + coord: [number, number]; + igo2CoordFormat: string; +}[] { const rawCoord3857 = olproj.transform(lonLat, 'EPSG:4326', 'EPSG:3857'); const convertedLonLat = [ { @@ -360,43 +475,42 @@ export function lonLatConversion(lonLat: [number, number], projections: Projecti const epsgUtm = utmZone < 10 ? `EPSG:3260${utmZone}` : `EPSG:326${utmZone}`; const utmName = `UTM-${utmZone}`; const rawCoordUtm = olproj.transform(lonLat, 'EPSG:4326', epsgUtm); - convertedLonLat.push( - { - code: epsgUtm, - alias: 'UTM', - coord: rawCoordUtm, - igo2CoordFormat: `${utmName} ${roundCoordTo(rawCoordUtm).join(', ')}` - }); + convertedLonLat.push({ + code: epsgUtm, + alias: 'UTM', + coord: rawCoordUtm, + igo2CoordFormat: `${utmName} ${roundCoordTo(rawCoordUtm).join(', ')}` + }); // detect the current mtm zone. const mtmZone = mtmZoneFromLonLat(lonLat); if (mtmZone) { - const epsgMtm = mtmZone < 10 ? `EPSG:3218${mtmZone}` : `EPSG:321${80 + mtmZone}`; + const epsgMtm = + mtmZone < 10 ? `EPSG:3218${mtmZone}` : `EPSG:321${80 + mtmZone}`; const mtmName = `MTM-${mtmZone}`; const rawCoordMtm = olproj.transform(lonLat, 'EPSG:4326', epsgMtm); - convertedLonLat.push( - { - code: epsgMtm, - alias: 'MTM', - coord: rawCoordMtm, - igo2CoordFormat: `${mtmName} ${roundCoordTo(rawCoordMtm).join(', ')}` - }); + convertedLonLat.push({ + code: epsgMtm, + alias: 'MTM', + coord: rawCoordMtm, + igo2CoordFormat: `${mtmName} ${roundCoordTo(rawCoordMtm).join(', ')}` + }); } projections.forEach(projection => { const rawCoord = olproj.transform(lonLat, 'EPSG:4326', projection.code); const numericEpsgCode = projection.code.split(':')[1]; - convertedLonLat.push( - { - code: projection.code, - alias: projection.alias || projection.code, - coord: rawCoord, - igo2CoordFormat: `${roundCoordTo(rawCoord).join(', ')} ; ${numericEpsgCode}` - }); + convertedLonLat.push({ + code: projection.code, + alias: projection.alias || projection.code, + coord: rawCoord, + igo2CoordFormat: `${roundCoordTo(rawCoord).join( + ', ' + )} ; ${numericEpsgCode}` + }); }); return convertedLonLat; - } /** @@ -416,15 +530,35 @@ export function utmZoneFromLonLat(lonLat: [number, number]) { export function mtmZoneFromLonLat(lonLat: [number, number]) { const long = lonLat[0]; let mtmZone; - if (long < -51 && long > -54) {mtmZone = 1; } - if (long < -54 && long > -57) {mtmZone = 2; } - if (long < -57 && long > -60) {mtmZone = 3; } - if (long < -60 && long > -63) {mtmZone = 4; } - if (long < -63 && long > -66) {mtmZone = 5; } - if (long < -66 && long > -69) {mtmZone = 6; } - if (long < -69 && long > -72) {mtmZone = 7; } - if (long < -72 && long > -75) {mtmZone = 8; } - if (long < -75 && long > -78) {mtmZone = 9; } - if (long < -78 && long > -81) {mtmZone = 10; } + if (long < -51 && long > -54) { + mtmZone = 1; + } + if (long < -54 && long > -57) { + mtmZone = 2; + } + if (long < -57 && long > -60) { + mtmZone = 3; + } + if (long < -60 && long > -63) { + mtmZone = 4; + } + if (long < -63 && long > -66) { + mtmZone = 5; + } + if (long < -66 && long > -69) { + mtmZone = 6; + } + if (long < -69 && long > -72) { + mtmZone = 7; + } + if (long < -72 && long > -75) { + mtmZone = 8; + } + if (long < -75 && long > -78) { + mtmZone = 9; + } + if (long < -78 && long > -81) { + mtmZone = 10; + } return mtmZone; }