forked from PaulLeCam/react-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridLayer.js
41 lines (35 loc) · 1.03 KB
/
GridLayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// @flow
import { GridLayer as LeafletGridLayer } from 'leaflet'
import MapLayer from './MapLayer'
import type { GridLayerProps } from './types'
export default class GridLayer<
LeafletElement: LeafletGridLayer,
Props: GridLayerProps,
> extends MapLayer<LeafletElement, Props> {
createLeafletElement(props: Props): LeafletElement {
return new LeafletGridLayer(this.getOptions(props))
}
updateLeafletElement(fromProps: Props, toProps: Props) {
const { opacity, zIndex } = toProps
if (opacity !== fromProps.opacity) {
this.leafletElement.setOpacity(opacity)
}
if (zIndex !== fromProps.zIndex) {
this.leafletElement.setZIndex(zIndex)
}
}
getOptions(props: Props): Props {
const options = super.getOptions(props)
return props.leaflet.map == null
? options
: // $FlowFixMe: object spread type
{
maxZoom: props.leaflet.map.options.maxZoom,
minZoom: props.leaflet.map.options.minZoom,
...options,
}
}
render() {
return null
}
}