问题
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:
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 .
When clicked on features which are intersecting, change forEachFeatureAtPixel method to add them to an array. Here's a working fiddle
map.on("singleclick", singleClickCB);
function singleClickCB(event) {
var features = [];
map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
features.push(feature);
});
if (features) {
var i;
for (i = 0; i < features.length; ++i) {
alert(features[i].get('title'));
}
}
} ;
来源:https://stackoverflow.com/questions/34643984/why-doesnt-show-feature-on-map