[GIS] Show different marker for cluster and icon for single vector features in OpenLayers

clusteringgeojsonopenlayers-2

I have a vector layer which is geoJSON file containing school points and their attributes,to visualize this i defined cluster and show circle which size is based on the number of features it contains. Whenever the zoom level reaches individual schools, i need to display symbol of school.

In style, i can define the size of cluster using the pointRadius property, and show icon using the externalGraphic property. i need to use both at once i.e use rendering as circle if cluster is more than one and render as icon in individual feautures.

How can i do this?

Best Answer

You can used cluster icon in cluster and other icon in single feature.

var styles = new OpenLayers.Style({
    externalGraphic: "${symbol}"
},
{
    context:{
        symbol: function(feature){
            if (feature.cluster){
                return 'icon/Cluster_icon.png';
            }
            else{
                return 'icon/Single_icon.png';
            }
        }
    }
});
Related Question