Skip to content

Commit

Permalink
Merge pull request #685 from OpenGeoscience/replace-wigglemaps
Browse files Browse the repository at this point in the history
Replace vendored wigglemaps with kdbush
  • Loading branch information
jbeezley authored Mar 30, 2017
2 parents cf4ca12 + d4c70a2 commit 21d8fb9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 416 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"kdbush": "^1.0.1",
"mousetrap": "^1.6.0",
"nib": "^1.1.2",
"node-resemble": "^1.1.3",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
* earcut
* @copyright 2016, Mapbox
* @license ISC
*
* kdbush
* @copyright 2017, Vladimir Agafonkin
* @license ISC
*/

var $ = require('jquery');
Expand Down
17 changes: 5 additions & 12 deletions src/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var pointFeature = function (arg) {
var ClusterGroup = require('./util/clustering');
var geo_event = require('./event');
var util = require('./util');
var wigglemaps = require('./util/wigglemaps');
var kdbush = require('kdbush');

////////////////////////////////////////////////////////////////////////////
/**
Expand Down Expand Up @@ -195,18 +195,17 @@ var pointFeature = function (arg) {
// create an array of positions in geo coordinates
pts = m_this.data().map(function (d, i) {
var pt = position(d);
pt.idx = i;

// store the maximum point radius
m_maxRadius = Math.max(
m_maxRadius,
radius(d, i) + (stroke(d, i) ? strokeWidth(d, i) : 0)
);

return pt;
return [pt.x, pt.y];
});

m_rangeTree = new wigglemaps.RangeTree(pts);
m_rangeTree = kdbush(pts);
m_rangeTreeTime.modified();
};

Expand All @@ -219,7 +218,7 @@ var pointFeature = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this.pointSearch = function (p) {
var min, max, data, idx = [], box, found = [], ifound = [], map, pt,
var min, max, data, idx = [], found = [], ifound = [], map, pt,
corners,
stroke = m_this.style.get('stroke'),
strokeWidth = m_this.style.get('strokeWidth'),
Expand Down Expand Up @@ -256,13 +255,7 @@ var pointFeature = function (arg) {
};

// Find points inside the bounding box
box = new wigglemaps.Box(
wigglemaps.vect(min.x, min.y),
wigglemaps.vect(max.x, max.y)
);
m_rangeTree.search(box).forEach(function (q) {
idx.push(q.idx);
});
idx = m_rangeTree.range(min.x, min.y, max.x, max.y);

// Filter by circular region
idx.forEach(function (i) {
Expand Down
Loading

0 comments on commit 21d8fb9

Please sign in to comment.