forked from PaulLeCam/react-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWMSTileLayer.js
45 lines (36 loc) · 1.28 KB
/
WMSTileLayer.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
42
43
44
45
// @flow
import { TileLayer } from 'leaflet'
import isEqual from 'fast-deep-equal'
import { withLeaflet } from './context'
import GridLayer from './GridLayer'
import { EVENTS_RE } from './MapEvented'
import type { GridLayerProps } from './types'
type LeafletElement = TileLayer.WMS
type Props = { url: string } & GridLayerProps
class WMSTileLayer extends GridLayer<LeafletElement, Props> {
createLeafletElement(props: Props): LeafletElement {
const { url, ...params } = props
return new TileLayer.WMS(url, this.getOptions(params))
}
updateLeafletElement(fromProps: Props, toProps: Props) {
super.updateLeafletElement(fromProps, toProps)
const { url: prevUrl, opacity: _po, zIndex: _pz, ...prevParams } = fromProps
const { url, opacity: _o, zIndex: _z, ...params } = toProps
if (url !== prevUrl) {
this.leafletElement.setUrl(url)
}
if (!isEqual(params, prevParams)) {
this.leafletElement.setParams(params)
}
}
getOptions(params: Object): Object {
const superOptions = super.getOptions(params)
return Object.keys(superOptions).reduce((options, key) => {
if (!EVENTS_RE.test(key)) {
options[key] = superOptions[key]
}
return options
}, {})
}
}
export default withLeaflet<Props, WMSTileLayer>(WMSTileLayer)