Skip to content

Commit f32b8bc

Browse files
committed
[Map][Google] Do not use deprecated loader.load() function, use loader.importLibrary() and rebuilt google.maps structure
1 parent 63e2f15 commit f32b8bc

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/Map/src/Bridge/Google/assets/dist/map_controller.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ let _google;
55
class default_1 extends AbstractMapController {
66
async connect() {
77
if (!_google) {
8-
const loader = new Loader(this.providerOptionsValue);
9-
_google = await loader.load();
8+
_google = { maps: {} };
9+
let { libraries = [], ...loaderOptions } = this.providerOptionsValue;
10+
const loader = new Loader(loaderOptions);
11+
libraries = ['core', ...libraries.filter((library) => library !== 'core')];
12+
const librariesImplementations = await Promise.all(libraries.map((library) => loader.importLibrary(library)));
13+
librariesImplementations.map((libraryImplementation, index) => {
14+
const library = libraries[index];
15+
if (['marker', 'places', 'geometry', 'journeySharing', 'drawing', 'visualization'].includes(library)) {
16+
_google.maps[library] = libraryImplementation;
17+
}
18+
else {
19+
_google.maps = { ..._google.maps, ...libraryImplementation };
20+
}
21+
});
1022
}
1123
super.connect();
1224
}

src/Map/src/Bridge/Google/assets/src/map_controller.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,29 @@ export default class extends AbstractMapController<
4747

4848
async connect() {
4949
if (!_google) {
50-
const loader = new Loader(this.providerOptionsValue);
51-
_google = await loader.load();
50+
_google = { maps: {} };
51+
52+
let { libraries = [], ...loaderOptions } = this.providerOptionsValue;
53+
54+
const loader = new Loader(loaderOptions);
55+
56+
// We could have used `loader.load()` to correctly load libraries, but this method is deprecated in favor of `loader.importLibrary()`.
57+
// But `loader.importLibrary()` is not a 1-1 replacement for `loader.load()`, we need to re-build the `google.maps` object ourselves,
58+
// see https://github.com/googlemaps/js-api-loader/issues/837 for more information.
59+
libraries = ['core', ...libraries.filter((library) => library !== 'core')]; // Ensure 'core' is loaded first
60+
const librariesImplementations = await Promise.all(
61+
libraries.map((library) => loader.importLibrary(library))
62+
);
63+
librariesImplementations.map((libraryImplementation, index) => {
64+
const library = libraries[index];
65+
66+
// The following libraries are in a sub-namespace
67+
if (['marker', 'places', 'geometry', 'journeySharing', 'drawing', 'visualization'].includes(library)) {
68+
_google.maps[library] = libraryImplementation;
69+
} else {
70+
_google.maps = { ..._google.maps, ...libraryImplementation };
71+
}
72+
});
5273
}
5374

5475
super.connect();

0 commit comments

Comments
 (0)