Skip to content

Commit 124fd43

Browse files
authored
Merge pull request #12299 from CesiumGS/choose-your-own-geocoder
Add option to select which geocoder is used
2 parents ab9e544 + 154c705 commit 124fd43

22 files changed

+484
-26
lines changed

Apps/Sandcastle/gallery/3D Tiles Vertical Exaggeration.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ <h1>Loading...</h1>
7878
animation: false,
7979
sceneModePicker: false,
8080
baseLayerPicker: false,
81+
geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
8182
// The globe does not need to be displayed,
8283
// since the Photorealistic 3D Tiles include terrain
8384
globe: false,
@@ -104,7 +105,10 @@ <h1>Loading...</h1>
104105

105106
// Add Photorealistic 3D Tiles
106107
try {
107-
const tileset = await Cesium.createGooglePhotorealistic3DTileset();
108+
const tileset = await Cesium.createGooglePhotorealistic3DTileset({
109+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
110+
onlyUsingWithGoogleGeocoder: true,
111+
});
108112
scene.primitives.add(tileset);
109113
} catch (error) {
110114
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/AEC Clipping.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
animation: false,
3333
sceneModePicker: false,
3434
baseLayerPicker: false,
35+
geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
3536
// The globe does not need to be displayed,
3637
// since the Photorealistic 3D Tiles include terrain
3738
globe: false,
@@ -48,7 +49,10 @@
4849
// Add Photorealistic 3D Tiles
4950
let googleTileset;
5051
try {
51-
googleTileset = await Cesium.createGooglePhotorealistic3DTileset();
52+
googleTileset = await Cesium.createGooglePhotorealistic3DTileset({
53+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
54+
onlyUsingWithGoogleGeocoder: true,
55+
});
5256
viewer.scene.primitives.add(googleTileset);
5357
} catch (error) {
5458
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/Bing Maps Labels Only.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
baseLayer: false,
6868
baseLayerPicker: false,
6969
infoBox: false,
70+
geocoder: Cesium.IonGeocodeProviderType.BING,
7071
});
7172

7273
const layers = viewer.imageryLayers;

Apps/Sandcastle/gallery/Clamp Entities to Ground.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
timeline: false,
4242
animation: false,
4343
baseLayerPicker: false,
44+
geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
4445
});
4546
const scene = viewer.scene;
4647
scene.globe.depthTestAgainstTerrain = true;
@@ -56,7 +57,10 @@
5657

5758
let worldTileset;
5859
try {
59-
worldTileset = await Cesium.createGooglePhotorealistic3DTileset();
60+
worldTileset = await Cesium.createGooglePhotorealistic3DTileset({
61+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
62+
onlyUsingWithGoogleGeocoder: true,
63+
});
6064
viewer.scene.primitives.add(worldTileset);
6165
} catch (error) {
6266
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/Clipping Regions.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
animation: false,
4444
sceneModePicker: false,
4545
baseLayerPicker: false,
46+
geocoder: Cesium.IonGeocoderProviderType.GOOGLE,
4647
});
4748
const scene = viewer.scene;
4849

@@ -60,7 +61,10 @@
6061

