@@ -9,6 +9,7 @@ export enum GoogleMapsScriptProtocol {
9
9
10
10
export class LazyMapsAPILoaderConfig {
11
11
apiKey : string = null ;
12
+ apiVersion : string = '3' ;
12
13
hostAndPath : string = 'maps.googleapis.com/maps/api/js' ;
13
14
protocol : GoogleMapsScriptProtocol = GoogleMapsScriptProtocol . HTTPS ;
14
15
}
@@ -19,8 +20,11 @@ const DEFAULT_CONFIGURATION = new LazyMapsAPILoaderConfig();
19
20
export class LazyMapsAPILoader extends MapsAPILoader {
20
21
private _scriptLoadingPromise : Promise < void > ;
21
22
22
- constructor ( @Optional ( ) private _config : LazyMapsAPILoaderConfig = DEFAULT_CONFIGURATION ) {
23
+ constructor ( @Optional ( ) private _config : LazyMapsAPILoaderConfig ) {
23
24
super ( ) ;
25
+ if ( this . _config === null || this . _config === undefined ) {
26
+ this . _config = DEFAULT_CONFIGURATION ;
27
+ }
24
28
}
25
29
26
30
load ( ) : Promise < void > {
@@ -62,20 +66,21 @@ export class LazyMapsAPILoader extends MapsAPILoader {
62
66
break ;
63
67
}
64
68
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
+ } ;
69
75
if ( apiKey ) {
70
76
queryParams [ 'key' ] = apiKey ;
71
77
}
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 } ` ;
80
85
}
81
86
}
0 commit comments