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;
|
var feature, clustered, cluster;
|
||||||
for(var i=0; i<this.features.length; ++i) {
|
for(var i=0; i<this.features.length; ++i) {
|
||||||
feature = this.features[i];
|
feature = this.features[i];
|
||||||
clustered = false;
|
if(feature.geometry) {
|
||||||
for(var j=0; j<clusters.length; ++j) {
|
clustered = false;
|
||||||
cluster = clusters[j];
|
for(var j=0; j<clusters.length; ++j) {
|
||||||
if(this.shouldCluster(cluster, feature)) {
|
cluster = clusters[j];
|
||||||
this.addToCluster(cluster, feature);
|
if(this.shouldCluster(cluster, feature)) {
|
||||||
clustered = true;
|
this.addToCluster(cluster, feature);
|
||||||
break;
|
clustered = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!clustered) {
|
||||||
|
clusters.push(this.createCluster(this.features[i]));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(!clustered) {
|
|
||||||
clusters.push(this.createCluster(this.features[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.layer.destroyFeatures();
|
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);
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
layer.addFeatures(features);
|
layer.addFeatures(features);
|
||||||
|
|
||||||
@@ -63,7 +66,7 @@
|
|||||||
// threshold: 4 * 20 = 80 units
|
// threshold: 4 * 20 = 80 units
|
||||||
// one cluster
|
// one cluster
|
||||||
t.eq(layer.features.length, 1, "[4] layer has 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
|
// resolution 2
|
||||||
// threshold: 2 * 20 = 40 units
|
// threshold: 2 * 20 = 40 units
|
||||||
|
|||||||
Reference in New Issue
Block a user