Skip to content

Commit cd52238

Browse files
committed
feat!: implement updated and simplified API
1 parent 1ece0a0 commit cd52238

24 files changed

+1543
-2523
lines changed

.eslintignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
# uses a compiled language
7979

8080
#- run: |
81-
# make bootstrap
81+
# make bootstrapInternal
8282
# make release
8383

8484
- name: Perform CodeQL Analysis

.github/workflows/e2e.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/bootstrap.js

.releaserc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 58 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,32 @@
1414
# Google Maps JavaScript API Loader
1515

1616
## Description
17-
Load the Google Maps JavaScript API script dynamically. This takes inspiration from the [google-maps](https://www.npmjs.com/package/google-maps) npm package but updates it with ES6, Promises, and TypeScript.
17+
18+
Load the Google Maps JavaScript API script dynamically. This is essentially
19+
an npm version of the [Dynamic Library Import](https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import)
20+
script.
1821

1922
## Requirements
2023

21-
* [Sign up with Google Maps Platform]
22-
* A Google Maps Platform [project] with the [**Maps Javascript API**][maps-sdk] enabled
23-
* An [API key] associated with the project above
24-
* [@googlemaps/js-api-loader NPM package][npm-pkg]
24+
- [Sign up with Google Maps Platform]
25+
- A Google Cloud Platform [project] with the [**Maps JavaScript API**]
26+
[maps-sdk] enabled
27+
- An [API key] associated with the project above
28+
- [@googlemaps/js-api-loader NPM package][npm-pkg]
2529

2630
## Installation
2731

28-
Install the [@googlemaps/js-api-loader NPM package][npm-pkg] with:
32+
Install the [`@googlemaps/js-api-loader` NPM package][npm-pkg] with:
2933

3034
```sh
31-
npm i @googlemaps/js-api-loader
35+
npm install @googlemaps/js-api-loader
3236
```
3337

34-
Alternatively you may add the umd package directly to the html document using the unpkg link.
38+
Alternatively you may add the UMD package directly to the html document using
39+
the unpkg link.
3540

3641
```html
37-
<script src="https://unpkg.com/@googlemaps/js-api-loader@1.x/dist/index.min.js"></script>
42+
<script src="https://unpkg.com/@googlemaps/js-api-loader@2.x/dist/index.umd.js"></script>
3843
```
3944

4045
When adding via unpkg, the loader can be accessed at `google.maps.plugins.loader.Loader`.
@@ -44,106 +49,83 @@ When adding via unpkg, the loader can be accessed at `google.maps.plugins.loader
4449
TypeScript users need to install the following types package.
4550

4651
```sh
47-
npm i -D @types/google.maps
52+
npm install --save-dev @types/google.maps
4853
```
4954

5055
## Documentation
5156

52-
The reference documentation can be found at this [link](https://googlemaps.github.io/js-api-loader/index.html). The Google Maps JavaScript API [documentation](https://developers.google.com/maps/documentation/javascript/tutorial) is the authoritative source for the loader options.
57+
The reference documentation can be found at this [link][reference]. The Google
58+
Maps JavaScript API documentation is the authoritative source for the loader options.
5359

5460
## Usage
5561

5662
```javascript
57-
import { Loader } from '@googlemaps/js-api-loader';
58-
59-
const loader = new Loader({
60-
apiKey: "",
61-
version: "weekly",
62-
libraries: ["places"]
63+
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
64+
65+
// set the options for loading the API.
66+
// See here for a list of supported options:
67+
// https://developers.google.com/maps/documentation/javascript/load-maps-js-api#required_parameters
68+
setOptions({ key: "your-api-key-here" });
69+
70+
// load the needed APIs asynchronously.
71+
// Once the returned promise is fulfilled, the libraries are also
72+
// available in the global `google.maps` namespace.
73+
const { Map } = await importLibrary("maps");
74+
const map = new Map(mapEl, mapOptions);
75+
76+
// alternatively:
77+
await importLibrary("maps");
78+
const map = new google.maps.Map(mapEl, mapOptions);
79+
80+
// or, if you prefer using callbacks instead of async/awqait:
81+
importLibrary("maps").then(() => {
82+
const map = new google.maps.Map(mapEl, mapOptions);
6383
});
64-
65-
const mapOptions = {
66-
center: {
67-
lat: 0,
68-
lng: 0
69-
},
70-
zoom: 4
71-
};
72-
73-
```
74-
75-
Using a promise for a specific library.
76-
77-
```javascript
78-
// Promise for a specific library
79-
loader
80-
.importLibrary('maps')
81-
.then(({Map}) => {
82-
new Map(document.getElementById("map"), mapOptions);
83-
})
84-
.catch((e) => {
85-
// do something
86-
});
8784
```
8885

89-
Using a promise for when the script has loaded.
90-
91-
```javascript
92-
// Promise
93-
loader
94-
.load()
95-
.then((google) => {
96-
new google.maps.Map(document.getElementById("map"), mapOptions);
97-
})
98-
.catch(e => {
99-
// do something
100-
});
101-
```
102-
103-
Alternatively, if you want to use a callback.
104-
105-
```javascript
106-
// Callback
107-
loader.loadCallback(e => {
108-
if (e) {
109-
console.log(e);
110-
} else {
111-
new google.maps.Map(document.getElementById("map"), mapOptions);
112-
}
113-
});
114-
```
115-
116-
View the package in action [here](https://googlemaps.github.io/js-api-loader/examples/index.html).
117-
11886
## Contributing
11987

120-
Contributions are welcome and encouraged! If you'd like to contribute, send us a [pull request] and refer to our [code of conduct] and [contributing guide].
88+
Contributions are welcome and encouraged! If you'd like to contribute, send
89+
us a [pull request] and refer to our [code of conduct] and [contributing guide].
12190

12291
## Terms of Service
12392

124-
This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to the Google Maps Platform [Terms of Service].
93+
This library uses Google Maps Platform services. Use of Google Maps
94+
Platform services through this library is subject to the Google Maps
95+
Platform [Terms of Service].
12596

126-
This library is not a Google Maps Platform Core Service. Therefore, the Google Maps Platform Terms of Service (e.g. Technical Support Services, Service Level Agreements, and Deprecation Policy) do not apply to the code in this library.
97+
This library is not a Google Maps Platform Core Service. Therefore, the
98+
Google Maps Platform Terms of Service (e.g. Technical Support Services,
99+
Service Level Agreements, and Deprecation Policy) do not apply to the code
100+
in this library.
127101

128102
### European Economic Area (EEA) developers
129103

130104
If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](https://developers.google.com/maps/comms/eea/faq).
131105

132106
## Support
133107

134-
This library is offered via an open source [license]. It is not governed by the Google Maps Platform Support [Technical Support Services Guidelines, the SLA, or the [Deprecation Policy]. However, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service.
108+
This library is offered via an open source [license]. It is not governed by
109+
the Google Maps Platform Support [Technical Support Services Guidelines],
110+
the [SLA], or the [Deprecation Policy]. However, any Google Maps Platform
111+
services used by the library remain subject to the Google Maps Platform Terms of Service.
135112

136-
This library adheres to [semantic versioning] to indicate when backwards-incompatible changes are introduced. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.
113+
This library adheres to [semantic versioning] to indicate when
114+
backwards-incompatible changes are introduced.
137115

138-
If you find a bug, or have a feature request, please [file an issue] on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of our [developer community channels]. If you'd like to contribute, please check the [contributing guide].
116+
If you find a bug, or have a feature request, please [file an issue] on
117+
GitHub. If you would like to get answers to technical questions from other
118+
Google Maps Platform developers, ask through one of our
119+
[developer community channels].
120+
If you'd like to contribute, please check the [contributing guide].
139121

140122
You can also discuss this library on our [Discord server].
141123

142124
[API key]: https://developers.google.com/maps/documentation/javascript/get-api-key
143125
[maps-sdk]: https://developers.google.com/maps/documentation/javascript
126+
[reference]: https://googlemaps.github.io/js-api-loader/index.html
144127
[documentation]: https://googlemaps.github.io/js-api-loader
145128
[npm-pkg]: https://npmjs.com/package/@googlemaps/js-api-loader
146-
147129
[code of conduct]: ?tab=coc-ov-file#readme
148130
[contributing guide]: CONTRIBUTING.md
149131
[Deprecation Policy]: https://cloud.google.com/maps-platform/terms

e2e/index.html

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)