From ee94fd59ee7f41d62277ad7e45d799e4c19326d0 Mon Sep 17 00:00:00 2001 From: WilliamKHo Date: Thu, 1 Jun 2017 13:17:43 -0400 Subject: [PATCH 1/4] Extended CGS to accept NSEW coordinates --- Source/Core/CartographicGeocoderService.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Core/CartographicGeocoderService.js b/Source/Core/CartographicGeocoderService.js index 9102bd08eac4..203110acb08e 100644 --- a/Source/Core/CartographicGeocoderService.js +++ b/Source/Core/CartographicGeocoderService.js @@ -42,6 +42,17 @@ define([ var latitude = +splitQuery[1]; var height = (splitQuery.length === 3) ? +splitQuery[2] : 300.0; + if (isNaN(longitude) || isNaN(latitude)) { + for (var i = 0; i < splitQuery.length; ++i) { + var splitCoord = splitQuery[i].match(/^(\d+)([nsew])/i); + if (/^[ns]/i.test(splitCoord[2])) { + latitude = (/^[n]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; + } else if (/^[ew]/i.test(splitCoord[2])) { + longitude = (/^[e]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; + } + } + } + if (!isNaN(longitude) && !isNaN(latitude) && !isNaN(height)) { var result = { displayName: query, From b2bef14f3f0c1370e8b5146bea36cbfab9279e15 Mon Sep 17 00:00:00 2001 From: WilliamKHo Date: Thu, 1 Jun 2017 13:36:29 -0400 Subject: [PATCH 2/4] Added unit tests. Modified regexp for decimals. --- Source/Core/CartographicGeocoderService.js | 2 +- Specs/Core/CartographicGeocoderServiceSpec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/Core/CartographicGeocoderService.js b/Source/Core/CartographicGeocoderService.js index 203110acb08e..4658aa86263b 100644 --- a/Source/Core/CartographicGeocoderService.js +++ b/Source/Core/CartographicGeocoderService.js @@ -44,7 +44,7 @@ define([ if (isNaN(longitude) || isNaN(latitude)) { for (var i = 0; i < splitQuery.length; ++i) { - var splitCoord = splitQuery[i].match(/^(\d+)([nsew])/i); + var splitCoord = splitQuery[i].match(/^(\d+.?\d*)([nsew])/i); if (/^[ns]/i.test(splitCoord[2])) { latitude = (/^[n]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; } else if (/^[ew]/i.test(splitCoord[2])) { diff --git a/Specs/Core/CartographicGeocoderServiceSpec.js b/Specs/Core/CartographicGeocoderServiceSpec.js index d120651727fb..1fc61d1fb08a 100644 --- a/Specs/Core/CartographicGeocoderServiceSpec.js +++ b/Specs/Core/CartographicGeocoderServiceSpec.js @@ -9,6 +9,22 @@ defineSuite([ var service = new CartographicGeocoderService(); + it('returns cartesian with matching coordinates for NS/EW input', function (done) { + var query = '35N 75W'; + service.geocode(query).then(function(results) { + expect(results.length).toEqual(1); + expect(results[0].destination).toEqual(Cartesian3.fromDegrees(-75.0, 35.0, 300.0)); + }); + }); + + it('returns cartesian with matching coordinates for EW/NS input', function (done) { + var query = '75W 35N'; + service.geocode(query).then(function(results) { + expect(results.length).toEqual(1); + expect(results[0].destination).toEqual(Cartesian3.fromDegrees(-75.0, 35.0, 300.0)); + }); + }); + it('returns cartesian with matching coordinates for long/lat/height input', function (done) { var query = ' 1.0, 2.0, 3.0 '; service.geocode(query).then(function(results) { From fcd9b57bd2a4997ab6cc62cfbc1c0d8b4e2edc6a Mon Sep 17 00:00:00 2001 From: WilliamKHo Date: Thu, 1 Jun 2017 14:13:16 -0400 Subject: [PATCH 3/4] more tests --- Source/Core/CartographicGeocoderService.js | 15 +++++++++------ Specs/Core/CartographicGeocoderServiceSpec.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/Core/CartographicGeocoderService.js b/Source/Core/CartographicGeocoderService.js index 4658aa86263b..9b6f72ff895d 100644 --- a/Source/Core/CartographicGeocoderService.js +++ b/Source/Core/CartographicGeocoderService.js @@ -42,13 +42,16 @@ define([ var latitude = +splitQuery[1]; var height = (splitQuery.length === 3) ? +splitQuery[2] : 300.0; - if (isNaN(longitude) || isNaN(latitude)) { + if (isNaN(longitude) && isNaN(latitude)) { + var coordTest = /^(\d+.?\d*)([nsew])/i; for (var i = 0; i < splitQuery.length; ++i) { - var splitCoord = splitQuery[i].match(/^(\d+.?\d*)([nsew])/i); - if (/^[ns]/i.test(splitCoord[2])) { - latitude = (/^[n]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; - } else if (/^[ew]/i.test(splitCoord[2])) { - longitude = (/^[e]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; + var splitCoord = splitQuery[i].match(coordTest); + if (coordTest.test(splitQuery[i]) && splitCoord.length === 3) { + if (/^[ns]/i.test(splitCoord[2])) { + latitude = (/^[n]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; + } else if (/^[ew]/i.test(splitCoord[2])) { + longitude = (/^[e]/i.test(splitCoord[2])) ? +splitCoord[1] : -splitCoord[1]; + } } } } diff --git a/Specs/Core/CartographicGeocoderServiceSpec.js b/Specs/Core/CartographicGeocoderServiceSpec.js index 1fc61d1fb08a..f0d31c766184 100644 --- a/Specs/Core/CartographicGeocoderServiceSpec.js +++ b/Specs/Core/CartographicGeocoderServiceSpec.js @@ -44,6 +44,22 @@ defineSuite([ }); }); + it('returns empty array for input with only longitudinal coordinates', function (done) { + var query = ' 1e 1e '; + service.geocode(query).then(function(results) { + expect(results.length).toEqual(0); + done(); + }); + }); + + it('returns empty array for input with only one NSEW coordinate', function (done) { + var query = ' 1e 1 '; + service.geocode(query).then(function(results) { + expect(results.length).toEqual(0); + done(); + }); + }); + it('returns empty array for input with only one number', function (done) { var query = ' 2.0 '; service.geocode(query).then(function(results) { From 8d40ea0930a387d43777fd8ba24830eeef81de2c Mon Sep 17 00:00:00 2001 From: WilliamKHo Date: Mon, 5 Jun 2017 16:39:43 -0400 Subject: [PATCH 4/4] added to CHANGES.md --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2a31206f654c..5bf7496a9ce3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ Change Log ========== +### 1.35 - 2017-07-05 + +* Fixed geocoder bug so geocoder can accurately handle NSEW inputs [#5407] (https://github.com/AnalyticalGraphicsInc/cesium/pull/5407) + ### 1.34 - 2017-06-01 * Breaking changes