Gis 如何在OpenLayers 4上添加单击事件?

Gis 如何在OpenLayers 4上添加单击事件?,gis,openlayers,Gis,Openlayers,我需要将事件侦听器附加到OpenLayers 4中的功能。 我已经尝试了该功能。在('click',function(){…})上,但它不起作用。 如何向功能添加tan事件? 提前感谢。没有为功能ol.feature对象注册的单击事件。但是click事件存在于ol.Map。使用forEachFeatureAtPixel方法获取像素上的所有功能,并将其与要为其添加侦听器的功能进行比较 相关代码: var featureListener = function ( event ) { cons

我需要将事件侦听器附加到OpenLayers 4中的功能。 我已经尝试了该功能。在('click',function(){…})上,但它不起作用。 如何向功能添加tan事件?
提前感谢。

没有为功能
ol.feature
对象注册的
单击
事件。但是
click
事件存在于
ol.Map
。使用
forEachFeatureAtPixel
方法获取像素上的所有功能,并将其与要为其添加侦听器的功能进行比较

相关代码:

var featureListener = function ( event ) {
    console.log("featureListenerCalled");
    alert("Feature Listener Called");
};

map.on('click', function(event) {

    map.forEachFeatureAtPixel(event.pixel, function(feature,layer) {
        if ( feature.getId() == "IND" ) {
                feature.setStyle(listenerStyle);
                featureListener(event);
        }
    });
});
我已经创造了这个弹拨器来证明这一点。点击印度地图

var iconFeature = new ol.Feature({
  geometry: new ol.geom.Point(ol.proj.fromLonLat([lon, lat])),
  adres: adres
  //population: 4000,
  //rainfall: 500
});

// iconFeatureA is an array that gets all features on mouse click pixel location

map.on('click', function(e) {
  var iconFeatureA = map.getFeaturesAtPixel(e.pixel);
  if (iconFeatureA !== null) {
    var adres = iconFeatureA[0].get("adres");
    alert(adres);
    e.preventDefault(); // avoid bubbling 
  }
});