Skip to content

Commit 14809a0

Browse files
authored
Supporting react leaflet v3 (#16)
* Supporting react-leaflet-v3 * Added default props * google-maps loader version bump * Updated the readme * Fixed branch name * Updated readme
1 parent cd52299 commit 14809a0

6 files changed

Lines changed: 123 additions & 165 deletions

File tree

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
[![Coverage Status](https://coveralls.io/repos/github/aviklai/react-leaflet-google-layer/badge.svg?branch=master)](https://coveralls.io/github/aviklai/react-leaflet-google-layer?branch=master)
33
[![npm version](https://img.shields.io/npm/v/react-leaflet-google-layer.svg)](https://www.npmjs.com/package/react-leaflet-google-layer)
44

5-
Google layer for React-Leaflet using leaflet.gridlayer.googlemutant, implemented with typescript.
5+
Google layer for React-Leaflet v3 using leaflet.gridlayer.googlemutant, implemented with typescript.
66

7-
Installation instructions:
7+
## Requirements
8+
The current version of this library supports React Leaflet v3. <br/>
9+
If you are using React Leaflet v2, please use the previous version of this library. Please see the documentation here: <br/>
10+
https://github.com/aviklai/react-leaflet-google-layer/tree/v1
11+
12+
## Installation instructions:
813
1. run `npm install --save react-leaflet-google-layer`
914
2. By default this library uses the google-maps loader library to load the google maps api. If you want to use the script tag instead, you can Add google maps js api in your index.html: <br/>
1015
`<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" async defer></script>` <br/>
@@ -14,38 +19,35 @@ and set the prop useGoogMapsLoader to `false`.
1419
Usage example:
1520
```
1621
import * as React from 'react';
17-
import { Map } from 'react-leaflet';
22+
import { MapContainer } from 'react-leaflet';
1823
import ReactLeafletGoogleLayer from 'react-leaflet-google-layer';
1924
20-
export class App extends React.Component {
21-
render() {
22-
return (
23-
<Map zoom={15} center={[45, 20]}>
24-
<ReactLeafletGoogleLayer googleMapsLoaderConf={{KEY: 'YOUR_API_KEY'}} type={'satellite'} />
25-
</Map>
26-
);
27-
}
28-
}
25+
export const App = () => {
26+
return (
27+
<MapContainer zoom={15} center={[45, 20]}>
28+
<ReactLeafletGoogleLayer apiKey='YOUR_API_KEY' type={'satellite'} />
29+
</MapContainer>
30+
);
31+
};
32+
2933
```
3034

3135
## Basic usage example
32-
https://codesandbox.io/s/basicusage-qluec
36+
https://codesandbox.io/s/basic-usage-with-react-leaflet-v3-vx8fd
3337

3438
## Options
39+
apiKey?: string <br/>
3540
useGoogMapsLoader?: boolean, default: `true` <br/>
3641
googleMapsAddLayers?: { name: 'BicyclingLayer' | 'TrafficLayer' | 'TransitLayer', options?: any }[] <br/>
3742
zIndex?: number <br/>
3843

3944
#### From google-maps (https://github.com/Carrooi/Js-GoogleMapsLoader) - googleMapsLoaderConf prop:
40-
* KEY?: string
41-
* URL?: string
42-
* LIBRARIES?: string[]
43-
* CLIENT?: string
44-
* CHANNEL?: string
45-
* LANGUAGE?: string
46-
* REGION?: string
47-
* VERSION?: string
48-
* WINDOW_CALLBACK_NAME?: string
45+
* version?: string
46+
* client?: string
47+
* channel?: string
48+
* language?: string
49+
* region?: string
50+
* libraries?: string[]
4951

5052
#### From googlemutant (https://gitlab.com/IvanSanchez/Leaflet.GridLayer.GoogleMutant):
5153
* minZoom?: number

package-lock.json

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

package.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-leaflet-google-layer",
3-
"version": "1.1.5",
3+
"version": "2.0.0",
44
"description": "React leaflet wrapper of leaflet.gridlayer.googlemutant",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -32,7 +32,8 @@
3232
"Leaflet",
3333
"google",
3434
"googlemutant",
35-
"typescript"
35+
"typescript",
36+
"react-leaflet-v3"
3637
],
3738
"author": "",
3839
"license": "MIT",
@@ -41,36 +42,34 @@
4142
},
4243
"homepage": "https://github.com/aviklai/react-leaflet-google-layer#readme",
4344
"peerDependencies": {
44-
"leaflet": "^1.3.0",
45-
"react": "^16.0.0",
46-
"react-dom": "^16.0.0",
47-
"react-leaflet": "^2.0.0"
45+
"leaflet": "^1.5.0",
46+
"react": "^16.8.0",
47+
"react-dom": "^16.8.0",
48+
"react-leaflet": "^3.0.0"
4849
},
4950
"devDependencies": {
5051
"@types/jest": "^24.0.9",
5152
"@types/react": "^16.8.7",
5253
"@types/react-dom": "^16.8.2",
53-
"@types/react-leaflet": "^2.2.0",
54-
"@types/react-test-renderer": "^16.8.1",
54+
"@types/react-test-renderer": "^16.9.3",
5555
"coveralls": "^3.0.3",
5656
"jest": "^24.3.0",
57-
"leaflet": "^1.4.0",
57+
"leaflet": "^1.5.0",
5858
"prettier": "^1.16.4",
5959
"react": "^16.8.4",
6060
"react-dom": "^16.8.4",
61-
"react-leaflet": "^2.2.1",
62-
"react-test-renderer": "^16.8.4",
61+
"react-leaflet": "^3.0.0",
62+
"react-test-renderer": "^16.14.0",
6363
"ts-jest": "^24.0.0",
6464
"tslint": "^5.13.1",
6565
"tslint-config-prettier": "^1.18.0",
66-
"typescript": "^3.3.3333",
66+
"typescript": "^4.0.5",
6767
"uglify-js": "^3.5.15"
6868
},
6969
"dependencies": {
70-
"@types/google-maps": "^3.2.0",
71-
"@types/leaflet": "^1.4.1",
70+
"@types/leaflet": "^1.5.0",
7271
"@types/leaflet.gridlayer.googlemutant": "^0.4.5",
73-
"google-maps": "^3.3.0",
72+
"google-maps": "4.3.3",
7473
"leaflet.gridlayer.googlemutant": "^0.10.0"
7574
}
7675
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import * as React from 'react';
2+
import ReactDOM from 'react-dom';
23
import ReactLeafletGoogleLayer from '../index';
3-
import { Map } from 'react-leaflet';
4+
import { MapContainer } from 'react-leaflet';
45
import * as ReactTestUtils from 'react-dom/test-utils';
56

7+
68
test('ReactLeafletGoogleLayer', () => {
7-
expect(ReactLeafletGoogleLayer);
9+
expect(ReactLeafletGoogleLayer);
810

9-
const component = ReactTestUtils.renderIntoDocument(
10-
<Map>
11-
<ReactLeafletGoogleLayer />
12-
</Map>
11+
const dom = ReactTestUtils.renderIntoDocument(
12+
<div>
13+
<MapContainer>
14+
<ReactLeafletGoogleLayer />
15+
</MapContainer>
16+
</div>
1317
) as any;
14-
expect(component.leafletElement._container).toBeDefined()
15-
18+
const component = ReactDOM.findDOMNode(dom.childNodes[0]) as any;
19+
expect(component).toBeInstanceOf(HTMLElement);
1620
});

0 commit comments

Comments
 (0)