[OpenLayers-Users] Cluster Strategy Based on Attribute

Matt Kenny matthewkenny at gmail.com
Tue Jun 2 02:30:01 EDT 2009


Thanks to both of you for the suggestions. It turned out that simply
separating the TYPE:COMPANY features to their own layer, and applying a
cluster strategy on it was the easiest solution.

I had originally put all features on the same vector layer so that they
could all be selected at the same time. By upgrading to OpenLayers 2.8, i
was able to separate the layers, while passing an array of all layers to my
select feature control.

Thanks again!
Matt

On Mon, Jun 1, 2009 at 4:17 PM, Eric Lemoine <eric.lemoine at camptocamp.com>wrote:

> 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
>



-- 
m a t t h e w k e n n y
http://www.mkgeomatics.com
Sent from Santa Paula, CA, United States
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090601/998ce533/attachment.html


More information about the Users mailing list