[OpenLayers-Dev] Cluster strategy activation

strk strk at keybit.net
Thu May 20 18:04:29 EDT 2010


On Thu, May 20, 2010 at 03:46:59PM -0600, Tim Schaub wrote:
> strk wrote:
> > On Thu, May 20, 2010 at 09:54:50AM +0200, strk wrote:
> >> Hi there,
> >>
> >> I noticed that the Cluster strategy activation does nothing 
> >> clustering only happens when you add features _after_ the control is
> >> activated.
> >>
> >> Sound reasonable, but the strategy can't be activated until the layer
> >> is placed on the map, so this makes it impossible to have a workflow like
> >> this:
> >>
> >> 	1. Create layer with cluster strategy
> >> 	2. Add features to layer
> >> 	3. Add layer to the map (triggers activation)
> >>
> >> Does it make sense for the Cluster.activate to instead perform
> >> the initial clustering when the layer already contains feature ?
> > 
> 
> So what does `strategy.activate(); strategy.deactivate(); 
> strategy.activate()` do?

activate [1] currently only registers handlers for "beforefeaturesadded"
and "moveend".

The first handler performs the caching and initial clustering [2],
the second performs clustering [3].

Since features are already in the layer at time of activation, there
will be no "beforefeaturesadded" fired in the workflow above and thus
no caching. .cluster(), invoked on "moveend" will then have nothing
to cluster (cache is empty).

[1] http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Strategy/Cluster.js#L79
[2] http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Strategy/Cluster.js#L123
[3] http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Strategy/Cluster.js#L150

> If activate clusters, then does deactivate uncluster?

Good question. I haven't touched deactivate.
It currently doesn't uncluster but only drops the
events and clears the cache.

> I haven't checked out the attached diff, but these are immediate 
> questions that come to mind.  Drop a link to a ticket if you've opened one.

http://trac.openlayers.org/ticket/2644

--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html



More information about the Dev mailing list