[OpenLayers-Users] OT: Event propagation problem...

Tim Schaub tschaub at openplans.org
Thu Nov 29 19:02:41 EST 2007


Hey-

Steve Lime wrote:
> What I ended up with is a div that covers the map and then I did something like:
> 
>   var elem = document.getElementById('myDiv');
>   elem.addEventListener( 'click', stopPropagation, false);
>   elem.addEventListener( 'mousedown', stopPropagation, false);
>   elem.addEventListener( 'mousemove', stopPropagation, false);
>   elem.addEventListener('mouseup', stopPropagation, false);
>   elem.addEventListener('mouseover', stopPropagation, false);
>   elem.addEventListener('mouseout', stopPropagation, false);
> 
> where stopPropagation is:
> 
>  function stopPropagation(e) { 
>    if (e && e.stopPropagation) evt.stopPropagation();
>    else if (window.event) window.event.cancelBubble = true;
>  }
> 

Since addEventListener isn't available cross-browser, you might want to 
try OpenLayers.Event.observe instead.

As in:

function block(evt) {
     OpenLayers.Event.stop(evt);
}
OpenLayers.Event.observe(elem, "mousedown", block);

etc.

Note it's probably enough to stop just mousedown, click, and dblclick. 
I haven't really followed what you're doing, but you might actually want 
to let mouseup and mousemove through.  Also, memory management (with 
stopObservingElement) is up to you since event listeners on elements 
with circular references are trouble for garbage collectors.

Tim

> Then I just hide/show the overlayed div as necessary. Works like a charm.
> 
> Steve
> 
>>>> On 11/29/2007 at 10:42 AM, in message
> <34E056CD4D475841B8C9ABCE956F92F615A37C at mrburns.KorOffice.local>, "Jeff Dege"
> <jdege at korterra.com> wrote:
>> I had a similar problem, and I hacked in a little kludge to allow me to turn 
>> off event propogation entirely:
>>
>> 	var map = new OpenLayers.Map('map', mapOptions);
>> 	
>> 	//This is a serious kludge, to allow us to turn off event handling on the 
>> map,
>>  	//when OpenLayers supports no such functionality.
>> 	map.events.idle = false;
>> 	map.events.originalTriggerEvent = openLayersMap.events.triggerEvent;
>> 	map.events.triggerEvent = function(type, evt) {
>> 		if (this.idle) return;
>> 		this.originalTriggerEvent(type, evt);
>> 	};
>>
>> It's ugly, and it may get me into real trouble, some time in the future, but 
>> it works.
>>
>> If I set map.events.idle = true, no events fire at all.
>>
>>
>> -----Original Message-----
>> From: Steve Lime [mailto:Steve.Lime at dnr.state.mn.us] 
>> Sent: Wed 11/28/2007 5:12 PM
>> To: Jeff Dege; users at openlayers.org 
>> Subject: RE: [OpenLayers-Users] OT: Event propagation problem...
>>  
>> No response at all, the content covers the whole map interface at the 
>> moment. Whether that works as a design (from a user perspective) is yet to be 
>> seen.
>>
>> Steve
>>
>>>>> On 11/28/2007 at 5:01 PM, in message
>> <34E056CD4D475841B8C9ABCE956F92F615A37B at mrburns.KorOffice.local>, "Jeff Dege"
>> <jdege at korterra.com> wrote:
>>> Do you want the map to not respond to clicks on your help or legend div?
>>>
>>> If so, you'll need to define event handlers, the way Popups do.
>>>
>>> Or do you want the map to not respond at all, while your help or legend is 
>>> visible?
>>>
>>>
>>> -----Original Message-----
>>> From: users-bounces at openlayers.org on behalf of Steve Lime
>>> Sent: Wed 11/28/2007 4:56 PM
>>> To: users at openlayers.org 
>>> Subject: [OpenLayers-Users] OT: Event propagation problem...
>>>  
>>> Hi all: Slightly off-topic question. I'm working on an interface that plops 
>>> help and legend content over the top of an OpenLayers
>>> map. Problem is that mouse events continue to propagate through the help or 
>>> legend content to OpenLayers. Anyone aware of
>>> an easy way to stop that or do I need to go ahead and define event handlers 
>>> (that do nothing) for the div that holds this other
>>> content?
>>>
>>> Steve
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org 
>>> http://openlayers.org/mailman/listinfo/users
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> !DSPAM:4033,474ef0b5293991628642973!
> 




More information about the Users mailing list