Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Add the features:


And add the layer to the map:


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.

share|improve this question
Just as a preliminary diagnostic: are you getting any JS errors in the browser console? – yalestar Jan 28 '13 at 16:53
no, nothing shows in the console – Munzilla Jan 30 '13 at 16:30
Just a thought: add layer to map; then add features to layer – user1702401 Aug 14 '13 at 10:02

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


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...

share|improve this answer
Well I think you're referencing the bottom bit of code in terms of the top bit. That last bottom bit of code is the example code given by OpenLayers. – Munzilla Jan 28 '13 at 20:00
did you try what i have mentioned? – Aragon Jan 29 '13 at 8:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.