forked from PaulLeCam/react-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoJSON.js
36 lines (28 loc) · 1.02 KB
/
GeoJSON.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
// @flow
import { GeoJSON as LeafletGeoJSON, type LatLng, type Layer } from 'leaflet'
import { withLeaflet } from './context'
import Path from './Path'
import type { PathProps } from './types'
type LeafletElement = LeafletGeoJSON
type GeoJSONdata = Object | Array<any>
type Props = {
data: GeoJSONdata,
pointToLayer?: (point: GeoJSONdata, latlng: LatLng) => Layer,
style?: (feature: GeoJSONdata) => Object,
onEachFeature?: (feature: GeoJSONdata, layer: Layer) => void,
filter?: (feature: GeoJSONdata) => boolean,
coordsToLatLng?: (coords: GeoJSONdata) => LatLng,
} & PathProps
class GeoJSON extends Path<LeafletElement, Props> {
createLeafletElement(props: Props): LeafletElement {
return new LeafletGeoJSON(props.data, this.getOptions(props))
}
updateLeafletElement(fromProps: Props, toProps: Props) {
if (typeof toProps.style === 'function') {
this.setStyle(toProps.style)
} else {
this.setStyleIfChanged(fromProps, toProps)
}
}
}
export default withLeaflet<Props, GeoJSON>(GeoJSON)