1

this is fiddle Link.Feature doesn't show on map when it has been like this code :

 var featureVectorLayer = new ol.layer.Vector({
    source: featureClusterSource,
    style: new ol.style.Style({
        fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.2)'
        }),
        stroke: new ol.style.Stroke({
            color: 'blue',
            width: 2
        }),
        image: new ol.style.Circle({
            radius: 7,
            fill: new ol.style.Fill({
                color: '#ffcc33'
            })
        })
    })
});

But i change source - featureClusterSource to featureVectorSource.it works well but in this time i don't get feature when i click feature on map .

 var featureVectorLayer = new ol.layer.Vector({
    source: featureVectorSource,
    style: new ol.style.Style({
        fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.2)'
        }),
        stroke: new ol.style.Stroke({
            color: 'blue',
            width: 2
        }),
        image: new ol.style.Circle({
            radius: 7,
            fill: new ol.style.Fill({
                color: '#ffcc33'
            })
        })
    })
});

How do I show feature on map with featureClusterSource?

1
  • featureClusterSource will work only if holds points. For polygons or linestring will not work. Didnt get your click problem. Changing to featureVectorSource will log the feature in the console when click.
    – pavlos
    Commented Jan 7, 2016 at 8:21

1 Answer 1

3

I have updated your code. Take a look here: http://jsfiddle.net/whwjusob/4/

First try to "beautify" your code with tools like http://jsbeautifier.org/ in order that it becomes better readible.

Your problem was that you tried to insert as source a cluster with a vector but no olCollection.

var featureVectorSource = new ol.source.Vector();
var featureClusterSource = new ol.source.Cluster({

    source: featureVectorSource,
});
var featureVectorLayer = new ol.layer.Vector({
    source: featureClusterSource,
    style: new ol.style.Style({
        fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.2)'
        }),
        stroke: new ol.style.Stroke({
            color: 'blue',
            width: 2
        }),
        image: new ol.style.Circle({
            radius: 7,
            fill: new ol.style.Fill({
                color: '#ffcc33'
            })
        })
    })
});

I changed it to this and now it works:

var features = new ol.Collection();

var featureSource = new ol.source.Vector({
    features: features
});

var featureVectorLayer = new ol.layer.Vector({
    source: featureSource,
    style: new ol.style.Style({
        fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.2)'
        }),
        stroke: new ol.style.Stroke({
            color: 'blue',
            width: 2
        }),
        image: new ol.style.Circle({
            radius: 7,
            fill: new ol.style.Fill({
                color: '#ffcc33'
            })
        })
    })
});

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.