[OpenLayers-Dev] Problem with cluster strategy

Ivan Grcic ivan.grcic at geofoto.hr
Wed Nov 26 09:15:10 EST 2008


HI Jerome,

Function Math.min(feature.attributes.count, 7) + 3 was just a sample
in the demo. You can use whatever function you need, just take care to
make it as simple as possible, because it runs trought it for every
feature in cluster.

Cheers, Ivan

On Wed, Nov 26, 2008 at 3:02 PM, Jerome Freyre <jerome.freyre at hispeed.ch> wrote:
>
> Hi everybody,
>
> In my project, I currently use the cluster strategy.
>
> In the example
> http://dev.openlayers.org/sandbox/vector-behavior/examples/strategy-cluster.html
>
> we use a little formula in the context to define the radius :
> Math.min(feature.attributes.count, 7) + 3;
>
> Personnally, I am not sure that it is the right way to define the radius
> size of the cluster.
>
> Normally, the radius should be defined by the "max value of all cluster" and
> the "max radius we autorize"!?
>
> Personally, I add a function in the Cluster.js file which is called before
> the this.layer.addFeatures(clusters) in the cluster function :
>
>    getBiggestClusterValue: function(clusters) {
>
>      if (this.maxVal == -1) {
>
>        if(clusters) {
>          for(var i=0; i<clusters.length; ++i) {
>              if (clusters[i].attributes.count > this.maxVal)
>                this.maxVal =
> clusters[i].attributes[this.AttributeUsedToCount];
>           }
>        }
>        return this.maxVal;
>      }
>      else
>      return this.maxVal;
>    },
>
> And in the context, I use this formula to determine the radius
>
> var maxClustersValue = parseInt(clusterStrategy.maxVal);
> var maxRadius = 18;
> var currentClusterValue = feature.attributes.nbOfSpams;
> var radius = Math.ceil(currentClusterValue * (maxRadius /
> maxClustersValue));
> return Math.max(2,radius);
>
>
> Is my reflexion correct?
>
> Thanks all,
> Jérome
>
>
> --
> View this message in context: http://www.nabble.com/Problem-with-cluster-strategy-tp20701364p20701364.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>



-- 
Ivan Grcic



More information about the Dev mailing list