【发布时间】:2016-01-06 22:22:23
【问题描述】:
这是小提琴Link。当它像这样的代码时,地图上不会显示地图:
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'
})
})
})
});
但我将源 - featureClusterSource 更改为 featureVectorSource。它运行良好,但此时我在地图上单击功能时没有获得功能。
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 在地图上显示要素?
【问题讨论】:
-
以 featureVectorSource 作为源,您的代码对我有用。我什至得到了点击事件。
-
是的,它适用于 featureVectorSource 。但它不适用于 featureClusterSource
-
是否有不能继续矢量源的原因?
-
是的,因为当我点击功能相交时,我只有一个功能。它不是真的。我必须同时获得两个功能
-
为此,您必须更改 forEachFeatureAtPixel 方法。根据您的代码,该方法会在检测到功能后立即返回该功能。所以顶部的任何功能都会被返回。