Skip to content

Commit

Permalink
lazily evaluate latlngs array for getLatLngs and toGeoJSON functions
Browse files Browse the repository at this point in the history
  • Loading branch information
danwild committed Feb 7, 2017
1 parent 364f865 commit 435ce87
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/js/hexbin/HexbinLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ L.HexbinLayer = (L.Layer ? L.Layer : L.Class).extend({
*/
data: function(data) {
this._data = (null != data)? data : [];
this._latlngs = this._data.map(function(d) { return L.latLng(d[0], d[1]); });
this._redraw();
return this;
},
Expand Down Expand Up @@ -309,15 +308,16 @@ L.HexbinLayer = (L.Layer ? L.Layer : L.Class).extend({
* Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
*/
getLatLngs: function () {
return this._latlngs;
return this._data.map(function(d) { return L.latLng(d[0], d[1]); });
},

/*
* Get path geometry as GeoJSON
*/
toGeoJSON: function () {
var multi = this._latlngs[0].isArray && this._latlngs[0] instanceof Array;
var coords = L.GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0);
var latLngs = this._data.map(function(d) { return L.latLng(d[0], d[1]); });
var multi = latLngs[0].isArray && latLngs[0] instanceof Array;
var coords = L.GeoJSON.latLngsToCoords(latLngs, multi ? 1 : 0);
return L.GeoJSON.getFeature(this, {
type: (multi ? 'Multi' : '') + 'LineString',
coordinates: coords
Expand Down

0 comments on commit 435ce87

Please sign in to comment.