I`m using OpenLayers to show POIs on a map. These POIs are loaded from a textfile and I`m using a Vector Layer to get it onto the map - works great. Now I want to use the cluster strategy to have points clustered to one when the user is zooming out and the points get to close (see this great tutorial). Works, too. But only for a static image. I want to get the image that is defined in the textfile, but I`m not able to get this. The text file is in the normal format for OpenLayers.Format.Text. The image is defined in the column named icon and as I told, it is shown when not using clustering. According to the Source code of OpenLayers.Format.Text.js the value of the column icon should be stored in the externalGraphic-property. But this doesn`t seem to be the case. Here`s my code to try to get the Image:

var clusterStyle = new OpenLayers.Style({
    externalGraphic: "${icon}",
    graphicWidth: 24,
graphicHeight: 24,
    description: "${description}"
}, {
    context: {
        icon: function (feature) {
    return feature.externalGraphic;

I`ve also tried other constructs like




to get the icon, but neither worked. So where is the icon stored, how to access it? Is there a qay to iterate the attributes-object? I`m using OpenLayers 2.12

1 Answer 1


Well, I found the solution myself - it was not a mistake in the code lines I`ve posted. The problem were silly parameters passed to the strategy-constructor: I used the following code to create the cluster strategy:

var clusterStrategy = new OpenLayers.Strategy.Cluster({ distance: 15, threshold: 1 });

The problem was to set the threshold to 1. That erased (or overlapped, whatever) the icon. So I`ve set the threshold to 2 and then it worked as described in the amazing tutorial from the openflight-project that I`ve posted in the question.

  • works for KML layers as well. U ROK!
    – tony gil
    Commented Mar 8, 2013 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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