6162
let worldTileset;
6263
try {
63-
worldTileset = await Cesium.createGooglePhotorealistic3DTileset();
64+
worldTileset = await Cesium.createGooglePhotorealistic3DTileset({
65+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
66+
onlyUsingWithGoogleGeocoder: true,
67+
});
6468
scene.primitives.add(worldTileset);
6569
} catch (error) {
6670
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/Globe Interior.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
//Sandcastle_Begin
3535
const viewer = new Cesium.Viewer("cesiumContainer", {
3636
orderIndependentTranslucency: false,
37+
geocoder: Cesium.IonGeocodeProviderType.BING,
3738
});
3839

3940
const scene = viewer.scene;

Apps/Sandcastle/gallery/Google Photorealistic 3D Tiles with Building Insert.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
animation: false,
3333
sceneModePicker: false,
3434
baseLayerPicker: false,
35+
geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
3536
// The globe does not need to be displayed,
3637
// since the Photorealistic 3D Tiles include terrain
3738
globe: false,
@@ -42,7 +43,10 @@
4243

4344
// Add Photorealistic 3D Tiles
4445
try {
45-
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset();
46+
const googleTileset = await Cesium.createGooglePhotorealistic3DTileset({
47+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
48+
onlyUsingWithGoogleGeocoder: true,
49+
});
4650
viewer.scene.primitives.add(googleTileset);
4751
} catch (error) {
4852
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/Google Photorealistic 3D Tiles.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
animation: false,
3333
sceneModePicker: false,
3434
baseLayerPicker: false,
35+
geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
3536
// The globe does not need to be displayed,
3637
// since the Photorealistic 3D Tiles include terrain
3738
globe: false,
@@ -42,7 +43,10 @@
4243

4344
// Add Photorealistic 3D Tiles
4445
try {
45-
const tileset = await Cesium.createGooglePhotorealistic3DTileset();
46+
const tileset = await Cesium.createGooglePhotorealistic3DTileset({
47+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
48+
onlyUsingWithGoogleGeocoder: true,
49+
});
4650
viewer.scene.primitives.add(tileset);
4751
} catch (error) {
4852
console.log(`Error loading Photorealistic 3D Tiles tileset.

Apps/Sandcastle/gallery/Imagery Color To Alpha.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
window.startup = async function (Cesium) {
5252
"use strict";
5353
//Sandcastle_Begin
54-
const viewer = new Cesium.Viewer("cesiumContainer");
54+
const viewer = new Cesium.Viewer("cesiumContainer", {
55+
geocoder: Cesium.IonGeocodeProviderType.BING,
56+
});
5557

5658
const layers = viewer.scene.imageryLayers;
5759

Apps/Sandcastle/gallery/Imagery Layers Manipulation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
//Sandcastle_Begin
107107
const viewer = new Cesium.Viewer("cesiumContainer", {
108108
baseLayerPicker: false,
109+
geocoder: false,
109110
});
110111
const imageryLayers = viewer.imageryLayers;
111112

Apps/Sandcastle/gallery/Imagery Layers Split.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
),
5959
baseLayerPicker: false,
6060
infoBox: false,
61+
geocoder: false,
6162
});
6263

6364
const layers = viewer.imageryLayers;

Apps/Sandcastle/gallery/development/3D Tiles Picking.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
animation: false,
3535
baseLayerPicker: false,
3636
globe: false,
37+
geocoder: false,
3738
});
3839
const scene = viewer.scene;
3940

@@ -44,7 +45,10 @@
4445
onselect: async () => {
4546
scene.primitives.remove(tileset);
4647
try {
47-
tileset = await Cesium.createGooglePhotorealistic3DTileset();
48+
tileset = await Cesium.createGooglePhotorealistic3DTileset({
49+
// Only the Google Geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of the viewer constructor options to IonGeocodeProviderType.GOOGLE.
50+
onlyUsingWithGoogleGeocoder: true,
51+
});
4852
scene.primitives.add(tileset);
4953
} catch (error) {
5054
console.log(error);

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88

99
- Added `getSample` to `SampledProperty` to get the time of samples. [#12253](https://github.com/CesiumGS/cesium/pull/12253)
1010
- Added `Entity.trackingReferenceFrame` property to allow tracking entities in their own inertial reference frame. [#12194](https://github.com/CesiumGS/cesium/pull/12194)
11+
- Added `GoogleGeocoderService` for standalone usage of Google geocoder. [#12299](https://github.com/CesiumGS/cesium/pull/12299)
1112

1213
##### Fixes :wrench:
1314

1415
- Fix label rendering bug in WebGL1 contexts. [#12301](https://github.com/CesiumGS/cesium/pull/12301)
1516
- Updated WMS example URL in UrlTemplateImageryProvider documentation to use an active service. [#12323](https://github.com/CesiumGS/cesium/pull/12323)
1617
- Fix point cloud filtering performance on certain hardware [#12317](https://github.com/CesiumGS/cesium/pull/12317)
1718

19+
##### Deprecated :hourglass_flowing_sand:
20+
21+
- `createGooglePhotorealistic3DTileset(key)` has been deprecated. Use `createGooglePhotorealistic3DTileset({key})` instead. It will be removed in 1.126.
22+
1823
#### @cesium/widgets
1924

25+
##### Additions :tada:
26+
27+
- Added the ability to choose between Bing and Google geocoders. Updated `Viewer` constructor to also accept `IonGeocoderProvider` [#12299](https://github.com/CesiumGS/cesium/pull/12299)
28+
2029
##### Fixes :wrench:
2130

2231
- Added a `DeveloperError` when `globe` is set to `false` and a `baseLayer` is provided in `Viewer` options. This prevents errors caused by attempting to use a `baseLayer` without a globe. [#12274](https://github.com/CesiumGS/cesium/pull/12274)

packages/engine/Source/Core/BingMapsGeocoderService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const url = "https://dev.virtualearth.net/REST/v1/Locations";
1010

1111
/**
1212
* Provides geocoding through Bing Maps.
13+
*
14+
* @see {@link https://www.microsoft.com/en-us/maps/bing-maps/product|Microsoft Bing Maps Platform APIs Terms Of Use}
1315
* @alias BingMapsGeocoderService
1416
* @constructor
1517
*
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import Check from "./Check.js";
2+
import Credit from "./Credit.js";
3+
import defaultValue from "./defaultValue.js";
4+
import Rectangle from "./Rectangle.js";
5+
import Resource from "./Resource.js";
6+
import defined from "./defined.js";
7+
import DeveloperError from "./DeveloperError.js";
8+
import RuntimeError from "./RuntimeError.js";
9+
10+
const API_URL = "https://maps.googleapis.com/maps/api/geocode/json";
11+
const CREDIT_HTML = `<img alt="Google" src="https://assets.ion.cesium.com/google-credit.png" style="vertical-align:-5px">`;
12+
13+
/**
14+
* Provides geocoding through Google.
15+
*
16+
* @see {@link https://developers.google.com/maps/documentation/geocoding/policies|Google Geocoding Policies}
17+
* @alias GoogleGeocoderService
18+
* @constructor
19+
*
20+
* @param {object} options Object with the following properties:
21+
* @param {string} options.key An API key to use with the Google geocoding service
22+
*/
23+
function GoogleGeocoderService(options) {
24+
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
25+
const key = options.key;
26+
//>>includeStart('debug', pragmas.debug);
27+
if (!defined(key)) {
28+
throw new DeveloperError("options.key is required.");
29+
}
30+
//>>includeEnd('debug');
31+
32+
this._resource = new Resource({
33+
url: API_URL,
34+
queryParameters: { key },
35+
});
36+
37+
this._credit = new Credit(CREDIT_HTML, true);
38+
}
39+
40+
Object.defineProperties(GoogleGeocoderService.prototype, {
41+
/**
42+
* Gets the credit to display after a geocode is performed. Typically this is used to credit
43+
* the geocoder service.
44+
* @memberof GoogleGeocoderService.prototype
45+
* @type {Credit|undefined}
46+
* @readonly
47+
*/
48+
credit: {
49+
get: function () {
50+
return this._credit;
51+
},
52+
},
53+
});
54+
55+
/**
56+
* Get a list of possible locations that match a search string.
57+
*
58+
* @function
59+
*
60+
* @param {string} query The query to be sent to the geocoder service
61+
* @returns {Promise<GeocoderService.Result[]>}
62+
* @throws {RuntimeError} If the services returns a status other than <code>OK</code> or <code>ZERO_RESULTS</code>
63+
*/
64+
GoogleGeocoderService.prototype.geocode = async function (query) {
65+
// See API documentation at https://developers.google.com/maps/documentation/geocoding/requests-geocoding
66+
67+
//>>includeStart('debug', pragmas.debug);
68+
Check.typeOf.string("query", query);
69+
//>>includeEnd('debug');
70+
71+
const resource = this._resource.getDerivedResource({
72+
queryParameters: {
73+
address: query,
74+
},
75+
});
76+
77+
const response = await resource.fetchJson();
78+
79+
if (response.status === "ZERO_RESULTS") {
80+
return [];
81+
}
82+
83+
if (response.status !== "OK") {
84+
throw new RuntimeError(
85+
`GoogleGeocoderService got a bad response ${response.status}: ${response.error_message}`,
86+
);
87+
}
88+
89+
const results = response.results.map((result) => {
90+
const southWest = result.geometry.viewport.southwest;
91+
const northEast = result.geometry.viewport.northeast;
92+
return {
93+
displayName: result.formatted_address,
94+
destination: Rectangle.fromDegrees(
95+
southWest.lng,
96+
southWest.lat,
97+
northEast.lng,
98+
northEast.lat,
99+
),
100+
attribution: {
101+
html: CREDIT_HTML,
102+
collapsible: false,
103+
},
104+
};
105+
});
106+
107+
return results;
108+
};
109+
110+
export default GoogleGeocoderService;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Underlying geocoding services that can be used via Cesium ion.
3+
*
4+
* @enum {string}
5+
*/
6+
const IonGeocodeProviderType = {
7+
/**
8+
* Google geocoder, for use with Google data.
9+
*
10+
* @type {string}
11+
* @constant
12+
*/
13+
GOOGLE: "GOOGLE",
14+
15+
/**
16+
* Bing geocoder, for use with Bing data.
17+
*
18+
* @type {string}
19+
* @constant
20+
*/
21+
BING: "BING",
22+
23+
/**
24+
* Use the default geocoder as set on the server. Used when neither Bing or
25+
* Google data is used.
26+
*
27+
* @type {string}
28+
* @constant
29+
*/
30+
DEFAULT: "DEFAULT",
31+
};
32+
33+
export default Object.freeze(IonGeocodeProviderType);

0 commit comments

Comments
 (0)