diff --git a/CHANGELOG.md b/CHANGELOG.md index 18161b7..ced003d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.0 Release +- Apply radius, blur, max for the first render +- Rerender heatmap when radius, blur or max changed + # 1.0.0 Release - Leaflet 1.0.0 support - React-Leaflet 1.0.0 support diff --git a/lib/HeatmapLayer.js b/lib/HeatmapLayer.js index 0d3e0bf..b6d4668 100644 --- a/lib/HeatmapLayer.js +++ b/lib/HeatmapLayer.js @@ -48,6 +48,11 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +function isTrue(cond) { + if (cond) return true; + return false; +} + function isInvalid(num) { return !(0, _lodash12.default)(num) && !num; } @@ -128,7 +133,7 @@ var HeatmapLayer = function (_MapLayer) { } this.attachEvents(); - this.updateHeatmapProps(this.getHeatmapProps(this.props)); + this.updateHeatmapProps(this.getHeatmapProps(this.props), true); }; HeatmapLayer.prototype.getMax = function getMax(props) { @@ -163,19 +168,19 @@ var HeatmapLayer = function (_MapLayer) { }; HeatmapLayer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { - this.updateHeatmapProps(this.getHeatmapProps(nextProps)); + this.updateHeatmapProps(this.getHeatmapProps(nextProps), false); }; - HeatmapLayer.prototype.updateHeatmapProps = function updateHeatmapProps(nextProps) { - if (nextProps.radius && (!this.props || nextProps.radius !== this.props.radius)) { - this._heatmap.radius(nextProps.radius); + HeatmapLayer.prototype.updateHeatmapProps = function updateHeatmapProps(nextProps, firstUpdate) { + if ([[nextProps.radius, [firstUpdate, nextProps.radius !== this.props.radius].some(isTrue)].every(isTrue), [nextProps.blur, [firstUpdate, nextProps.blur !== this.props.blur].some(isTrue)].every(isTrue)].some(isTrue)) { + this._heatmap.radius(nextProps.radius, nextProps.blur); } if (nextProps.gradient) { this._heatmap.gradient(nextProps.gradient); } - if (nextProps.max && (!this.props || nextProps.max !== this.props.max)) { + if (nextProps.max && (firstUpdate || nextProps.max !== this.props.max)) { this._heatmap.max(nextProps.max); } }; diff --git a/package.json b/package.json index bae16e4..4adff93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-leaflet-heatmap-layer", - "version": "1.0.0", + "version": "1.1.0", "description": "A custom layer for heatmaps in react-leaflet", "main": "lib/HeatmapLayer.js", "scripts": { diff --git a/src/HeatmapLayer.js b/src/HeatmapLayer.js index d815a14..39a4f22 100644 --- a/src/HeatmapLayer.js +++ b/src/HeatmapLayer.js @@ -46,6 +46,11 @@ export type LeafletZoomEvent = { center: Object; } +function isTrue(cond: boolean): boolean { + if (cond) return true; + return false; +} + function isInvalid(num: number): boolean { return !isNumber(num) && !num; } @@ -129,7 +134,7 @@ export default class HeatmapLayer extends MapLayer { } this.attachEvents(); - this.updateHeatmapProps(this.getHeatmapProps(this.props)); + this.updateHeatmapProps(this.getHeatmapProps(this.props), true); } getMax(props) { @@ -164,13 +169,29 @@ export default class HeatmapLayer extends MapLayer { } componentWillReceiveProps(nextProps: Object): void { - this.updateHeatmapProps(this.getHeatmapProps(nextProps)); + this.updateHeatmapProps(this.getHeatmapProps(nextProps), false); } - updateHeatmapProps(nextProps: Object) { - if (nextProps.radius - && (!this.props || nextProps.radius !== this.props.radius)) { - this._heatmap.radius(nextProps.radius); + updateHeatmapProps(nextProps: Object, firstUpdate: boolean) { + if ( + [ + [ + nextProps.radius, + [ + firstUpdate, + nextProps.radius !== this.props.radius, + ].some(isTrue), + ].every(isTrue), + [ + nextProps.blur, + [ + firstUpdate, + nextProps.blur !== this.props.blur, + ].some(isTrue), + ].every(isTrue), + ].some(isTrue) + ) { + this._heatmap.radius(nextProps.radius, nextProps.blur); } if (nextProps.gradient) { @@ -178,7 +199,7 @@ export default class HeatmapLayer extends MapLayer { } if (nextProps.max - && (!this.props || nextProps.max !== this.props.max)) { + && (firstUpdate || nextProps.max !== this.props.max)) { this._heatmap.max(nextProps.max); } }