/
IonGeocoderService.js
77 lines (68 loc) · 2.37 KB
/
IonGeocoderService.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
define([
'./Check',
'./Credit',
'./defaultValue',
'./defined',
'./defineProperties',
'./Ion',
'./PeliasGeocoderService',
'./Rectangle',
'./Resource'
], function (
Check,
Credit,
defaultValue,
defined,
defineProperties,
Ion,
PeliasGeocoderService,
Rectangle,
Resource) {
'use strict';
/**
* Provides geocoding through Cesium ion.
* @alias IonGeocoderService
* @constructor
*
* @param {Object} options Object with the following properties:
* @param {Scene} options.scene The scene
* @param {String} [options.accessToken=Ion.defaultAccessToken] The access token to use.
* @param {String} [options.accessToken=Ion.defaultAccessToken] The access token to use.
* @param {String|Resource} [options.server=Ion.defaultServer] The resource to the Cesium ion API server.
*
* @see Ion
*/
function IonGeocoderService(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('options.scene', options.scene);
//>>includeEnd('debug');
var accessToken = defaultValue(options.accessToken, Ion.defaultAccessToken);
var server = Resource.createIfNeeded(defaultValue(options.server, Ion.defaultServer));
server.appendForwardSlash();
var defaultTokenCredit = Ion.getDefaultTokenCredit(accessToken);
if (defined(defaultTokenCredit)) {
options.scene.frameState.creditDisplay.addDefaultCredit(Credit.clone(defaultTokenCredit));
}
var searchEndpoint = server.getDerivedResource({
url: 'v1/geocode'
});
if (defined(accessToken)) {
searchEndpoint.appendQueryParameters({ access_token: accessToken });
}
this._accessToken = accessToken;
this._server = server;
this._pelias = new PeliasGeocoderService(searchEndpoint);
}
/**
* @function
*
* @param {String} query The query to be sent to the geocoder service
* @param {GeocodeType} [type=GeocodeType.SEARCH] The type of geocode to perform.
* @returns {Promise<GeocoderService~Result[]>}
*/
IonGeocoderService.prototype.geocode = function (query, geocodeType) {
return this._pelias.geocode(query, geocodeType);
};
return IonGeocoderService;
});