From b72ee0a09c8d6015e340e87851bf208349cd63b5 Mon Sep 17 00:00:00 2001 From: James Rae Date: Fri, 13 Sep 2019 15:07:14 -0400 Subject: [PATCH] fix(map): handle broke projection in northarrow --- package-lock.json | 2 +- package.json | 2 +- src/map/esriMap.js | 40 ++++++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index b212e8e3..997288f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "geoApi", - "version": "3.2.0-1", + "version": "3.2.0-2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index af4fe71a..82d7d12e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "geoApi", - "version": "3.2.0-1", + "version": "3.2.0-2", "description": "", "main": "src/index.js", "dependencies": { diff --git a/src/map/esriMap.js b/src/map/esriMap.js index 63cf84e4..684e8290 100644 --- a/src/map/esriMap.js +++ b/src/map/esriMap.js @@ -261,30 +261,34 @@ function esriMap(esriBundle, geoApi) { * http://www.movable-type.co.uk/scripts/latlong.html * @function getNorthArrowAngle * @param {Object} opts options to apply to north arrow calculation - * @returns {Number} map rotation angle (in degree) + * @returns {String} map rotation angle (in degree) in string format */ getNorthArrowAngle (opts) { // get center point in longitude and use bottom value for latitude for default point const bottomCenter = { x: (this._map.extent.xmin + this._map.extent.xmax) / 2, y: this._map.extent.ymin }; // get point if specified by caller else get default const point = opts ? opts.point || bottomCenter : bottomCenter; - const pointB = geoApi.proj.localProjectPoint(this._map.extent.spatialReference, 'EPSG:4326', point); - - // north value (set longitude to be half of Canada extent (141° W, 52° W)) - const pointA = { x: -96, y: 90 }; - - // set info on longitude and latitude - const dLon = (pointB.x - pointA.x) * Math.PI / 180; - const lat1 = pointA.y * Math.PI / 180; - const lat2 = pointB.y * Math.PI / 180; - - // calculate bearing - const y = Math.sin(dLon) * Math.cos(lat2); - const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); - const bearing = Math.atan2(y, x) * 180 / Math.PI; - - // return angle (180 is pointiong north) - return ((bearing + 360) % 360).toFixed(1); + try { + const pointB = geoApi.proj.localProjectPoint(this._map.extent.spatialReference, 'EPSG:4326', point); + + // north value (set longitude to be half of Canada extent (141° W, 52° W)) + const pointA = { x: -96, y: 90 }; + + // set info on longitude and latitude + const dLon = (pointB.x - pointA.x) * Math.PI / 180; + const lat1 = pointA.y * Math.PI / 180; + const lat2 = pointB.y * Math.PI / 180; + + // calculate bearing + const y = Math.sin(dLon) * Math.cos(lat2); + const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); + const bearing = Math.atan2(y, x) * 180 / Math.PI; + + // return angle (180 is pointiong north) + return ((bearing + 360) % 360).toFixed(1); + } catch(error) { + return '180.0'; + } } /**