Skip to content
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 19 commits into from
Nov 22, 2024
Merged

Conversation

angrycat9000
Copy link
Contributor

@angrycat9000 angrycat9000 commented Nov 11, 2024

Description

Adds the ability to change the geocoder used.

Both Bing and Google have legal requirements that their geocoders should not be used with other data. Eg. Using Bing geocode results while showing Google 3D Tiles is not allowed.

  • Adds GoogleGeocoderService for standalone usage of Google geocoder
  • Adds IonGeocodeProvider enum to list the possible geocode providers when using Cesium ion.
  • Updates Viewer constructor to also take an IonGeocoderProvider value
  • Updates Sandcastles to specify Google or Bing geocoders where appropriate, or remove the geocoder if other map data is used.

Testing plan

  1. Run npm run start
  2. Open http://localhost:8080/Apps/Sandcastle/index.html
  3. Type in Philadelphia in the geocoder
    • Verify that multiple results are returned for Philadelphia
  4. Open http://localhost:8080/Apps/Sandcastle/index.html?src=Google%20Photorealistic%203D%20Tiles%20with%20Building%20Insert.html
  5. Type in Philadelphia in the geocoder
    • Verify that only a single result is returned
    • Verify that there is only a single google attribution at the bottom of the screen
  6. Open http://localhost:8080/Apps/Sandcastle/index.html?src=Bing%20Maps%20Labels%20Only.html
  7. Type in Philadelphia in the geocoder
    • Verify that multiple results are returned for Philadelphia
  8. Run the following code snippets in the local sandcastle and verify the results. Replace 'your-key-here` with a valid Google API key with Geocoding enabled
const viewer = new Cesium.Viewer("cesiumContainer", {
  geocoder: new Cesium.GoogleGeocoderService({
    key: 'your-key-here'
  })
});
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset({
  onlyUsingWithGoogleGeocoder: true
});
viewer.scene.primitives.add(googleTileset);
  • Type Philadelphia in the geocoder
  • Verify that a single result appears and takes you to the correct location
  • Verify that a single Google logo is shown on screen in the data attributions
const viewer = new Cesium.Viewer("cesiumContainer");
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset();
viewer.scene.primitives.add(googleTileset);
  • Verify there is a warning in the console about using the Google geocoder
const viewer = new Cesium.Viewer("cesiumContainer");
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset('your-key-here');
viewer.scene.primitives.add(googleTileset);
  • Verify that the tileset loads
  • Verify there is a deprecation warning
const viewer = new Cesium.Viewer("cesiumContainer");
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset({
  key:'your-api-key-here', 
  onlyUsingWithGoogleGeocoder: true
});
viewer.scene.primitives.add(googleTileset);
  • Verify that the tileset loads
  • Verify that there is no deprecation warning.

Author checklist

Copy link

Thank you for the pull request, @angrycat9000!

✅ We can confirm we have a CLA on file for you.

@ggetz
Copy link
Contributor

ggetz commented Nov 13, 2024

Thanks @angrycat9000! We're hoping to take a review pass today.

@angrycat9000
Copy link
Contributor Author

Thanks @ggetz . Two things that were still pending:

  • Duplicate Google attributions. The fix requires a patch for ion which will probably be deployed next week.
  • Random test failure which I had started to look into. I don't think is is related to any of my changes at this point.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good @angrycat9000! All of my comments are just code and documentation cleanup.

CHANGES.md Outdated Show resolved Hide resolved
/**
* Provides geocoding through Google.
*
* @see {@link https://developers.google.com/maps/documentation/geocoding/policies|Google Geocoding Policies}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 BingMapsGeocoderService?

packages/engine/Source/Core/GoogleGeocoderService.js Outdated Show resolved Hide resolved
packages/engine/Source/Core/IonGeocoderService.js Outdated Show resolved Hide resolved
*
* @enum {string}
*/
const IonGeocodeProvider = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const IonGeocodeProvider = {
const IonGeocodeProviderType = {

This may be a bit nit-picky, but type may help distinguish this from from the *GeocoderService instance. I got a bit confused when looking through the specs which was which.

* @memberof IonGeocoderService.prototype
* @type {IonGeocodeProvider}
*/
geocodeProvider: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
geocodeProvider: {
geocodeProviderType: {

This may be a bit nit-picky, but type may help distinguish this from from the *GeocoderService instance. I got a bit confused when looking through the specs which was which.

@@ -280,7 +281,7 @@ function enableVRUI(viewer, enabled) {
* @property {boolean} [baseLayerPicker=true] If set to false, the BaseLayerPicker widget will not be created.
* @property {boolean} [fullscreenButton=true] If set to false, the FullscreenButton widget will not be created.
* @property {boolean} [vrButton=false] If set to true, the VRButton widget will be created.
* @property {boolean|GeocoderService[]} [geocoder=true] If set to false, the Geocoder widget will not be created.
* @property {boolean|IonGeocodeProvider|GeocoderService[]} [geocoder=IonGeocodeProvider.DEFAULT] If set to false, the Geocoder widget will not be created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property {boolean|IonGeocodeProvider|GeocoderService[]} [geocoder=IonGeocodeProvider.DEFAULT] If set to false, the Geocoder widget will not be created.
* @property {boolean|IonGeocodeProvider|GeocoderService|GeocoderService[]} [geocoder=IonGeocodeProvider.DEFAULT] The geocoding service or services to use when searching with the Geocoder widget. If set to false, the Geocoder widget will not be created.

Wow, this option was not well documented prior to this PR! Let's clean it up if it's not too much trouble.

@ggetz
Copy link
Contributor

ggetz commented Nov 21, 2024

Hi @angrycat9000, I wanted to check in on the status of this PR as we are coming up on our next release soon.

  1. Are there any remaining TODO's for this PR?
  2. Is it at a point where it can come out Draft?

@angrycat9000
Copy link
Contributor Author

Hi @angrycat9000, I wanted to check in on the status of this PR as we are coming up on our next release soon.

  1. Are there any remaining TODO's for this PR?
  2. Is it at a point where it can come out Draft?

Just the discussion of how assertive to make the one time warning discussion. Added a to-do for that. Will be ready once that is decided.

@angrycat9000 angrycat9000 marked this pull request as ready for review November 21, 2024 22:22
@angrycat9000
Copy link
Contributor Author

This is updated and ready for review again @ggetz

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @angrycat9000! Thanks!

Just two small comments and this should be good to merge.

The last step would be to open an issue to track removing the deprecated API in 1.126.

@@ -44,7 +44,10 @@
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.createGooglePhotorealistic3DTileset();
tileset = await Cesium.createGooglePhotorealistic3DTileset({
Copy link
Contributor

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?

Copy link
Contributor Author

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.

options.geocodeProviderType,
IonGeocodeProviderType.DEFAULT,
);
validateIonGeocodeProviderType(geocodeProviderType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function throws a developer error, we should surround it with the debug pragmas so it is stripped out in production builds.

Suggested change
validateIonGeocodeProviderType(geocodeProviderType);
//>>includeStart('debug', pragmas.debug);
validateIonGeocodeProviderType(geocodeProviderType);
//>>includeEnd('debug');

@angrycat9000
Copy link
Contributor Author

Thanks for the feedback @ggetz . Updated and ready for another look

@ggetz
Copy link
Contributor

ggetz commented Nov 22, 2024

Fantastic! Thanks for contributing this @angrycat9000!

@ggetz ggetz added this pull request to the merge queue Nov 22, 2024
Merged via the queue into main with commit 124fd43 Nov 22, 2024
9 checks passed
@ggetz ggetz deleted the choose-your-own-geocoder branch November 22, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants