Skip to content

Commit 6c333c7

Browse files
committed
Fixed google maps loading multiple scripts
1 parent cb5f6bf commit 6c333c7

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

package-lock.json

Lines changed: 13 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-leaflet-google-layer",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "React leaflet wrapper of leaflet.gridlayer.googlemutant",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ interface IProps extends L.gridLayer.GoogleMutantOptions {
1818
apiKey?: string;
1919
}
2020

21+
let googleMapsScriptLoaded = false;
22+
2123
const createLeafletElement = (props: IProps, context: LeafletContextInterface) => {
2224
const { apiKey, useGoogMapsLoader = true, googleMapsLoaderConf = {}, googleMapsAddLayers, ...googleMutantProps } = props;
23-
if (useGoogMapsLoader) {
25+
if (useGoogMapsLoader && !googleMapsScriptLoaded) {
2426
const loader = new Loader(apiKey, googleMapsLoaderConf);
2527
loader.load();
28+
googleMapsScriptLoaded = true;
2629
}
2730
const instance = L.gridLayer.googleMutant(googleMutantProps)
2831
if (googleMapsAddLayers) {

0 commit comments

Comments
 (0)