为什么不在地图上显示地图项 [英] why doesn't show feature on map
问题描述
这是小提琴链接.当类似此代码时,功能不会显示在地图上:
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'
})
})
})
});
但是我将source-featureClusterSource更改为featureVectorSource.it效果很好,但是这次我单击地图上的feature时没有得到Feature.
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'
})
})
})
});
如何使用featureClusterSource在地图上显示地图项?
How do I show feature on map with featureClusterSource?
推荐答案
但是我将源-featureClusterSource更改为featureVectorSource.it效果很好,但是这一次我单击地图上的Feature时没有得到Feature.
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 .
单击相交的要素时,更改forEachFeatureAtPixel方法以将其添加到数组中. 在这里是一个工作的小提琴
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'));
}
}
} ;
这篇关于为什么不在地图上显示地图项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!