why doesn't show feature on map

断了今生、忘了曾经 提交于 2019-12-25 19:50:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!