-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add option to select which geocoder is used #12299
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9557a3e
Add option to select which geocoder is used
angrycat9000 3bd5d72
Fix bug with gecoder:undefined getting passed in the query
angrycat9000 5f849b1
Update documentation
angrycat9000 096e67b
Fix documentation for IonGeocodeProvider
angrycat9000 0b2e65e
IonGeocoderProvider -> IonGeocodeProvider
angrycat9000 79cb58b
Add GoogleGeocoderService
angrycat9000 fa0da08
Update for Google Geocoder
angrycat9000 f04ee84
Update CHANGES.md
angrycat9000 4e91c99
Minor PR feedback
angrycat9000 a781121
Rename IonGeocodeProvder -> IonGeocodeProviderType
angrycat9000 0c382fd
Merge branch 'main' into choose-your-own-geocoder
angrycat9000 31e10f7
Merge branch 'main' into choose-your-own-geocoder
angrycat9000 b511f59
Remove geocoder from sandcastles with non bing/google map data
angrycat9000 5014ecb
Add links to terms of service
angrycat9000 c05d122
More renames of geocodeProvider -> geocodeProviderType
angrycat9000 6a43470
Merge branch 'main' into choose-your-own-geocoder
angrycat9000 8a20ef0
Add one time warning and deprecation
angrycat9000 d1fb2e0
Merge branch 'main' into choose-your-own-geocoder
angrycat9000 154c705
Minor PR feedback
angrycat9000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great that you included the link! Can we call out explicitly the "TLDR"– that Google Geocoding should only be used when using Google data in the scene? And is there a similar disclaimer we should put in |
||
* @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 | ||
* | ||
ggetz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @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 | ||
ggetz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//>>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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the
geocoder: false
viewer option be set for this example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say yes since it isn't valid for the non-georeferenced models.
The use with the Maxar data is more of a grey area so it is probably good to remove it on that account too.