Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 728960d

Browse files
committed
feat(LazyMapsAPILoader): make Google Maps API version configurable
Via the LazyMapAPIConfiguration, it is now possible to configure a specific Google Maps API version. The default configuration is now `3`.
1 parent b65e35d commit 728960d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/services/maps-api-loader/lazy-maps-api-loader.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum GoogleMapsScriptProtocol {
99

1010
export class LazyMapsAPILoaderConfig {
1111
apiKey: string = null;
12+
apiVersion: string = '3';
1213
hostAndPath: string = 'maps.googleapis.com/maps/api/js';
1314
protocol: GoogleMapsScriptProtocol = GoogleMapsScriptProtocol.HTTPS;
1415
}
@@ -19,8 +20,11 @@ const DEFAULT_CONFIGURATION = new LazyMapsAPILoaderConfig();
1920
export class LazyMapsAPILoader extends MapsAPILoader {
2021
private _scriptLoadingPromise: Promise<void>;
2122

22-
constructor(@Optional() private _config: LazyMapsAPILoaderConfig = DEFAULT_CONFIGURATION) {
23+
constructor(@Optional() private _config: LazyMapsAPILoaderConfig) {
2324
super();
25+
if (this._config === null || this._config === undefined) {
26+
this._config = DEFAULT_CONFIGURATION;
27+
}
2428
}
2529

2630
load(): Promise<void> {
@@ -62,20 +66,21 @@ export class LazyMapsAPILoader extends MapsAPILoader {
6266
break;
6367
}
6468

65-
const hostAndPath: string =
66-
(this._config && this._config.hostAndPath) || DEFAULT_CONFIGURATION.hostAndPath;
67-
const apiKey: string = (this._config && this._config.apiKey) || DEFAULT_CONFIGURATION.apiKey;
68-
const queryParams: {[key: string]: string} = {};
69+
const hostAndPath: string = this._config.hostAndPath || DEFAULT_CONFIGURATION.hostAndPath;
70+
const apiKey: string = this._config.apiKey || DEFAULT_CONFIGURATION.apiKey;
71+
const queryParams: {[key: string]: string} = {
72+
v: this._config.apiVersion || DEFAULT_CONFIGURATION.apiKey,
73+
callback: callbackName
74+
};
6975
if (apiKey) {
7076
queryParams['key'] = apiKey;
7177
}
72-
queryParams['callback'] = callbackName;
73-
const queryParamsString: string =
74-
Object.keys(queryParams)
75-
.map(
76-
(key: string, index: number) =>
77-
index === 0 ? `?${key}=${queryParams[key]}` : `&${key}=${queryParams[key]}`)
78-
.join('');
79-
return `${protocol}//${hostAndPath}${queryParamsString}`;
78+
const params: string = Object.keys(queryParams)
79+
.map((k: string, i: number) => {
80+
let param = (i === 0) ? '?' : '&';
81+
return param += `${k}=${queryParams[k]}`;
82+
})
83+
.join('');
84+
return `${protocol}//${hostAndPath}${params}`;
8085
}
8186
}

0 commit comments

Comments
 (0)