-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gpm-sandcastle
- Loading branch information
Showing
27 changed files
with
529 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import Check from "./Check.js"; | ||
import Credit from "./Credit.js"; | ||
import defaultValue from "./defaultValue.js"; | ||
import Rectangle from "./Rectangle.js"; | ||
import Resource from "./Resource.js"; | ||
import defined from "./defined.js"; | ||
import DeveloperError from "./DeveloperError.js"; | ||
import RuntimeError from "./RuntimeError.js"; | ||
|
||
const API_URL = "https://maps.googleapis.com/maps/api/geocode/json"; | ||
const CREDIT_HTML = `<img alt="Google" src="https://assets.ion.cesium.com/google-credit.png" style="vertical-align:-5px">`; | ||
|
||
/** | ||
* Provides geocoding through Google. | ||
* | ||
* @see {@link https://developers.google.com/maps/documentation/geocoding/policies|Google Geocoding Policies} | ||
* @alias GoogleGeocoderService | ||
* @constructor | ||
* | ||
* @param {object} options Object with the following properties: | ||
* @param {string} options.key An API key to use with the Google geocoding service | ||
*/ | ||
function GoogleGeocoderService(options) { | ||
options = defaultValue(options, defaultValue.EMPTY_OBJECT); | ||
const key = options.key; | ||
//>>includeStart('debug', pragmas.debug); | ||
if (!defined(key)) { | ||
throw new DeveloperError("options.key is required."); | ||
} | ||
//>>includeEnd('debug'); | ||
|
||
this._resource = new Resource({ | ||
url: API_URL, | ||
queryParameters: { key }, | ||
}); | ||
|
||
this._credit = new Credit(CREDIT_HTML, true); | ||
} | ||
|
||
Object.defineProperties(GoogleGeocoderService.prototype, { | ||
/** | ||
* Gets the credit to display after a geocode is performed. Typically this is used to credit | ||
* the geocoder service. | ||
* @memberof GoogleGeocoderService.prototype | ||
* @type {Credit|undefined} | ||
* @readonly | ||
*/ | ||
credit: { | ||
get: function () { | ||
return this._credit; | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* Get a list of possible locations that match a search string. | ||
* | ||
* @function | ||
* | ||
* @param {string} query The query to be sent to the geocoder service | ||
* @returns {Promise<GeocoderService.Result[]>} | ||
* @throws {RuntimeError} If the services returns a status other than <code>OK</code> or <code>ZERO_RESULTS</code> | ||
*/ | ||
GoogleGeocoderService.prototype.geocode = async function (query) { | ||
// See API documentation at https://developers.google.com/maps/documentation/geocoding/requests-geocoding | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.string("query", query); | ||
//>>includeEnd('debug'); | ||
|
||
const resource = this._resource.getDerivedResource({ | ||
queryParameters: { | ||
address: query, | ||
}, | ||
}); | ||
|
||
const response = await resource.fetchJson(); | ||
|
||
if (response.status === "ZERO_RESULTS") { | ||
return []; | ||
} | ||
|
||
if (response.status !== "OK") { | ||
throw new RuntimeError( | ||
`GoogleGeocoderService got a bad response ${response.status}: ${response.error_message}`, | ||
); | ||
} | ||
|
||
const results = response.results.map((result) => { | ||
const southWest = result.geometry.viewport.southwest; | ||
const northEast = result.geometry.viewport.northeast; | ||
return { | ||
displayName: result.formatted_address, | ||
destination: Rectangle.fromDegrees( | ||
southWest.lng, | ||
southWest.lat, | ||
northEast.lng, | ||
northEast.lat, | ||
), | ||
attribution: { | ||
html: CREDIT_HTML, | ||
collapsible: false, | ||
}, | ||
}; | ||
}); | ||
|
||
return results; | ||
}; | ||
|
||
export default GoogleGeocoderService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Underlying geocoding services that can be used via Cesium ion. | ||
* | ||
* @enum {string} | ||
*/ | ||
const IonGeocodeProviderType = { | ||
/** | ||
* Google geocoder, for use with Google data. | ||
* | ||
* @type {string} | ||
* @constant | ||
*/ | ||
GOOGLE: "GOOGLE", | ||
|
||
/** | ||
* Bing geocoder, for use with Bing data. | ||
* | ||
* @type {string} | ||
* @constant | ||
*/ | ||
BING: "BING", | ||
|
||
/** | ||
* Use the default geocoder as set on the server. Used when neither Bing or | ||
* Google data is used. | ||
* | ||
* @type {string} | ||
* @constant | ||
*/ | ||
DEFAULT: "DEFAULT", | ||
}; | ||
|
||
export default Object.freeze(IonGeocodeProviderType); |
Oops, something went wrong.