Skip to content

Commit 407f402

Browse files
committed
Merge remote-tracking branch 'upstream/master' into prop_types
2 parents 885501d + 731e86e commit 407f402

File tree

5 files changed

+157
-26
lines changed

5 files changed

+157
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.0.2 Release
2+
- Fix bug where radius, blur, and max were not being used when passed in as props.
3+
14
# 1.0.1 Release
25
- Fix bug in componentWillUnmount->safeRemoveLayer where getPanes doesn't return anything so .contains is called on undefined.
36
- Fixed warning "Accessing PropTypes via the main React package is deprecated"

example/index.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ class MapExample extends React.Component {
99
state = {
1010
mapHidden: false,
1111
layerHidden: false,
12-
addressPoints
12+
addressPoints,
13+
radius: 4,
14+
blur: 8,
15+
max: 0.5,
16+
limitAddressPoints: true,
1317
};
1418

15-
componentDidMount() {
16-
setTimeout(() => {
17-
this.setState({ addressPoints: addressPoints.slice(500, 1000) });
18-
}, 5000);
19+
/**
20+
* Toggle limiting the address points to test behavior with refocusing/zooming when data points change
21+
*/
22+
toggleLimitedAddressPoints() {
23+
if (this.state.limitAddressPoints) {
24+
this.setState({ addressPoints: addressPoints.slice(500, 1000), limitAddressPoints: false });
25+
} else {
26+
this.setState({ addressPoints, limitAddressPoints: true });
27+
}
1928
}
2029

2130
render() {
@@ -48,6 +57,9 @@ class MapExample extends React.Component {
4857
latitudeExtractor={m => m[0]}
4958
gradient={gradient}
5059
intensityExtractor={m => parseFloat(m[2])}
60+
radius={Number(this.state.radius)}
61+
blur={Number(this.state.blur)}
62+
max={Number.parseFloat(this.state.max)}
5163
/>
5264
}
5365
<TileLayer
@@ -65,6 +77,45 @@ class MapExample extends React.Component {
6577
value="Toggle Layer"
6678
onClick={() => this.setState({ layerHidden: !this.state.layerHidden })}
6779
/>
80+
<input
81+
type="button"
82+
value="Toggle Limited Data"
83+
onClick={this.toggleLimitedAddressPoints.bind(this)}
84+
/>
85+
86+
<div>
87+
Radius
88+
<input
89+
type="range"
90+
min={1}
91+
max={40}
92+
value={this.state.radius}
93+
onChange={(e) => this.setState({ radius: e.currentTarget.value })}
94+
/> {this.state.radius}
95+
</div>
96+
97+
<div>
98+
Blur
99+
<input
100+
type="range"
101+
min={1}
102+
max={20}
103+
value={this.state.blur}
104+
onChange={(e) => this.setState({ blur: e.currentTarget.value })}
105+
/> {this.state.blur}
106+
</div>
107+
108+
<div>
109+
Max
110+
<input
111+
type="range"
112+
min={0.1}
113+
max={3}
114+
step={0.1}
115+
value={this.state.max}
116+
onChange={(e) => this.setState({ max: e.currentTarget.value })}
117+
/> {this.state.max}
118+
</div>
68119
</div>
69120
);
70121
}

lib/HeatmapLayer.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ var HeatmapLayer = function (_MapLayer) {
126126
if (this.props.fitBoundsOnLoad) {
127127
this.fitBounds();
128128
}
129-
130129
this.attachEvents();
131130
this.updateHeatmapProps(this.getHeatmapProps(this.props));
132131
};
@@ -163,20 +162,64 @@ var HeatmapLayer = function (_MapLayer) {
163162
};
164163

165164
HeatmapLayer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
166-
this.updateHeatmapProps(this.getHeatmapProps(nextProps));
165+
var currentProps = this.props;
166+
var nextHeatmapProps = this.getHeatmapProps(nextProps);
167+
168+
this.updateHeatmapGradient(nextHeatmapProps.gradient);
169+
170+
var hasRadiusUpdated = nextHeatmapProps.radius !== currentProps.radius;
171+
var hasBlurUpdated = nextHeatmapProps.blur !== currentProps.blur;
172+
173+
if (hasRadiusUpdated || hasBlurUpdated) {
174+
this.updateHeatmapRadius(nextHeatmapProps.radius, nextHeatmapProps.blur);
175+
}
176+
177+
if (nextHeatmapProps.max !== currentProps.max) {
178+
this.updateHeatmapMax(nextHeatmapProps.max);
179+
}
167180
};
168181

169-
HeatmapLayer.prototype.updateHeatmapProps = function updateHeatmapProps(nextProps) {
170-
if (nextProps.radius && (!this.props || nextProps.radius !== this.props.radius)) {
171-
this._heatmap.radius(nextProps.radius);
182+
/**
183+
* Update various heatmap properties like radius, gradient, and max
184+
*/
185+
186+
187+
HeatmapLayer.prototype.updateHeatmapProps = function updateHeatmapProps(props) {
188+
this.updateHeatmapRadius(props.radius, props.blur);
189+
this.updateHeatmapGradient(props.gradient);
190+
this.updateHeatmapMax(props.max);
191+
};
192+
193+
/**
194+
* Update the heatmap's radius and blur (blur is optional)
195+
*/
196+
197+
198+
HeatmapLayer.prototype.updateHeatmapRadius = function updateHeatmapRadius(radius, blur) {
199+
if (radius) {
200+
this._heatmap.radius(radius, blur);
172201
}
202+
};
203+
204+
/**
205+
* Update the heatmap's gradient
206+
*/
173207

174-
if (nextProps.gradient) {
175-
this._heatmap.gradient(nextProps.gradient);
208+
209+
HeatmapLayer.prototype.updateHeatmapGradient = function updateHeatmapGradient(gradient) {
210+
if (gradient) {
211+
this._heatmap.gradient(gradient);
176212
}
213+
};
214+
215+
/**
216+
* Update the heatmap's maximum
217+
*/
218+
177219

178-
if (nextProps.max && (!this.props || nextProps.max !== this.props.max)) {
179-
this._heatmap.max(nextProps.max);
220+
HeatmapLayer.prototype.updateHeatmapMax = function updateHeatmapMax(maximum) {
221+
if (maximum) {
222+
this._heatmap.max(maximum);
180223
}
181224
};
182225

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-leaflet-heatmap-layer",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A custom layer for heatmaps in react-leaflet",
55
"main": "lib/HeatmapLayer.js",
66
"scripts": {

src/HeatmapLayer.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export default class HeatmapLayer extends MapLayer {
128128
if (this.props.fitBoundsOnLoad) {
129129
this.fitBounds();
130130
}
131-
132131
this.attachEvents();
133132
this.updateHeatmapProps(this.getHeatmapProps(this.props));
134133
}
@@ -165,22 +164,57 @@ export default class HeatmapLayer extends MapLayer {
165164
}
166165

167166
componentWillReceiveProps(nextProps: Object): void {
168-
this.updateHeatmapProps(this.getHeatmapProps(nextProps));
167+
const currentProps = this.props;
168+
const nextHeatmapProps = this.getHeatmapProps(nextProps);
169+
170+
this.updateHeatmapGradient(nextHeatmapProps.gradient);
171+
172+
const hasRadiusUpdated = nextHeatmapProps.radius !== currentProps.radius;
173+
const hasBlurUpdated = nextHeatmapProps.blur !== currentProps.blur;
174+
175+
if (hasRadiusUpdated || hasBlurUpdated) {
176+
this.updateHeatmapRadius(nextHeatmapProps.radius, nextHeatmapProps.blur);
177+
}
178+
179+
if (nextHeatmapProps.max !== currentProps.max) {
180+
this.updateHeatmapMax(nextHeatmapProps.max);
181+
}
182+
183+
}
184+
185+
/**
186+
* Update various heatmap properties like radius, gradient, and max
187+
*/
188+
updateHeatmapProps(props: Object) {
189+
this.updateHeatmapRadius(props.radius, props.blur);
190+
this.updateHeatmapGradient(props.gradient);
191+
this.updateHeatmapMax(props.max);
169192
}
170193

171-
updateHeatmapProps(nextProps: Object) {
172-
if (nextProps.radius
173-
&& (!this.props || nextProps.radius !== this.props.radius)) {
174-
this._heatmap.radius(nextProps.radius);
194+
/**
195+
* Update the heatmap's radius and blur (blur is optional)
196+
*/
197+
updateHeatmapRadius(radius: number, blur: ?number): void {
198+
if (radius) {
199+
this._heatmap.radius(radius, blur);
175200
}
201+
}
176202

177-
if (nextProps.gradient) {
178-
this._heatmap.gradient(nextProps.gradient);
203+
/**
204+
* Update the heatmap's gradient
205+
*/
206+
updateHeatmapGradient(gradient: Object): void {
207+
if (gradient) {
208+
this._heatmap.gradient(gradient);
179209
}
210+
}
180211

181-
if (nextProps.max
182-
&& (!this.props || nextProps.max !== this.props.max)) {
183-
this._heatmap.max(nextProps.max);
212+
/**
213+
* Update the heatmap's maximum
214+
*/
215+
updateHeatmapMax(maximum: number): void {
216+
if (maximum) {
217+
this._heatmap.max(maximum);
184218
}
185219
}
186220

0 commit comments

Comments
 (0)