Skip to content

Commit 1c41fad

Browse files
authored
feat: add url option (#59)
1 parent caffe67 commit 1c41fad

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ test.each([
3636
{ mapIds: ["foo", "bar"] },
3737
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&map_ids=foo,bar",
3838
],
39+
[
40+
{ url: "https://example.com/js" },
41+
"https://example.com/js?callback=__googleMapsCallback",
42+
],
3943
])("createUrl is correct", (options: LoaderOptions, expected: string) => {
4044
const loader = new Loader(options);
4145
expect(loader.createUrl()).toEqual(expected);

src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export interface LoaderOptions {
130130
* your bootstrap request.
131131
*/
132132
mapIds?: string[];
133+
/**
134+
* Use a custom url and path to load the Google Maps API script.
135+
*/
136+
url?: string;
133137
}
134138

135139
/**
@@ -179,8 +183,12 @@ export class Loader {
179183
*/
180184
mapIds: string[];
181185

186+
/**
187+
* See [[LoaderOptions.url]]
188+
*/
189+
url: string;
190+
182191
private CALLBACK = "__googleMapsCallback";
183-
private URL = "https://maps.googleapis.com/maps/api/js";
184192
private callbacks: ((e: Event) => void)[] = [];
185193
private done = false;
186194
private loading = false;
@@ -202,21 +210,23 @@ export class Loader {
202210
region,
203211
version,
204212
mapIds,
213+
url = "https://maps.googleapis.com/maps/api/js",
205214
}: LoaderOptions) {
206215
this.version = version;
207216
this.apiKey = apiKey;
208217
this.libraries = libraries;
209218
this.language = language;
210219
this.region = region;
211220
this.mapIds = mapIds;
221+
this.url = url;
212222
}
213223
/**
214224
* CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
215225
*
216226
* @ignore
217227
*/
218228
createUrl(): string {
219-
let url = this.URL;
229+
let url = this.url;
220230

221231
url += `?callback=${this.CALLBACK}`;
222232

0 commit comments

Comments
 (0)