4
4
5
5
/**
6
6
* @name DataLayerClusterer for Google Maps v3 (Connum's Fork)
7
- * @version version 1.0.0
7
+ * @version version 1.0.1
8
8
* @author Nelson Antunes
9
9
* @author Jesús R Peinado
10
10
* @author Constantin Groß
46
46
* 'minimumClusterSize': (number) The minimum number of features to be in a
47
47
* cluster before the features are hidden and a count
48
48
* 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.
49
54
* 'setProperty': (boolean) when true, the features will not be hidden, but
50
55
* the property 'in_cluster' (or a configurable property name defined
51
56
* in the constant DataLayerClusterer.CLUSTER_PROPERTY_NAME)
@@ -83,6 +88,7 @@ function DataLayerClusterer(optOptions) {
83
88
this . map = options . map || null ;
84
89
this . gridSize_ = options . gridSize || 60 ;
85
90
this . minClusterSize_ = options . minimumClusterSize || 2 ;
91
+ this . minPolySize_ = options . minimumPolySize || 50 ;
86
92
this . setProperty_ = options . setProperty || false ;
87
93
this . maxZoom_ = options . maxZoom || null ;
88
94
this . className_ = options . className || 'cluster' ;
@@ -521,6 +527,7 @@ DataLayerClusterer.prototype.addToClosestCluster_ = function(feature) {
521
527
522
528
if ( isVisible ) {
523
529
var csize = this . clusters_ . length ;
530
+
524
531
for ( var i = 0 ; i !== csize ; ++ i ) {
525
532
var center = this . clusters_ [ i ] . getCenter ( ) ;
526
533
@@ -688,6 +695,8 @@ function FeatureCluster(featureClusterer) {
688
695
689
696
this . clusterIcon_ = new FeatureClusterIcon ( this , featureClusterer . getStyles ( ) ,
690
697
featureClusterer . getGridSize ( ) , this . classId ) ;
698
+
699
+ this . forced_ = false ;
691
700
}
692
701
693
702
/**
@@ -741,7 +750,26 @@ FeatureCluster.prototype.addFeature = function(feature) {
741
750
this . features_ . push ( feature ) ;
742
751
743
752
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_ ) {
745
773
// Min cluster size not reached so show the feature.
746
774
if ( this . featureClusterer_ . setProperty_ ) {
747
775
feature . setProperty ( DataLayerClusterer . CLUSTER_PROPERTY_NAME , false ) ;
@@ -750,7 +778,7 @@ FeatureCluster.prototype.addFeature = function(feature) {
750
778
}
751
779
}
752
780
753
- if ( len === this . minClusterSize_ ) {
781
+ if ( len === this . minClusterSize_ || this . forced_ ) {
754
782
// Hide the features that were showing.
755
783
for ( var i = 0 ; i < len ; i ++ ) {
756
784
if ( this . featureClusterer_ . setProperty_ ) {
@@ -761,7 +789,7 @@ FeatureCluster.prototype.addFeature = function(feature) {
761
789
}
762
790
}
763
791
764
- if ( len >= this . minClusterSize_ ) {
792
+ if ( len >= this . minClusterSize_ || this . forced_ ) {
765
793
for ( var j = 0 ; j < len ; j ++ ) {
766
794
if ( this . featureClusterer_ . setProperty_ ) {
767
795
this . features_ [ j ] . setProperty ( DataLayerClusterer . CLUSTER_PROPERTY_NAME , true ) ;
@@ -887,7 +915,7 @@ FeatureCluster.prototype.updateIcon = function() {
887
915
return ;
888
916
}
889
917
890
- if ( this . features_ . length < this . minClusterSize_ ) {
918
+ if ( this . features_ . length < this . minClusterSize_ && ! this . forced_ ) {
891
919
// Min cluster size not yet reached.
892
920
this . clusterIcon_ . hide ( ) ;
893
921
return ;
0 commit comments