Hi Jerome and Heidtmare, I tried to add all vectorfeatures at once before because I saw that´s the case in the example-site as well. But it didn´t help. So I performed a little bit of "trial and error" and after changing my code to adding-all-features-at-once AND erasing the codeline clusterStrategy.activate() it works. If I don´t erase it I get the error " 'this.layer.map' is null or no object".
Thx to all of you Max Stephan Jerome Freyre wrote: > > Heidtmare is right and faster than me.... :D > > Have a look to http://openlayers.org/dev/examples/strategy-cluster.html to > modify the size of cluster depending of the number of feature they > represent > > > > Here is a script that is working. And think that you can > > PS: Sorry for the "double post" I push the wrong button :) > > var map, wfs; > > var styleMap1 = new OpenLayers.StyleMap({ > "default": new OpenLayers.Style( > { > fillColor: "#0000FF", > strokeColor: "#0000FF", > pointRadius: 6 > } > ) > }); > > function init(){ > map = new OpenLayers.Map('map'); > var wms = new OpenLayers.Layer.WMS( > "OpenLayers WMS", > > "http://labs.metacarta.com/wms/vmap0?", > {layers: 'basic'} > ); > map.addLayer(wms); > map.zoomToMaxExtent(); > > > var strat = new > OpenLayers.Strategy.Cluster({distance:20}); > > vectorLayer = new OpenLayers.Layer.Vector("Vektorlayer",{ > > strategies: [ > > strat > > ], > > styleMap: styleMap1, maxResolution: 19}); > > strat.activate(); > > map.addLayers([vectorLayer]); > > /** > * Generate datas // Simulate your data access > */ > var dx = 3; > var dy = 3; > var px, py; > featuresToBeClustered = []; > for(var x=-45; x<=45; x+=dx) { > for(var y=-22.5; y<=22.5; y+=dy) { > px = x + (2 * dx * (Math.random() - 0.5)); > py = y + (2 * dy * (Math.random() - 0.5)); > featuresToBeClustered.push({ > 'lonlat':new > OpenLayers.LonLat(px,py), > 'id':px+' '+py > }); > } > } > /** > * Populate the array of feature > */ > var arrayOfFeatures = []; > for (var i=0; i<featuresToBeClustered.length; i++){ > arrayOfFeatures.push(generateFeature(vectorLayer, > featuresToBeClustered[i].lonlat, featuresToBeClustered[i].id)); > } > > /** > * Add all features in one time > */ > vectorLayer.addFeatures(arrayOfFeatures); > > > > map.setCenter(new OpenLayers.LonLat(0, 0), 2); > > } > /** > * Modification of you function > */ > function generateFeature(layer, lonlat, mestId){ > var geometryObjekt = new > OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat); > var vectorObjekt = new > OpenLayers.Feature.Vector(geometryObjekt); > vectorObjekt.attributes.mest = mestId; > return vectorObjekt; > } > > > > > Heidtmare wrote: >> >> i believe you need to add all your features at once, >> so instead of looping the layer.addFeatures() call >> you need to build all your features into an array and then call >> layer.addFeatures() once. >> >> >> > > -- View this message in context: http://n2.nabble.com/Cluster-strategy-not-working-tp3533851p3552202.html Sent from the OpenLayers Users mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users