[OpenLayers-Users] recenter on a vector layer with Cluster strategy on

Christopher Schmidt crschmidt at metacarta.com
Wed Dec 10 13:03:09 EST 2008


On Wed, Dec 10, 2008 at 06:39:16PM +0100, Didrik Pinte wrote:
> Hi,
> 
> I try to have a vector layer with a Cluster and Fixed strategy
> automatically recenter after the feature are added to the layer.
> 
> It works fine with the Fixed strategy only but with the Cluster, it is
> just wrong ...
> 
> Does anyone of you knows if this bug could be the source of the problem
> #1820 ?
> 
> I am recentering using a layer.getDataExtent(). I suppose this is the
> culprit.

getDataExtent only works against the features currently in the layer --
it isn'at aware of the 'subfeatures' inside the clusters. 

I use this instead:

    var e = m.layers[0].features[0].geometry.getBounds();
    for (var i = 0; i < m.layers[0].features.length; i++) {
        for (var j = 0; j< m.layers[0].features[i].cluster.length; j++) {
            e.extend(m.layers[0].features[i].cluster[j].geometry.getBounds());
        }
    }

This creates an extent that takes into account all the features.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list