Skip to content

Commit

Permalink
feat(LazyMapsAPILoader): support libraries query param
Browse files Browse the repository at this point in the history
closes #114
  • Loading branch information
sebholstein committed Feb 9, 2016
1 parent e9f9d31 commit a94662f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/services/maps-api-loader/lazy-maps-api-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,31 @@ export enum GoogleMapsScriptProtocol {
}

export class LazyMapsAPILoaderConfig {
/**
* The Google Maps API Key (see:
* https://developers.google.com/maps/documentation/javascript/get-api-key)
*/
apiKey: string = null;

/**
* Google Maps API version.
*/
apiVersion: string = '3';

/**
* Host and Path used for the `<script>` tag.
*/
hostAndPath: string = 'maps.googleapis.com/maps/api/js';

/**
* Protocol used for the `<script>` tag.
*/
protocol: GoogleMapsScriptProtocol = GoogleMapsScriptProtocol.HTTPS;

/**
* Defines which Google Maps libraries should get loaded.
*/
libraries: string[] = [];
}

const DEFAULT_CONFIGURATION = new LazyMapsAPILoaderConfig();
Expand Down Expand Up @@ -68,13 +89,17 @@ export class LazyMapsAPILoader extends MapsAPILoader {

const hostAndPath: string = this._config.hostAndPath || DEFAULT_CONFIGURATION.hostAndPath;
const apiKey: string = this._config.apiKey || DEFAULT_CONFIGURATION.apiKey;
const libraries: string[] = this._config.libraries || DEFAULT_CONFIGURATION.libraries;
const queryParams: {[key: string]: string} = {
v: this._config.apiVersion || DEFAULT_CONFIGURATION.apiKey,
callback: callbackName
};
if (apiKey) {
queryParams['key'] = apiKey;
}
if (libraries != null && libraries.length > 0) {
queryParams['libraries'] = libraries.join(',');
}
const params: string = Object.keys(queryParams)
.map((k: string, i: number) => {
let param = (i === 0) ? '?' : '&';
Expand Down

0 comments on commit a94662f

Please sign in to comment.