Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LazyMapsAPILoader): support libraries query param #114

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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