Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ test.each([
},
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo&libraries=places&language=language&region=region&v=weekly",
],
[
{ mapIds: ["foo", "bar"] },
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&map_ids=foo,bar",
],
])("createUrl is correct", (options: LoaderOptions, expected: string) => {
const loader = new Loader(options);
expect(loader.createUrl()).toEqual(expected);
Expand Down
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export interface LoaderOptions {
* ```
*/
region?: string;
/**
* (Beta) You can add multiple Map IDs to your map using the map_ids paramenter in
* your bootstrap request.
*/
mapIds?: string[];
}

/**
Expand Down Expand Up @@ -169,6 +174,11 @@ export class Loader {
*/
region: string;

/**
* See [[LoaderOptions.mapIds]]
*/
mapIds: string[];

private CALLBACK = "__googleMapsCallback";
private URL = "https://maps.googleapis.com/maps/api/js";
private callbacks: ((e: Event) => void)[] = [];
Expand All @@ -191,12 +201,14 @@ export class Loader {
language,
region,
version,
mapIds,
}: LoaderOptions) {
this.version = version;
this.apiKey = apiKey;
this.libraries = libraries;
this.language = language;
this.region = region;
this.mapIds = mapIds;
}
/**
* CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
Expand Down Expand Up @@ -228,6 +240,10 @@ export class Loader {
url += `&v=${this.version}`;
}

if (this.mapIds) {
url += `&map_ids=${this.mapIds.join(",")}`;
}

return url;
}

Expand Down