/
CartographicGeocoderService.js
59 lines (54 loc) · 1.7 KB
/
CartographicGeocoderService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*global define*/
define([
'./Cartesian3',
'./defaultValue',
'./defineProperties',
'./defined',
'./DeveloperError',
'../ThirdParty/when'
], function(
Cartesian3,
defaultValue,
defineProperties,
defined,
DeveloperError,
when) {
'use strict';
/**
* Geocodes queries containing longitude and latitude coordinates and an optional height.
* Query format: `longitude latitude (height)` with longitude/latitude in degrees and height in meters.
*
* @alias CartographicGeocoderService
* @constructor
*/
function CartographicGeocoderService() {
}
/**
* @function
*
* @param {String} query The query to be sent to the geocoder service
* @returns {Promise<GeocoderResult[]>}
*/
CartographicGeocoderService.prototype.geocode = function(query) {
//>>includeStart('debug', pragmas.debug);
if (!defined(query)) {
throw new DeveloperError('query must be defined');
}
//>>includeEnd('debug');
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)) {
var result = {
displayName: query,
destination: Cartesian3.fromDegrees(longitude, latitude, height)
};
return when.resolve([result]);
}
}
return when.resolve([]);
};
return CartographicGeocoderService;
});