Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ var feature = require('./feature');
* @typedef {object} geo.pointFeature.clusteringSpec
* @property {number} [radius=10] This is size in pixels that determines how
* close points need to be to each other to be clustered.
* @property {number} [maxZoom=18] Never cluster above this zoom level.
* @property {number} [maxZoom=18] Never cluster above this zoom level. For a
* point feature associated with a layer and a map, this will default to the
* map's zoomRange().max value.
*/

/**
Expand Down Expand Up @@ -138,6 +140,10 @@ var pointFeature = function (arg) {

// set clustering options to default if an options argument wasn't supplied
var opts = m_clustering === true ? {radius: 10} : m_clustering;
if (!opts.maxZoom && this.layer() && this.layer().map()) {
opts = Object.assign({}, opts);
opts.maxZoom = this.layer().map().zoomRange().max;
}

// generate the cluster tree from the raw data
var position = m_this.position();
Expand Down
10 changes: 3 additions & 7 deletions src/util/clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* hierarchically given an array of length scales (zoom levels).
*/

var $ = require('jquery');

/**
* This class manages a group of nearby points that are clustered as a
* single object for display purposes. The class constructor is private
Expand Down Expand Up @@ -106,10 +104,10 @@ ClusterTree.prototype.each = function (func) {
* @returns {geo.geoPosition} The 2-d coordinates of the center.
*/
ClusterTree.prototype.coords = function () {
var i, center = {x: 0, y: 0};
if (this._coord) {
return this._coord;
}
var i, center = {x: 0, y: 0};
// first add up the points at the node
for (i = 0; i < this._points.length; i += 1) {
center.x += this._points[i].x;
Expand All @@ -122,10 +120,11 @@ ClusterTree.prototype.coords = function () {
center.y += this._clusters[i].coords().y * this._clusters[i].count();
}

return {
this._coord = {
x: center.x / this.count(),
y: center.y / this.count()
};
return this._coord;
};

/**
Expand Down Expand Up @@ -202,9 +201,6 @@ C.prototype.addPoint = function (point) {
}
}

if (!parent) {
$.noop();
}
// create a new cluster with these two points
newCluster = new ClusterTree(this, zoom, [closest, point]);
this._clusters[zoom].addObject(newCluster, newCluster.coords());
Expand Down