Skip to content

Commit 33ff68a

Browse files
authored
Merge pull request #2 from evansiroky/master
fix merge conflict and linting issues
2 parents fd91971 + f33efde commit 33ff68a

File tree

8 files changed

+174
-224
lines changed

8 files changed

+174
-224
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/**
2+
lib/**

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"block-scoped-var": 0,
4848
// Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
4949
"padded-blocks": 0,
50-
50+
"no-param-reassign": 0
5151
},
5252
"plugins": [
5353
"react",

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.0.0 Release
2+
- Leaflet 1.0.0 support
3+
- React-Leaflet 1.0.0 support
4+
- List eslint as an explicit devDependency
5+
- upgrade the eslint related packages
6+
- fix linting errors using current config
7+
- Add notes about maintaining absence of lint errors and warnings in Contributing guide
8+
- This should make it easier to ensure code quality as others contribute in the open
9+
- Also, drop unused jest and enzyme deps
10+
111
# 0.2.3 Release
212
- Missed Transpilation
313

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Before submitting a Pull Request please ensure you have completed the following
5656
2. Make sure your copy is up to date: `git pull upstream master`
5757
3. Run `npm run compile`, to compile your changes to the exported `/lib` code.
5858
4. Bump the version in `package.json` as appropriate, see `Versioning` in the section below.
59+
4. Run `npm run lint` to verify code style, all pull requests should have zero lint errors and warnings
5960
4. Commit your changes
6061
5. Push your changes to your fork: `your-username/react-leaflet-heatmap-layer`
6162
6. Open a pull request from your fork to the `upstream` fork (`OpenGov/react-leaflet-heatmap-layer`)

example/index.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from 'react-dom';
3-
import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
3+
import { Map, TileLayer } from 'react-leaflet';
44
import HeatmapLayer from '../src/HeatmapLayer';
55
import { addressPoints } from './realworld.10000.js';
66

@@ -9,7 +9,7 @@ class MapExample extends React.Component {
99
state = {
1010
mapHidden: false,
1111
layerHidden: false,
12-
addressPoints: addressPoints
12+
addressPoints
1313
};
1414

1515
componentDidMount() {
@@ -25,38 +25,46 @@ class MapExample extends React.Component {
2525
<input
2626
type="button"
2727
value="Toggle Map"
28-
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })} />
28+
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })}
29+
/>
2930
</div>
3031
);
3132
}
32-
const gradient = { '0.1': '#89BDE0', '0.2': '#96E3E6', '0.4': '#82CEB6', '0.6': '#FAF3A5', '0.8': '#F5D98B', '1.0': '#DE9A96'};
33+
34+
const gradient = {
35+
0.1: '#89BDE0', 0.2: '#96E3E6', 0.4: '#82CEB6',
36+
0.6: '#FAF3A5', 0.8: '#F5D98B', '1.0': '#DE9A96'
37+
};
3338

3439
return (
3540
<div>
36-
<Map center={[0,0]} zoom={13}>
41+
<Map center={[0, 0]} zoom={13}>
3742
{!this.state.layerHidden &&
3843
<HeatmapLayer
39-
fitBoundsOnLoad
40-
fitBoundsOnUpdate
41-
points={this.state.addressPoints}
42-
longitudeExtractor={m => m[1]}
43-
latitudeExtractor={m => m[0]}
44-
gradient={gradient}
45-
intensityExtractor={m => parseFloat(m[2])} />
44+
fitBoundsOnLoad
45+
fitBoundsOnUpdate
46+
points={this.state.addressPoints}
47+
longitudeExtractor={m => m[1]}
48+
latitudeExtractor={m => m[0]}
49+
gradient={gradient}
50+
intensityExtractor={m => parseFloat(m[2])}
51+
/>
4652
}
4753
<TileLayer
48-
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
54+
url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"
4955
attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
5056
/>
5157
</Map>
5258
<input
5359
type="button"
5460
value="Toggle Map"
55-
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })} />
61+
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })}
62+
/>
5663
<input
5764
type="button"
5865
value="Toggle Layer"
59-
onClick={() => this.setState({ layerHidden: !this.state.layerHidden })} />
66+
onClick={() => this.setState({ layerHidden: !this.state.layerHidden })}
67+
/>
6068
</div>
6169
);
6270
}

lib/HeatmapLayer.js

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ var _react = require('react');
66

77
var _react2 = _interopRequireDefault(_react);
88

9-
var _reactDom = require('react-dom');
10-
11-
var _reactDom2 = _interopRequireDefault(_reactDom);
12-
139
var _lodash = require('lodash.map');
1410

1511
var _lodash2 = _interopRequireDefault(_lodash);
@@ -18,30 +14,22 @@ var _lodash3 = require('lodash.reduce');
1814

1915
var _lodash4 = _interopRequireDefault(_lodash3);
2016

21-
var _lodash5 = require('lodash.foreach');
17+
var _lodash5 = require('lodash.filter');
2218

2319
var _lodash6 = _interopRequireDefault(_lodash5);
2420

25-
var _lodash7 = require('lodash.pluck');
21+
var _lodash7 = require('lodash.min');
2622

2723
var _lodash8 = _interopRequireDefault(_lodash7);
2824

29-
var _lodash9 = require('lodash.filter');
25+
var _lodash9 = require('lodash.max');
3026

3127
var _lodash10 = _interopRequireDefault(_lodash9);
3228

33-
var _lodash11 = require('lodash.min');
29+
var _lodash11 = require('lodash.isnumber');
3430

3531
var _lodash12 = _interopRequireDefault(_lodash11);
3632

37-
var _lodash13 = require('lodash.max');
38-
39-
var _lodash14 = _interopRequireDefault(_lodash13);
40-
41-
var _lodash15 = require('lodash.isnumber');
42-
43-
var _lodash16 = _interopRequireDefault(_lodash15);
44-
4533
var _leaflet = require('leaflet');
4634

4735
var _leaflet2 = _interopRequireDefault(_leaflet);
@@ -60,25 +48,25 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
6048

6149
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; }
6250

63-
function isValidLatLngArray(arr) {
64-
return (0, _lodash10.default)(arr, isValid).length === arr.length;
51+
function isInvalid(num) {
52+
return !(0, _lodash12.default)(num) && !num;
6553
}
6654

67-
function isInvalidLatLngArray(arr) {
68-
return !isValidLatLngArray(arr);
55+
function isValid(num) {
56+
return !isInvalid(num);
6957
}
7058

71-
function isInvalid(num) {
72-
return !(0, _lodash16.default)(num) && !num;
59+
function isValidLatLngArray(arr) {
60+
return (0, _lodash6.default)(arr, isValid).length === arr.length;
7361
}
7462

75-
function isValid(num) {
76-
return !isInvalid(num);
63+
function isInvalidLatLngArray(arr) {
64+
return !isValidLatLngArray(arr);
7765
}
7866

79-
function safeRemoveLayer(map, el) {
80-
var _map$getPanes = map.getPanes(),
81-
overlayPane = _map$getPanes.overlayPane;
67+
function safeRemoveLayer(leafletMap, el) {
68+
var _leafletMap$getPanes = leafletMap.getPanes(),
69+
overlayPane = _leafletMap$getPanes.overlayPane;
8270

8371
if (overlayPane.contains(el)) {
8472
overlayPane.removeChild(el);
@@ -103,41 +91,34 @@ var HeatmapLayer = function (_MapLayer) {
10391
};
10492

10593
HeatmapLayer.prototype.componentDidMount = function componentDidMount() {
106-
var _style;
94+
var _this2 = this;
10795

10896
var canAnimate = this.context.map.options.zoomAnimation && _leaflet2.default.Browser.any3d;
10997
var zoomClass = 'leaflet-zoom-' + (canAnimate ? 'animated' : 'hide');
11098
var mapSize = this.context.map.getSize();
11199
var transformProp = _leaflet2.default.DomUtil.testProp(['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin']);
112100

113-
var canvasProps = {
114-
className: 'leaflet-heatmap-layer leaflet-layer ' + zoomClass,
115-
style: (_style = {}, _style[transformProp] = '50% 50%', _style),
116-
width: mapSize.x,
117-
height: mapSize.y
118-
};
119-
120101
this._el = _leaflet2.default.DomUtil.create('canvas', zoomClass);
121102
this._el.style[transformProp] = '50% 50%';
122103
this._el.width = mapSize.x;
123104
this._el.height = mapSize.y;
124105

125106
var el = this._el;
126107

127-
var element = _leaflet2.default.Layer.extend({
128-
onAdd: function onAdd(map) {
129-
map.getPanes().overlayPane.appendChild(el);
108+
var Heatmap = _leaflet2.default.Layer.extend({
109+
onAdd: function onAdd(leafletMap) {
110+
return leafletMap.getPanes().overlayPane.appendChild(el);
130111
},
131-
addTo: function addTo(map) {
132-
map.addLayer(this);
133-
return this;
112+
addTo: function addTo(leafletMap) {
113+
leafletMap.addLayer(_this2);
114+
return _this2;
134115
},
135-
onRemove: function onRemove(map) {
136-
safeRemoveLayer(map, el);
116+
onRemove: function onRemove(leafletMap) {
117+
return safeRemoveLayer(leafletMap, el);
137118
}
138119
});
139120

140-
this.leafletElement = new element();
121+
this.leafletElement = new Heatmap();
141122
_MapLayer.prototype.componentDidMount.call(this);
142123
this._heatmap = (0, _simpleheat2.default)(this._el);
143124
this.reset();
@@ -207,8 +188,8 @@ var HeatmapLayer = function (_MapLayer) {
207188
var points = this.props.points;
208189
var lngs = (0, _lodash2.default)(points, this.props.longitudeExtractor);
209190
var lats = (0, _lodash2.default)(points, this.props.latitudeExtractor);
210-
var ne = { lng: (0, _lodash14.default)(lngs), lat: (0, _lodash14.default)(lats) };
211-
var sw = { lng: (0, _lodash12.default)(lngs), lat: (0, _lodash12.default)(lats) };
191+
var ne = { lng: (0, _lodash10.default)(lngs), lat: (0, _lodash10.default)(lats) };
192+
var sw = { lng: (0, _lodash8.default)(lngs), lat: (0, _lodash8.default)(lats) };
212193

213194
if (shouldIgnoreLocation(ne) || shouldIgnoreLocation(sw)) {
214195
return;
@@ -230,17 +211,17 @@ var HeatmapLayer = function (_MapLayer) {
230211
};
231212

232213
HeatmapLayer.prototype.attachEvents = function attachEvents() {
233-
var _this2 = this;
214+
var _this3 = this;
234215

235-
var map = this.context.map;
236-
map.on('viewreset', function () {
237-
return _this2.reset();
216+
var leafletMap = this.props.map;
217+
leafletMap.on('viewreset', function () {
218+
return _this3.reset();
238219
});
239-
map.on('moveend', function () {
240-
return _this2.reset();
220+
leafletMap.on('moveend', function () {
221+
return _this3.reset();
241222
});
242-
if (map.options.zoomAnimation && _leaflet2.default.Browser.any3d) {
243-
map.on('zoomanim', this._animateZoom, this);
223+
if (leafletMap.options.zoomAnimation && _leaflet2.default.Browser.any3d) {
224+
leafletMap.on('zoomanim', this._animateZoom, this);
244225
}
245226
};
246227

@@ -268,7 +249,7 @@ var HeatmapLayer = function (_MapLayer) {
268249
this._el.height = this._heatmap._height = size.y;
269250
}
270251

271-
if (this._heatmap && !this._frame && !this.context.map._animating) {
252+
if (this._heatmap && !this._frame && !this.props.map._animating) {
272253
this._frame = _leaflet2.default.Util.requestAnimFrame(this.redraw, this);
273254
}
274255

@@ -286,8 +267,7 @@ var HeatmapLayer = function (_MapLayer) {
286267
var v = 1 / Math.pow(2, Math.max(0, Math.min(maxZoom - this.context.map.getZoom(), 12)));
287268

288269
var cellSize = r / 2;
289-
var grid = [];
290-
var panePos = this.context.map._getMapPanePos();
270+
var panePos = this.props.map._getMapPanePos();
291271
var offsetX = panePos.x % cellSize;
292272
var offsetY = panePos.y % cellSize;
293273
var getLat = this.props.latitudeExtractor;
@@ -298,15 +278,15 @@ var HeatmapLayer = function (_MapLayer) {
298278
return bounds.contains(p);
299279
};
300280

301-
var filterUndefined = function filterUndefined(r) {
302-
return (0, _lodash10.default)(r, function (c) {
281+
var filterUndefined = function filterUndefined(row) {
282+
return (0, _lodash6.default)(row, function (c) {
303283
return c !== undefined;
304284
});
305285
};
306286

307287
var roundResults = function roundResults(results) {
308288
return (0, _lodash4.default)(results, function (result, row) {
309-
return (0, _lodash2.default)(filterUndefined(row), function (cell, key, row) {
289+
return (0, _lodash2.default)(filterUndefined(row), function (cell) {
310290
return [Math.round(cell[0]), Math.round(cell[1]), Math.min(cell[2], maxIntensity), cell[3]];
311291
}).concat(result);
312292
}, []);
@@ -348,28 +328,27 @@ var HeatmapLayer = function (_MapLayer) {
348328
}, []);
349329
};
350330

351-
var getBounds = function getBounds(leafletMap) {
331+
var getBounds = function getBounds() {
352332
return new _leaflet2.default.Bounds(_leaflet2.default.point([-r, -r]), size.add([r, r]));
353333
};
354334

355335
var getDataForHeatmap = function getDataForHeatmap(points, leafletMap) {
356336
return roundResults(accumulateInGrid(points, leafletMap, getBounds(leafletMap)));
357337
};
358-
var data = getDataForHeatmap(this.props.points, this.context.map);
338+
339+
var data = getDataForHeatmap(this.props.points, this.props.map);
359340

360341
this._heatmap.clear();
361342
this._heatmap.data(data).draw(this.getMinOpacity(this.props));
362343

363344
this._frame = null;
364345

365346
if (this.props.onStatsUpdate && this.props.points && this.props.points.length > 0) {
366-
var stats = _.reduce(data, function (stats, point) {
347+
this.props.onStatsUpdate((0, _lodash4.default)(data, function (stats, point) {
367348
stats.max = point[3] > stats.max ? point[3] : stats.max;
368349
stats.min = point[3] < stats.min ? point[3] : stats.min;
369350
return stats;
370-
}, { min: Infinity, max: -Infinity });
371-
372-
this.props.onStatsUpdate(stats);
351+
}, { min: Infinity, max: -Infinity }));
373352
}
374353
};
375354

0 commit comments

Comments
 (0)