[GIS] Clustering not working on features in OpenLayers

clusteringopenlayers-2openstreetmap

I've built a mapping solution using OpenLayers that works well except I can't get the points to cluster. I've looked at the examples on the site, and I've even implemented those examples in my environment to make sure they work.
When I try to do it with my map, however, all of my points show up, but they're not clustered.
Here is my code where I create the Vector Layer:

var layerVector = new OpenLayers.Layer.Vector("Regions",{
                 strategies: [

                        new OpenLayers.Strategy.Cluster()
                    ]
            });

I add all of the points to an array of features:

var feature_point = new OpenLayers.Feature.Vector(
                            this, {
                                "rName" : rObj.tName
                            }, {
                                'fillColor' : rObj.rColor,
                                'strokeWidth' : borderWidth,
                                'strokeColor' : rObj.rColor,
                                'fillOpacity' : regOp,
                                'pointRadius' : regPercent
                            });
                            fArray.push(feature_point);

Add the features:

layerVector.addFeatures(fArray);

And add the layer to the map:

window[mapName].addLayer(layerVector);

Seems pretty simple, but it seems like I'm missing something.
In the example on the OpenLayers site, they add a styleMap to the layer, but I tried this and it doesn't do anything for me. I'm honestly not sure what it even means:

 var style = new OpenLayers.Style({
                    pointRadius: "${radius}",
                    fillColor: "#ffcc66",
                    fillOpacity: 0.8,
                    strokeColor: "#cc6633",
                    strokeWidth: "${width}",
                    strokeOpacity: 0.8
                }, {
                    context: {
                        width: function(feature) {
                            return (feature.cluster) ? 2 : 1;
                        },
                        radius: function(feature) {
                            var pix = 2;
                            if(feature.cluster) {
                                pix = Math.min(feature.attributes.count, 7) + 2;
                            }
                            return pix;
                        }
                    }
                });

                strategy = new OpenLayers.Strategy.Cluster();

                clusters = new OpenLayers.Layer.Vector("Clusters", {
                    strategies: [strategy],
                    styleMap: new OpenLayers.StyleMap({
                        "default": style,
                        "select": {
                            fillColor: "#8aeeef",
                            strokeColor: "#32a8a9"
                        }
                    })
                });

Any help would be immensely appreciated.

Best Answer

i think you have to add your features to cluster layer that you dont need layerVector.

clusters.addFeatures(features);

and your features should be

features.push(new OpenLayers.Feature.Vector(
                     new OpenLayers.Geometry.Point(px, py), null, null // or your style
                    ));

i hope it helps you...