Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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) {
    if(feature.cluster)
    {
        feature.externalGraphic="/img/clusterimage.png";
    }
    return feature.externalGraphic;
        }...

I`ve also tried other constructs like

feature.cluster[0].attributes['icon']

or

feature.externalGraphic=feature.cluster[0].attributes['icon']

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

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
works for KML layers as well. U ROK! –  tony gil Mar 8 '13 at 21:53
add comment

Your Answer

 
discard

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.