From 972a959aee58bc1a0c363cca6ecead7ece610b46 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 15 Jun 2020 09:20:46 -0700 Subject: [PATCH] feat: add support for map ids --- src/index.test.ts | 4 ++++ src/index.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index 864f7871..de5f0d7e 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -32,6 +32,10 @@ test.each([ }, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo&libraries=places&language=language®ion=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); diff --git a/src/index.ts b/src/index.ts index 9c24c571..ec00dae8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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[]; } /** @@ -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)[] = []; @@ -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]]. @@ -228,6 +240,10 @@ export class Loader { url += `&v=${this.version}`; } + if (this.mapIds) { + url += `&map_ids=${this.mapIds.join(",")}`; + } + return url; }