Skip to content

Commit

Permalink
Merge branch 'master' into layer-visible
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey authored Apr 13, 2017
2 parents 3dad631 + ac3de62 commit a3df5ce
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 518 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
6 changes: 6 additions & 0 deletions src/gl/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var gl_pointFeature = function (arg) {
m_pixelWidthUniform = null,
m_aspectUniform = null,
m_dynamicDraw = arg.dynamicDraw === undefined ? false : arg.dynamicDraw,
/* If you are drawing very large points, you will often get better
* performance using a different primitiveShape. The 'sprite' shape uses
* the least memory, but has hardware-specific limitations to its size.
* 'triangle' seems to be fastest on low-powered hardware, but 'square'
* visits fewer fragments. */
m_primitiveShape = 'sprite', // arg can change this, below
s_init = this._init,
s_update = this._update,
Expand Down Expand Up @@ -529,6 +534,7 @@ var gl_pointFeature = function (arg) {
////////////////////////////////////////////////////////////////////////////
this._exit = function () {
m_this.renderer().contextRenderer().removeActor(m_actor);
m_actor = null;
s_exit();
};

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
87 changes: 24 additions & 63 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 @@ -62,10 +62,9 @@ var pointFeature = function (arg) {
m_clusterTree = null;
m_clustering = false;
s_data(m_allData);
m_allData = null;
} else if (!m_clustering && val) {
} else if (val && m_clustering !== val) {
// Generate the cluster tree
m_clustering = true;
m_clustering = val;
m_this._clusterData();
}
return m_this;
Expand Down Expand Up @@ -158,12 +157,14 @@ var pointFeature = function (arg) {
if (val === undefined) {
return m_this.style('position');
} else {
val = util.ensureFunction(val);
var isFunc = util.isFunction(val);
m_this.style('position', function (d, i) {
if (d.__cluster) {
return d;
} else {
} else if (isFunc) {
return val(d, i);
} else {
return val;
}
});
m_this.dataTime().modified();
Expand Down Expand Up @@ -194,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 @@ -218,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 All @@ -232,6 +232,10 @@ var pointFeature = function (arg) {
};
}

// We need to do this before we find corners, since the max radius is
// determined then
m_this._updateRangeTree();

map = m_this.layer().map();
pt = map.gcsToDisplay(p);
// check all corners to make sure we handle rotations
Expand All @@ -251,14 +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_this._updateRangeTree();
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 Expand Up @@ -315,8 +312,10 @@ var pointFeature = function (arg) {
if (data === undefined) {
return s_data();
}
if (m_clustering && !m_ignoreData) {
if (!m_ignoreData) {
m_allData = data;
}
if (m_clustering && !m_ignoreData) {
m_this._clusterData();
} else {
s_data(data);
Expand All @@ -325,55 +324,13 @@ var pointFeature = function (arg) {
return m_this;
};

////////////////////////////////////////////////////////////////////////////
/**
* Returns the bounding box for a given datum in screen coordinates as an
* object: ::
*
* {
* min: {
* x: value,
* y: value
* },
* max: {
* x: value,
* y: value
* }
* }
*
* @returns {object}
*/
////////////////////////////////////////////////////////////////////////////
this._boundingBox = function (d) {
var pt, radius;

// get the position in geo coordinates
pt = m_this.position()(d);

// convert to screen coordinates
pt = m_this.layer().map().gcsToDisplay(pt);

// get the radius of the points (should we add stroke width?)
radius = m_this.style().radius(d);

return {
min: {
x: pt.x - radius,
y: pt.y - radius
},
max: {
x: pt.x + radius,
y: pt.y + radius
}
};
};

////////////////////////////////////////////////////////////////////////////
/**
* Initialize
*/
////////////////////////////////////////////////////////////////////////////
this._init = function (arg) {
arg = arg || {};
s_init.call(m_this, arg);

var defaultStyle = $.extend(
Expand All @@ -399,6 +356,9 @@ var pointFeature = function (arg) {
}

m_this.style(defaultStyle);
if (defaultStyle.position) {
m_this.position(defaultStyle.position);
}
m_this.dataTime().modified();

// bind to the zoom handler for point clustering
Expand All @@ -425,9 +385,10 @@ var pointFeature = function (arg) {
* @param {geo.pointFeature.spec} spec The object specification
* @returns {geo.pointFeature|null}
*/
pointFeature.create = function (layer, renderer, spec) {
pointFeature.create = function (layer, spec) {
'use strict';

spec = spec || {};
spec.type = 'point';
return feature.create(layer, spec);
};
Expand Down
51 changes: 0 additions & 51 deletions src/util/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,57 +361,6 @@
*/
radiusEarth: 6378137,

/**
* Linearly combine two "coordinate-like" objects in a uniform way.
* Coordinate like objects have ``x``, ``y``, and optionally a ``z``
* key. The first object is mutated.
*
* a <= ca * a + cb * b
*
* @param {number} ca
* @param {object} a
* @param {number} [a.x=0]
* @param {number} [a.y=0]
* @param {number} [a.z=0]
* @param {number} cb
* @param {object} b
* @param {number} [b.x=0]
* @param {number} [b.y=0]
* @param {number} [b.z=0]
* @returns {object} ca * a + cb * b
*/
lincomb: function (ca, a, cb, b) {
a.x = ca * (a.x || 0) + cb * (b.x || 0);
a.y = ca * (a.y || 0) + cb * (b.y || 0);
a.z = ca * (a.x || 0) + cb * (b.x || 0);
return a;
},

/**
* Element-wise product of two coordinate-like object. Mutates
* the first object. Note the default values for ``b``, which
* are intended to used as a anisotropic scaling factors.
*
* a <= a * b^pow
*
* @param {object} a
* @param {number} [a.x=0]
* @param {number} [a.y=0]
* @param {number} [a.z=0]
* @param {object} b
* @param {number} [b.x=1]
* @param {number} [b.y=1]
* @param {number} [b.z=1]
* @param {number} [pow=1]
* @returns {object} a * b^pow
*/
scale: function (a, b, pow) {
a.x = (a.x || 0) * Math.pow(b.x || 1, pow);
a.y = (a.y || 0) * Math.pow(b.y || 1, pow);
a.z = (a.z || 0) * Math.pow(b.z || 1, pow);
return a;
},

/**
* Compare two arrays and return if their contents are equal.
* @param {array} a1 first array to compare
Expand Down
Loading

0 comments on commit a3df5ce

Please sign in to comment.