Adding a check to make sure features have a geometry before entering the cluster algorithm. r=crschmidt (closes #1816)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8316 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -147,17 +147,19 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
var feature, clustered, cluster;
|
||||
for(var i=0; i<this.features.length; ++i) {
|
||||
feature = this.features[i];
|
||||
clustered = false;
|
||||
for(var j=0; j<clusters.length; ++j) {
|
||||
cluster = clusters[j];
|
||||
if(this.shouldCluster(cluster, feature)) {
|
||||
this.addToCluster(cluster, feature);
|
||||
clustered = true;
|
||||
break;
|
||||
if(feature.geometry) {
|
||||
clustered = false;
|
||||
for(var j=0; j<clusters.length; ++j) {
|
||||
cluster = clusters[j];
|
||||
if(this.shouldCluster(cluster, feature)) {
|
||||
this.addToCluster(cluster, feature);
|
||||
clustered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!clustered) {
|
||||
clusters.push(this.createCluster(this.features[i]));
|
||||
}
|
||||
}
|
||||
if(!clustered) {
|
||||
clusters.push(this.createCluster(this.features[i]));
|
||||
}
|
||||
}
|
||||
this.layer.destroyFeatures();
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
);
|
||||
}
|
||||
|
||||
// add one additional feature, with no geometry - just to confirm it doesn't break things
|
||||
features.push(new OpenLayers.Feature.Vector());
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
layer.addFeatures(features);
|
||||
|
||||
@@ -63,7 +66,7 @@
|
||||
// threshold: 4 * 20 = 80 units
|
||||
// one cluster
|
||||
t.eq(layer.features.length, 1, "[4] layer has one cluster");
|
||||
t.ok(featuresEq(layer.features[0].cluster, features), "[4] cluster includes all features");
|
||||
t.ok(featuresEq(layer.features[0].cluster, features.slice(0, 80)), "[4] cluster includes all features with geometries");
|
||||
|
||||
// resolution 2
|
||||
// threshold: 2 * 20 = 40 units
|
||||
|
||||
Reference in New Issue
Block a user