为什么不在地图上显示功能
why doesn't show feature on map
这是 fiddle 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.it 效果很好,但这次我在地图上单击要素时没有获得要素。
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 在地图上显示要素?
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 方法以将它们添加到数组中。 Here 可以正常工作 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'));
}
}
} ;
这是 fiddle 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.it 效果很好,但这次我在地图上单击要素时没有获得要素。
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 在地图上显示要素?
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 方法以将它们添加到数组中。 Here 可以正常工作 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'));
}
}
} ;