@@ -9,6 +9,7 @@ export enum GoogleMapsScriptProtocol {
99
1010export 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();
1920export 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