Skip to content

Commit d826cf9

Browse files
author
Constantin Groß
committed
new option minimumPolySize, updated package.json, increased version number to 1.0.1
1 parent 2590a17 commit d826cf9

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "data-layer-clusterer",
3-
"version": "0.7.3",
3+
"version": "1.0.1",
44
"homepage": "https://github.com/Connum/data-layer-clusterer",
55
"authors": [
66
"Nelson Antunes"

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "data-layer-clusterer",
3-
"version": "1.0.0",
4-
"homepage": "https://github.com/nantunes/data-layer-clusterer",
3+
"version": "1.0.1",
4+
"homepage": "https://github.com/Connum/data-layer-clusterer",
55
"authors": [
66
"Nelson Antunes"
77
],
8-
"description": "The library creates and manages per-zoom-level clusters large amounts of data layer features. Google API v3.",
8+
"description": "The library creates and manages per-zoom-level clusters for large amounts of data layer features. Google API v3.",
99
"main": "src/datalayerclusterer.js",
1010
"keywords": [
1111
"google",
1212
"maps",
1313
"data",
1414
"layer",
15+
"features",
1516
"marker",
1617
"cluster",
1718
"clusterer",

src/datalayerclusterer.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* @name DataLayerClusterer for Google Maps v3 (Connum's Fork)
7-
* @version version 1.0.0
7+
* @version version 1.0.1
88
* @author Nelson Antunes
99
* @author Jesús R Peinado
1010
* @author Constantin Groß
@@ -46,6 +46,11 @@
4646
* 'minimumClusterSize': (number) The minimum number of features to be in a
4747
* cluster before the features are hidden and a count
4848
* is shown.
49+
* 'minimumPolySize': (number) The minimum width or height of the bounding box
50+
* of a feature (other than type 'Point') in pixels before
51+
* it is forced into a cluster, even if the cluster ends up
52+
* containing only this one feature. 0 or false to disable
53+
* this functionality.
4954
* 'setProperty': (boolean) when true, the features will not be hidden, but
5055
* the property 'in_cluster' (or a configurable property name defined
5156
* in the constant DataLayerClusterer.CLUSTER_PROPERTY_NAME)
@@ -83,6 +88,7 @@ function DataLayerClusterer(optOptions) {
8388
this.map = options.map || null;
8489
this.gridSize_ = options.gridSize || 60;
8590
this.minClusterSize_ = options.minimumClusterSize || 2;
91+
this.minPolySize_ = options.minimumPolySize || 50;
8692
this.setProperty_ = options.setProperty || false;
8793
this.maxZoom_ = options.maxZoom || null;
8894
this.className_ = options.className || 'cluster';
@@ -521,6 +527,7 @@ DataLayerClusterer.prototype.addToClosestCluster_ = function(feature) {
521527

522528
if (isVisible) {
523529
var csize = this.clusters_.length;
530+
524531
for (var i = 0; i !== csize; ++i) {
525532
var center = this.clusters_[i].getCenter();
526533

@@ -688,6 +695,8 @@ function FeatureCluster(featureClusterer) {
688695

689696
this.clusterIcon_ = new FeatureClusterIcon(this, featureClusterer.getStyles(),
690697
featureClusterer.getGridSize(), this.classId);
698+
699+
this.forced_ = false;
691700
}
692701

693702
/**
@@ -741,7 +750,26 @@ FeatureCluster.prototype.addFeature = function(feature) {
741750
this.features_.push(feature);
742751

743752
var len = this.features_.length;
744-
if (len < this.minClusterSize_) {
753+
754+
if (len == 1 && !!this.featureClusterer_.minPolySize_ && feature.getGeometry().getType() != 'Point') {
755+
var polyMinSize = this.featureClusterer_.minPolySize_;
756+
var bounds = this.featureClusterer_.featureBounds_(feature);
757+
var SW = bounds.getSouthWest();
758+
var NE = bounds.getNorthEast();
759+
var proj = this.map_.getProjection();
760+
var swPx = proj.fromLatLngToPoint(SW);
761+
var nePx = proj.fromLatLngToPoint(NE);
762+
var pixelWidth = Math.round(Math.abs((nePx.x - swPx.x)* Math.pow(2, this.map_.getZoom())));
763+
var pixelHeight = Math.round(Math.abs((swPx.y - nePx.y)* Math.pow(2, this.map_.getZoom())));
764+
765+
if (pixelWidth < polyMinSize && pixelHeight < polyMinSize) {
766+
this.forced_ = true;
767+
} else {
768+
this.forced_ = false;
769+
}
770+
}
771+
772+
if (len < this.minClusterSize_ && !this.forced_) {
745773
// Min cluster size not reached so show the feature.
746774
if (this.featureClusterer_.setProperty_) {
747775
feature.setProperty(DataLayerClusterer.CLUSTER_PROPERTY_NAME, false);
@@ -750,7 +778,7 @@ FeatureCluster.prototype.addFeature = function(feature) {
750778
}
751779
}
752780

753-
if (len === this.minClusterSize_) {
781+
if (len === this.minClusterSize_ || this.forced_) {
754782
// Hide the features that were showing.
755783
for (var i = 0; i < len; i++) {
756784
if (this.featureClusterer_.setProperty_) {
@@ -761,7 +789,7 @@ FeatureCluster.prototype.addFeature = function(feature) {
761789
}
762790
}
763791

764-
if (len >= this.minClusterSize_) {
792+
if (len >= this.minClusterSize_ || this.forced_) {
765793
for (var j = 0; j < len; j++) {
766794
if (this.featureClusterer_.setProperty_) {
767795
this.features_[j].setProperty(DataLayerClusterer.CLUSTER_PROPERTY_NAME, true);
@@ -887,7 +915,7 @@ FeatureCluster.prototype.updateIcon = function() {
887915
return;
888916
}
889917

890-
if (this.features_.length < this.minClusterSize_) {
918+
if (this.features_.length < this.minClusterSize_ && !this.forced_) {
891919
// Min cluster size not yet reached.
892920
this.clusterIcon_.hide();
893921
return;

0 commit comments

Comments
 (0)