如何在OpenLayers中获取所选功能的Event或DOM元素 [英] How to get Event or DOM element of selected feature in OpenLayers

查看:210
本文介绍了如何在OpenLayers中获取所选功能的Event或DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm implementing an OpenLayers SelectFeature control, and trying to position an JQuery UI dialog widget right on top of the selected feature. To use the JQuery UI Position utility, it requires either a DOM element or an Event.

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

The onSelect callback of the SelectFeature control gives me an OpenLayers.Feature.Vector object representing the selected feature. From this, how do I get either the DOM element of the selected feature, or the Event object of the 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?
            }
   }); 


推荐答案

你做得对。

You are doing it right.

如果您执行 console.log(功能)您将看到它返回CLASS_NAME = $ b的对象$ bOpenLayers.Feature.Vector

If you do a console.log(feature) You'll see that it returns an object with CLASS_NAME = "OpenLayers.Feature.Vector"

onSelect: function(feature) {
    console.log(feature);
}

我明白了。
你可以添加事件监听器

I see. You could add event listeners

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

这篇关于如何在OpenLayers中获取所选功能的Event或DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