0

我正在尝试在 openlayers 的弹出窗口上有一个点击事件。现在我正在使用该功能中的硬编码 onclick 进行操作:

    var vector = new OpenLayers.Layer.Vector("Points",{
            eventListeners:{
                'featureselected':function(evt){
                    var feature = evt.feature;
                    var popup = new OpenLayers.Popup.Anchored("popup",
                        OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
                        new OpenLayers.Size(275,71),
                        '<div id="pincontent" onclick="pindetails()"><h3>' + feature.attributes.title +'</h3><div style="display: none;" id="pindescription">'+  feature.attributes.content +'</div></div>',
                        null,
                        false
                    );
                    popup.imageSrc = 'img/popup.png';
                    popup.autoSize = false;
                    popup.backgroundColor = 'transparent';
                    var offset = {'size':new OpenLayers.Size(0,0),'offset':new OpenLayers.Pixel(-74,-10)};
                    popup.anchor = offset;
                    popup.panMapIfOutOfView = true;
                    popup.imageSize = new OpenLayers.Size(275,71);
                    popup.relativePosition = "br";
                    popup.calculateRelativePosition = function () {
                         return 'tr';
                    };
                    feature.popup = popup;
                    map.addPopup(popup);
     //adding event listener
                    map.events.register('mousedown', popup, function(evt){alert('help')}, false);
                },
                'featureunselected':function(evt){
                    var feature = evt.feature;
                    map.removePopup(feature.popup);
                    feature.popup.destroy();
                    feature.popup = null;
                }

            }
        });

但是主要的 OpenLayers div 正在拦截点击,所以我必须点击两次。我不确定是否有办法禁用它。我查看了 openLayers 文档,但不确定如何使用他们的 API 添加事件侦听器以单击功能。

4

2 回答 2

2

也许您应该return false;在 onclick 中的函数调用之后添加以停止事件传播(这是默认设置)。也看看注册方法:

this.map.events.register('click', this.map, function handleMapClick(e) { ... }

http://dev.openlayers.org/releases/OpenLayers-2.6/doc/apidocs/files/OpenLayers/Events-js.html#OpenLayers.Events.register

于 2013-02-06T13:32:27.317 回答
0

似乎这evt.stopPropagation();行不通。但是return true;singleclick事件处理程序中使用可以阻止Event-Propagation向下渗透到级联层。

于 2019-06-16T15:18:08.200 回答