[OpenLayers-Users] Need help for Cluster strategy using externalGraphic

Xavier Mamano (jorix) xavier.mamano at gmail.com
Mon Mar 4 10:30:53 PST 2013


Hi,

Yes, it costs a bit to understand this issue, but is not a bug.

Suppose loading two points not far and zoom is 0. Both CenteredCluster and
Cluster act in the same way, calculate a single cluster and the map will
focus on this point. But here's the difference,  Cluster chooses as
coordenadeas the first point load, but CenteredCluster choose the center of
the segment that joins the two points.

Try use this code:


function myGetDataExtent(layer) {
    var _maxExtent = null,
        features = layer.features;
    if (features && features.length > 0) {
        var extendBounds = function(geometry) {
            if (geometry) {
                if (_maxExtent === null) {
                    _maxExtent = new OpenLayers.Bounds();
                }
                _maxExtent.extend(geometry.getBounds());
            }
        };
        for(var i = 0, len = features.length; i < len; i++) {
            var feature = features[i],
                cluster = feature.cluster;
            if (cluster) {
                for(var ii = 0, iilen = cluster.length; ii < iilen; ii++) {
                    extendBounds(cluster[ii].geometry);
                }
            } else {
                extendBounds(feature.geometry);
            }
        }
    }
    return _maxExtent;
};

and at "loadend" call:

  map.zoomToExtent(myGetDataExtent(kml_layer));

NOTE: If you use today's version of CenteredCluster.js this change is not
necessary.






--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Need-help-for-Cluster-strategy-using-externalGraphic-tp5037985p5038337.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list