[OpenLayers-Users] cluster strategy filtering
Didrik Pinte
lists at dipole-consulting.com
Wed Nov 5 07:37:38 EST 2008
On Wed, 2008-11-05 at 11:25 +0100, Didrik Pinte wrote:
> Hi,
>
> How is it possible to a Filter.Comparison on clustered layer based on
> the feature attributes ? Looking through the code, it seems impossible
> because the cluster strategy hiddes the feature attributes by the
> cluster attribute (the count property). Would there be an easy and clean
> solution to this problem ?
>
> Didrik
Here is a not really elegant solution.
When a cluster counts more than one feature, the only attribute
interesting is count. When the cluster counts only one attribute, we
could be interested by the feature attributes. Thus, when the cluster is
created, I just copy the feature attributes to the cluster. There is
only one line of code added (extending cluster.attributes using
feature.attributes)
OpenLayers/Strategy/Cluster.js - line 250
--------------------------------------------------------------------------------
createCluster: function(feature) {
var center = feature.geometry.getBounds().getCenterLonLat();
var cluster = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(center.lon, center.lat),
{count: 1}
);
OpenLayers.Util.extend(cluster.attributes, feature.attributes);
cluster.cluster = [feature];
return cluster;
},
--------------------------------------------------------------------------------
The only problem could be when the feature already has a count
attribute ...
Didrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081105/83fcfee8/attachment.bin
More information about the Users
mailing list