如何在OpenLayers中获取选定功能的事件或DOM元素

yal*_*tar 5 javascript jquery openlayers

我正在实现OpenLayers SelectFeature控件,并尝试将JQuery UI对话框小部件放置在所选功能的顶部。要使用JQuery UI Position Utility,它需要DOM元素或Event。

SelectFeature控件的onSelect回调为我提供了代表所选功能的OpenLayers.Feature.Vector对象。由此,如何获得所选功能的DOM元素或click事件的Event对象?

  var selectControl = new OpenLayers.Control.SelectFeature(clientsLayer, {
            hover   : false,
            clickout: false,
            multiple: false,
            onSelect: function(feature) {
                // how do I get the DOM element of the feature
                // or alternately, the click event of the selection?
            }
   }); 
Run Code Online (Sandbox Code Playgroud)

cap*_*gon 1

你做得对。

如果你执行 aconsole.log(feature)你会看到它返回一个 CLASS_NAME = "OpenLayers.Feature.Vector" 的对象

onSelect: function(feature) {
    console.log(feature);
}
Run Code Online (Sandbox Code Playgroud)

更新:

我懂了。您可以添加事件监听器

var selectControl = new OpenLayers.Control.SelectFeature(clientsLayer, {
    hover: false,
    clickout: false,
    multiple: false,
    eventListeners: {
        featurehighlighted: function (event) {
            console.log(event);
            console.log(event.feature);
        }
    }
});
Run Code Online (Sandbox Code Playgroud)