Skip to content

Commit

Permalink
Merge branch 'master' into kml_query
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviohartman authored Jun 7, 2017
2 parents 8c6028c + 4d3cd8e commit 11d5a99
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log
* Reduced the amount of Sun bloom post-process effect near the horizon. [#5381](https://github.com/AnalyticalGraphicsInc/cesium/issues/5381)
* Added Sandcastle demo for ArcticDEM data. [#5224](https://github.com/AnalyticalGraphicsInc/cesium/issues/5224)
* `CzmlDataSource` and `KmlDataSource` load functions now take an optional `query` object, which will append query parameters to all network requests. [#5419](https://github.com/AnalyticalGraphicsInc/cesium/pull/5419), [#5434](https://github.com/AnalyticalGraphicsInc/cesium/pull/5434)
* Fixed geocoder bug so geocoder can accurately handle NSEW inputs [#5407] (https://github.com/AnalyticalGraphicsInc/cesium/pull/5407)

### 1.34 - 2017-06-01

Expand Down
14 changes: 14 additions & 0 deletions Source/Core/CartographicGeocoderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ define([
var latitude = +splitQuery[1];
var height = (splitQuery.length === 3) ? +splitQuery[2] : 300.0;

if (isNaN(longitude) && isNaN(latitude)) {
var coordTest = /^(\d+.?\d*)([nsew])/i;
for (var i = 0; i < splitQuery.length; ++i) {
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];
}
}
}
}

if (!isNaN(longitude) && !isNaN(latitude) && !isNaN(height)) {
var result = {
displayName: query,
Expand Down
32 changes: 32 additions & 0 deletions Specs/Core/CartographicGeocoderServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,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) {
Expand Down

0 comments on commit 11d5a99

Please sign in to comment.