[OpenLayers-Users] Cluster Strategy Based on Attribute

Eric Lemoine eric.lemoine at camptocamp.com
Mon Jun 1 19:17:37 EDT 2009


On Thursday, May 28, 2009, Matt Kenny <matthewkenny at gmail.com> wrote:
> Hello,
>
> I've got a quick question that I'm hoping someone knows the answer to.
>
> I've got a single vector layer containing both point and line features.
>
> All features have a 'TYPE' attribute. Points are either 'TYPE:COMPANY' or 'TYPE:AIRPORT', and lines are always 'TYPE:ROUTE'.
>
> I'm wondering if it is possible to create a cluster strategy that only clusters features in my vector layer that are of an attribute, 'TYPE:COMPANY'?

Registering a beforefeaturesadded listener and have this listener
filter out features that aren't of type TYPE:COMPANY should work. The
listener would look like:

function filter(evt) {
    var features = [];
    for(var i=0, len=evt.features.length; i<len; i++) {
        if(evt.features[i].attributes.type == "TYPE:COMPANY") {
            features.push(evt.features[i]);
        }
    }
    evt.features = features; // with that the cluster strategy will
see a different set of features
}

The thing is you need to register the listener *before* the cluster
strategy is activated. For that either (a) set autoActivate to false
in the strategy config, and activate the strategy yourself after the
registration of your beforefeaturesadded listener, (b) deactivate the
strategy, register your listener, and activate the strategy again. (a)
is more elegant I think.

Cheers,




>
> Thanks,
> Matt
> --
> m a t t h e w k e n n y
> http://www.mkgeomatics.com
> Sent from Tempe, AZ, United States
>

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Users mailing list