Skip to content

Commit c16ea3d

Browse files
authored
Merge pull request #1381 from OpenGeoscience/speed-up-cluster-transition
perf: Speed up cluster zoom transition
2 parents 55abf07 + 5c5b020 commit c16ea3d

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/pointFeature.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,26 @@ var pointFeature = function (arg) {
185185
// store the current zoom level privately
186186
m_lastZoom = z;
187187

188-
// get the raw data elements for the points at the current level
189-
var data = m_clusterTree.points(z).map(function (d) {
190-
return m_allData[d.index];
191-
});
188+
const points = m_clusterTree.points(z);
189+
const clusters = m_clusterTree.clusters(z);
190+
const data = new Array(points.length + clusters.length);
191+
for (let pidx = 0; pidx < points.length; pidx += 1) {
192+
data[pidx] = m_allData[points[pidx].index];
193+
}
192194

193195
// append the clusters at the current level
194-
m_clusterTree.clusters(z).forEach(function (d) {
196+
for (let cidx = 0, didx = points.length; cidx < clusters.length; cidx += 1, didx += 1) {
197+
const d = clusters[cidx];
195198
// mark the datum as a cluster for accessor methods
196199
d.__cluster = true;
197200

198201
// store all of the data objects for each point in the cluster as __data
199-
d.__data = [];
200-
d.obj.each(function (e) {
201-
d.__data.push(m_allData[e.index]);
202-
});
203-
data.push(d);
204-
});
202+
d.__data = new Array(d.obj.length);
203+
for (let idx = 0; idx < d.obj.length; idx += 1) {
204+
d.__data[idx] = m_allData[d.obj[idx].index];
205+
}
206+
data[didx] = d;
207+
}
205208

206209
// prevent recomputing the clustering and set the new data array
207210
m_ignoreData = true;

src/util/distanceGrid.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5555
* @copyright 2012, David Leaver
5656
*/
5757

58-
var $ = require('jquery');
5958
var L = {};
6059
L.Util = {
6160
// return unique ID of an object
@@ -181,7 +180,7 @@ DistanceGrid.prototype = {
181180

182181
/* return the point coordinates contained in the structure */
183182
contents: function () {
184-
return $.map(this._objectPoint, function (val) { return val; });
183+
return Object.values(this._objectPoint);
185184
},
186185

187186
_getCoord: function (x) {

0 commit comments

Comments
 (0)