Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geocoder lon lat bug #5407

Merged
merged 6 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
* Fixed a bug where picking clusters would return undefined instead of a list of the clustered entities. [#5286](https://github.com/AnalyticalGraphicsInc/cesium/issues/5286)
* 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)
* Fixed geocoder bug so geocoder can accurately handle NSEW inputs [#5407] (https://github.com/AnalyticalGraphicsInc/cesium/pull/5407)
* `CzmlDataSource` 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)

### 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