[英]Stop an event in OpenLayers 2?
I have a map with features. 我有一张有特色的地图。 I want to klick on features and react to 'featureselected'. 我想快速浏览一下功能并对“ featureselected”功能做出反应。 I also want to be able to click somewhere else in the map. 我还希望能够单击地图上的其他位置。
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function(evt) {
// do things
}
});
var click = new OpenLayers.Control.Click();
selectControl = new OpenLayers.Control.SelectFeature(vector);
_map.addControl(selectControl);
selectControl.activate();
_map.addControl(click);
click.activate();
vector.events.on({
'featureselected': onSelect,
When the feature is clicked, I DO NOT want to call the click function for the map. 单击功能时,我不想调用地图的单击功能。 What do I have to call in onSelect to prevent the event from propagating, bubbling? 我必须调用onSelect来防止事件传播,冒泡吗? Right now both functions are called when I click on a feature. 现在,当我单击某个功能时,将同时调用这两个功能。 I tried OpenLayers.Event.stop(evt), found evt.cancelBubble, cannot find evt.Bubbles 我尝试过OpenLayers.Event.stop(evt),发现evt.cancelBubble,找不到evt.Bubbles
Thanks a lot, Ropo 非常感谢,Ropo
I have an OpenLayers Map with an MouseOver-Control (Vector), with a SelectFeature (Vector) and also a Click-Event that searches GetFeatureInfo-Requests a the click position if nothing was found. 我有一个带有MouseOver-Control(矢量),一个SelectFeature(矢量)和一个Click-Event的OpenLayers映射,它搜索GetFeatureInfo-请求一个单击位置(如果未找到任何内容)。
It might help you to add your Click-Control before the selectControl. 它可以帮助您在SelectControl之前添加Click-Control。
My init-function approximately looks like this in the following order: 我的init函数大致如下所示:
oMouseOverCtrl = new OpenLayers.Control.SelectFeature( oMouseOverVectorArray, { ... });
oMapObj.addControl( oMouseOverCtrl );
oMouseOverCtrl.activate();
oMouseClickControl = new OpenLayers.Control.SelectFeature( oMouseOverVectorArray, { ... });
oMapObj.addControl( oMouseClickControl );
oMouseClickControl.activate();
oMouseClickControlInfotool = new OpenLayers.Control.WMSGetFeatureInfo({...});
oMapObj.addControl( oMouseClickControlInfotool );
oMouseClickControlInfotool.activate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.