-
Notifications
You must be signed in to change notification settings - Fork 26
/
MapOverlay.js
140 lines (129 loc) · 2.96 KB
/
MapOverlay.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React from "react";
import {
shape,
bool,
number,
func,
node,
oneOfType,
arrayOf,
string
} from "prop-types";
import DeckGL, { GeoJsonLayer } from "deck.gl";
import centerOfMass from "@turf/center-of-mass";
const MapOverlay = props => {
const {
id,
viewport,
children,
data,
pickable,
opacity,
filled,
getFillColor,
stroked,
getLineColor,
getLineWidth,
extruded,
getElevation,
circleFieldName,
getRadius,
radiusScale,
autoHighlight,
highlightColor,
onLayerClick,
onHover,
tooltipInfo,
x,
y
} = props;
const tooltip = React.Children.map(children, child => {
return React.cloneElement(child, {
tooltipInfo,
x,
y
});
});
const tooltipRender = tooltipInfo && x && y ? tooltip : null;
const centroidData = circleFieldName
? data.map(d =>
centerOfMass(d.geometry, { properties: { ...d.properties } })
)
: [];
const radius = circleFieldName
? f => Math.sqrt(+f.properties[circleFieldName])
: getRadius || 10;
return (
<div>
<DeckGL {...viewport} className="DeckGL" getCursor={() => "crosshair"}>
<GeoJsonLayer
id={id}
className="GeoJSONMap"
pickable={pickable}
data={[...data, ...centroidData]}
opacity={opacity}
filled={filled}
getFillColor={getFillColor}
stroked={stroked}
getLineColor={getLineColor}
getLineWidth={getLineWidth}
lineWidthMinPixels={1}
extruded={extruded}
getElevation={getElevation}
circleFieldName={circleFieldName}
getRadius={radius}
pointRadiusScale={radiusScale}
pointRadiusMinPixels={1}
autoHighlight={autoHighlight}
highlightColor={highlightColor}
onClick={onLayerClick}
onHover={onHover}
updateTriggers={{
getFillColor,
getLineColor,
getLineWidth,
getRadius
}}
/>
</DeckGL>
{tooltipRender}
</div>
);
};
MapOverlay.propTypes = {
viewport: shape({}),
children: node,
id: string,
data: arrayOf(shape({})).isRequired,
pickable: bool,
opacity: number,
filled: bool,
getFillColor: oneOfType([arrayOf(number), func]),
stroked: bool,
getLineColor: oneOfType([arrayOf(number), func]),
getLineWidth: oneOfType([number, func]),
extruded: bool,
getElevation: oneOfType([number, func]),
circleFieldName: string,
getRadius: oneOfType([number, func]),
radiusScale: number,
autoHighlight: bool,
highlightColor: arrayOf(number),
onLayerClick: func,
onHover: func,
tooltipInfo: shape({}),
x: number,
y: number
};
MapOverlay.defaultProps = {
pickable: true,
opacity: 0.8,
filled: true,
getFillColor: [0, 0, 0],
stroked: true,
getLineColor: [112, 122, 122, 100],
getLineWidth: 10,
extruded: false,
autoHighlight: false
};
export default MapOverlay;