Skip to content

Commit

Permalink
Merge pull request #2439 from AnalyticalGraphicsInc/geocoder-fly
Browse files Browse the repository at this point in the history
Added (lon, lat, height) to Geocoder
  • Loading branch information
mramato committed Mar 1, 2015
2 parents 4b151fd + d5998c2 commit 4531460
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Change Log
* Added the ability to pass a `Promise` to a target to `viewer.zoomTo` and `viewer.flyTo`.
* All `CzmlDataSource` and `GeoJsonDataSource` loading functions now return `Promise` instances that resolve to the instances after data is loaded.
* Error handling in all `CzmlDataSource` and `GeoJsonDataSource` loading functions is now more consistent. Rather than a mix of exceptions and `Promise` rejections, all errors are raised via `Promise` rejections.
* In addition to addresses, the `Geocoder` widget now allows input of longitude, latitude, and an optional height in degrees and meters. Example: `-75.596, 40.038, 1000` or `-75.596 40.038`.

### 1.6 - 2015-02-02

Expand Down
23 changes: 22 additions & 1 deletion Source/Widgets/Geocoder/GeocoderViewModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*global define*/
define([
'../../Core/BingMapsApi',
'../../Core/Cartesian3',
'../../Core/defaultValue',
'../../Core/defined',
'../../Core/defineProperties',
Expand All @@ -13,6 +14,7 @@ define([
'../createCommand'
], function(
BingMapsApi,
Cartesian3,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -85,7 +87,8 @@ define([
});

/**
* Gets or sets the text to search for.
* Gets or sets the text to search for. The text can be an address, or longitude, latitude,
* and optional height, where longitude and latitude are in degrees and height is in meters.
*
* @type {String}
*/
Expand Down Expand Up @@ -190,6 +193,24 @@ define([
return;
}

// If the user entered (longitude, latitude, [height]) in degrees/meters,
// fly without calling the geocoder.
var splitQuery = query.match(/[^\s,\n]+/g);
if ((splitQuery.length === 2) || (splitQuery.length === 3)) {
var longitude = +splitQuery[0];
var latitude = +splitQuery[1];
var height = (splitQuery.length === 3) ? +splitQuery[2] : 300.0;

if (!isNaN(longitude) && !isNaN(latitude) && !isNaN(height)) {
viewModel._scene.camera.flyTo({
destination : Cartesian3.fromDegrees(longitude, latitude, height),
duration : viewModel._flightDuration,
endTransform : Matrix4.IDENTITY,
convert : false
});
return;
}
}
viewModel._isSearchInProgress = true;

var promise = jsonp(viewModel._url + 'REST/v1/Locations', {
Expand Down
23 changes: 23 additions & 0 deletions Specs/Widgets/Geocoder/GeocoderViewModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
defineSuite([
'Widgets/Geocoder/GeocoderViewModel',
'Core/Cartesian3',
'Scene/Camera',
'Specs/createScene'
], function(
GeocoderViewModel,
Cartesian3,
Camera,
createScene) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
Expand Down Expand Up @@ -74,6 +76,27 @@ defineSuite([
});
});

it('Zooms to longitude, latitude, height', function() {
var viewModel = new GeocoderViewModel({
scene : scene
});

spyOn(Camera.prototype, 'flyTo');

viewModel.searchText = ' 1.0, 2.0, 3.0 ';
viewModel.search();
expect(Camera.prototype.flyTo).toHaveBeenCalled();
expect(Camera.prototype.flyTo.mostRecentCall.args[0].destination).toEqual(Cartesian3.fromDegrees(1.0, 2.0, 3.0));

viewModel.searchText = '1.0 2.0 3.0';
viewModel.search();
expect(Camera.prototype.flyTo.mostRecentCall.args[0].destination).toEqual(Cartesian3.fromDegrees(1.0, 2.0, 3.0));

viewModel.searchText = '-1.0, -2.0';
viewModel.search();
expect(Camera.prototype.flyTo.mostRecentCall.args[0].destination).toEqual(Cartesian3.fromDegrees(-1.0, -2.0, 300.0));
});

it('constructor throws without scene', function() {
expect(function() {
return new GeocoderViewModel();
Expand Down

0 comments on commit 4531460

Please sign in to comment.