为什么不;不要在地图上显示特征

why doesn't show feature on map

本文关键字:显示 特征 地图 为什么不      更新时间:2023-09-26

这是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。它运行良好,但在这段时间里,当我点击地图上的功能时,我没有得到功能。

 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在地图上显示要素?

但我将源-featureClusterSource更改为featureVectorSource。它运行良好,但在这段时间里,当我点击地图上的功能时,我没有得到功能。

单击相交的要素时,更改"EachFeatureAtPixel"方法以将它们添加到阵列中。这是一把工作小提琴

    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'));
            }
         }
   } ;