Skip to content

Commit ef2d0b9

Browse files
authored
feat: add support for map ids (#11)
1 parent 1427b5e commit ef2d0b9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ test.each([
3232
},
3333
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo&libraries=places&language=language&region=region&v=weekly",
3434
],
35+
[
36+
{ mapIds: ["foo", "bar"] },
37+
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&map_ids=foo,bar",
38+
],
3539
])("createUrl is correct", (options: LoaderOptions, expected: string) => {
3640
const loader = new Loader(options);
3741
expect(loader.createUrl()).toEqual(expected);

src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export interface LoaderOptions {
125125
* ```
126126
*/
127127
region?: string;
128+
/**
129+
* (Beta) You can add multiple Map IDs to your map using the map_ids paramenter in
130+
* your bootstrap request.
131+
*/
132+
mapIds?: string[];
128133
}
129134

130135
/**
@@ -169,6 +174,11 @@ export class Loader {
169174
*/
170175
region: string;
171176

177+
/**
178+
* See [[LoaderOptions.mapIds]]
179+
*/
180+
mapIds: string[];
181+
172182
private CALLBACK = "__googleMapsCallback";
173183
private URL = "https://maps.googleapis.com/maps/api/js";
174184
private callbacks: ((e: Event) => void)[] = [];
@@ -191,12 +201,14 @@ export class Loader {
191201
language,
192202
region,
193203
version,
204+
mapIds,
194205
}: LoaderOptions) {
195206
this.version = version;
196207
this.apiKey = apiKey;
197208
this.libraries = libraries;
198209
this.language = language;
199210
this.region = region;
211+
this.mapIds = mapIds;
200212
}
201213
/**
202214
* CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
@@ -228,6 +240,10 @@ export class Loader {
228240
url += `&v=${this.version}`;
229241
}
230242

243+
if (this.mapIds) {
244+
url += `&map_ids=${this.mapIds.join(",")}`;
245+
}
246+
231247
return url;
232248
}
233249

0 commit comments

Comments
 (0)