Skip to content

Commit 202d098

Browse files
committed
get example working and some lint fixes
1 parent 63d0f02 commit 202d098

File tree

2 files changed

+34
-59
lines changed

2 files changed

+34
-59
lines changed

lib/HeatmapLayer.js

Lines changed: 20 additions & 31 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);
@@ -68,9 +64,9 @@ function isInvalidLatLngArray(arr) {
6864
return !isValidLatLngArray(arr);
6965
}
7066

71-
function safeRemoveLayer(map, el) {
72-
var _map$getPanes = map.getPanes(),
73-
overlayPane = _map$getPanes.overlayPane;
67+
function safeRemoveLayer(leafletMap, el) {
68+
var _leafletMap$getPanes = leafletMap.getPanes(),
69+
overlayPane = _leafletMap$getPanes.overlayPane;
7470

7571
if (overlayPane.contains(el)) {
7672
overlayPane.removeChild(el);
@@ -95,41 +91,34 @@ var HeatmapLayer = function (_MapLayer) {
9591
};
9692

9793
HeatmapLayer.prototype.componentDidMount = function componentDidMount() {
98-
var _style;
94+
var _this2 = this;
9995

10096
var canAnimate = this.context.map.options.zoomAnimation && _leaflet2.default.Browser.any3d;
10197
var zoomClass = 'leaflet-zoom-' + (canAnimate ? 'animated' : 'hide');
10298
var mapSize = this.context.map.getSize();
10399
var transformProp = _leaflet2.default.DomUtil.testProp(['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin']);
104100

105-
var canvasProps = {
106-
className: 'leaflet-heatmap-layer leaflet-layer ' + zoomClass,
107-
style: (_style = {}, _style[transformProp] = '50% 50%', _style),
108-
width: mapSize.x,
109-
height: mapSize.y
110-
};
111-
112101
this._el = _leaflet2.default.DomUtil.create('canvas', zoomClass);
113102
this._el.style[transformProp] = '50% 50%';
114103
this._el.width = mapSize.x;
115104
this._el.height = mapSize.y;
116105

117106
var el = this._el;
118107

119-
var element = _leaflet2.default.Layer.extend({
120-
onAdd: function onAdd(map) {
121-
map.getPanes().overlayPane.appendChild(el);
108+
var Heatmap = _leaflet2.default.Layer.extend({
109+
onAdd: function onAdd(leafletMap) {
110+
return leafletMap.getPanes().overlayPane.appendChild(el);
122111
},
123-
addTo: function addTo(map) {
124-
map.addLayer(this);
125-
return this;
112+
addTo: function addTo(leafletMap) {
113+
leafletMap.addLayer(_this2);
114+
return _this2;
126115
},
127-
onRemove: function onRemove(map) {
128-
safeRemoveLayer(map, el);
116+
onRemove: function onRemove(leafletMap) {
117+
return safeRemoveLayer(leafletMap, el);
129118
}
130119
});
131120

132-
this.leafletElement = new element();
121+
this.leafletElement = new Heatmap();
133122
_MapLayer.prototype.componentDidMount.call(this);
134123
this._heatmap = (0, _simpleheat2.default)(this._el);
135124
this.reset();
@@ -222,14 +211,14 @@ var HeatmapLayer = function (_MapLayer) {
222211
};
223212

224213
HeatmapLayer.prototype.attachEvents = function attachEvents() {
225-
var _this2 = this;
214+
var _this3 = this;
226215

227216
var leafletMap = this.props.map;
228217
leafletMap.on('viewreset', function () {
229-
return _this2.reset();
218+
return _this3.reset();
230219
});
231220
leafletMap.on('moveend', function () {
232-
return _this2.reset();
221+
return _this3.reset();
233222
});
234223
if (leafletMap.options.zoomAnimation && _leaflet2.default.Browser.any3d) {
235224
leafletMap.on('zoomanim', this._animateZoom, this);
@@ -241,9 +230,9 @@ var HeatmapLayer = function (_MapLayer) {
241230
var offset = this.context.map._getCenterOffset(e.center)._multiplyBy(-scale).subtract(this.context.map._getMapPanePos());
242231

243232
if (_leaflet2.default.DomUtil.setTransform) {
244-
_leaflet2.default.DomUtil.setTransform(this.refs.container, offset, scale);
233+
_leaflet2.default.DomUtil.setTransform(this._el, offset, scale);
245234
} else {
246-
this.refs.container.style[_leaflet2.default.DomUtil.TRANSFORM] = _leaflet2.default.DomUtil.getTranslateString(offset) + ' scale(' + scale + ')';
235+
this._el.style[_leaflet2.default.DomUtil.TRANSFORM] = _leaflet2.default.DomUtil.getTranslateString(offset) + ' scale(' + scale + ')';
247236
}
248237
};
249238

@@ -254,10 +243,10 @@ var HeatmapLayer = function (_MapLayer) {
254243
var size = this.context.map.getSize();
255244

256245
if (this._heatmap._width !== size.x) {
257-
this.refs.container.width = this._heatmap._width = size.x;
246+
this._el.width = this._heatmap._width = size.x;
258247
}
259248
if (this._heatmap._height !== size.y) {
260-
this.refs.container.height = this._heatmap._height = size.y;
249+
this._el.height = this._heatmap._height = size.y;
261250
}
262251

263252
if (this._heatmap && !this._frame && !this.props.map._animating) {

src/HeatmapLayer.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
32
import map from 'lodash.map';
43
import reduce from 'lodash.reduce';
54
import filter from 'lodash.filter';
@@ -63,8 +62,8 @@ function isInvalidLatLngArray(arr: Array<number>): boolean {
6362
return !isValidLatLngArray(arr);
6463
}
6564

66-
function safeRemoveLayer (map, el) {
67-
const {overlayPane} = map.getPanes();
65+
function safeRemoveLayer(leafletMap: Map, el): void {
66+
const { overlayPane } = leafletMap.getPanes();
6867
if (overlayPane.contains(el)) {
6968
overlayPane.removeChild(el);
7069
}
@@ -104,36 +103,23 @@ export default class HeatmapLayer extends MapLayer {
104103
['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin']
105104
);
106105

107-
const canvasProps = {
108-
className: `leaflet-heatmap-layer leaflet-layer ${zoomClass}`,
109-
style: {
110-
[transformProp]: '50% 50%'
111-
},
112-
width: mapSize.x,
113-
height: mapSize.y
114-
};
115-
116106
this._el = L.DomUtil.create('canvas', zoomClass);
117-
this._el.style[transformProp] = '50% 50%'
107+
this._el.style[transformProp] = '50% 50%';
118108
this._el.width = mapSize.x;
119109
this._el.height = mapSize.y;
120110

121-
var el = this._el
111+
const el = this._el;
122112

123-
var element = L.Layer.extend({
124-
onAdd: function (map) {
125-
map.getPanes().overlayPane.appendChild(el);
126-
},
127-
addTo: function (map) {
128-
map.addLayer(this);
113+
const Heatmap = L.Layer.extend({
114+
onAdd: (leafletMap) => leafletMap.getPanes().overlayPane.appendChild(el),
115+
addTo: (leafletMap) => {
116+
leafletMap.addLayer(this);
129117
return this;
130118
},
131-
onRemove: function(map) {
132-
safeRemoveLayer(map, el);
133-
}
119+
onRemove: (leafletMap) => safeRemoveLayer(leafletMap, el)
134120
});
135121

136-
this.leafletElement = new element();
122+
this.leafletElement = new Heatmap();
137123
super.componentDidMount();
138124
this._heatmap = simpleheat(this._el);
139125
this.reset();
@@ -245,9 +231,9 @@ export default class HeatmapLayer extends MapLayer {
245231
.subtract(this.context.map._getMapPanePos());
246232

247233
if (L.DomUtil.setTransform) {
248-
L.DomUtil.setTransform(this.refs.container, offset, scale);
234+
L.DomUtil.setTransform(this._el, offset, scale);
249235
} else {
250-
this.refs.container.style[L.DomUtil.TRANSFORM] =
236+
this._el.style[L.DomUtil.TRANSFORM] =
251237
`${L.DomUtil.getTranslateString(offset)} scale(${scale})`;
252238
}
253239
}
@@ -259,10 +245,10 @@ export default class HeatmapLayer extends MapLayer {
259245
const size = this.context.map.getSize();
260246

261247
if (this._heatmap._width !== size.x) {
262-
this.refs.container.width = this._heatmap._width = size.x;
248+
this._el.width = this._heatmap._width = size.x;
263249
}
264250
if (this._heatmap._height !== size.y) {
265-
this.refs.container.height = this._heatmap._height = size.y;
251+
this._el.height = this._heatmap._height = size.y;
266252
}
267253

268254
if (this._heatmap && !this._frame && !this.props.map._animating) {

0 commit comments

Comments
 (0)