×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    2

    Weird behaviour of event listeners

    I have a listener for a click event on a map and on the marker. When I click on the marker, also the function that is attached to the map is fired. Why? Isn't a marker overlay?
    Another thing is that also with double click listeners react, and this is wrong for sure. What am I doing wrong?

    Code:
    var newOfficeMarker = new nokia.maps.map.StandardMarker(
    	new nokia.maps.geo.Coordinate(0, 0),
    	{draggable: true}
    );
    
    function selectionOfNewOffice(){
    	newOfficeMarker.addListener("click", function(evt){
    		alert("Test2");
    		map.objects.remove(newOfficeMarker);
    	}, true);
    	addNewOfficeMarkerListener = function(evt){
    		alert("Test1");
    		if(evt.currentTarget == map && map.objects.indexOf(newOfficeMarker)<0)
    			map.objects.add(newOfficeMarker);
    	};
    	map.addListener("click", addNewOfficeMarkerListener, true);
    }

  2. #2
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: Weird behaviour of event listeners

    Event behaviour is described in detail in the API reference documentation here: http://api.maps.nokia.com/en/apirefe...entTarget.html It explains that events will propagate through the DOM so the MapDisplay will also receive an event when the MapMarker is clicked. You can stop this by using methods such as stopImmediatePropagation() Consider this code snippet:

    Code:
        var map = new nokia.maps.map.Display(mapContainer, {
            zoomLevel: 4, //zoom level for the map
            center: [50.5,15.5], // center coordinates
            components : [
               new nokia.maps.map.component.ZoomBar(), 
               new nokia.maps.map.component.Behavior(),
               new nokia.maps.map.component.TypeSelector(),
               new nokia.maps.map.component.Overview(),
               new nokia.maps.map.component.ScaleBar()]                   
        });
        
    map.addListener("click", function(evt) {	 
    	console.log(evt);
    });
    
    var marker = new nokia.maps.map.StandardMarker([50.5,15.5]);
    marker.addListener("click", function(evt) {	 
    	console.log(evt);
    	evt.stopImmediatePropagation();
    });
    
    map.objects.add(marker);
    Clicking on the marker will not fire the map "click" listener.

Similar Threads

  1. CLOCKD_TIME_CHANGED weird behaviour
    By mismael in forum Nokia N9
    Replies: 7
    Last Post: 2010-03-22, 14:02
  2. Weird behaviour with HandleForegroundEventL
    By narsi27 in forum Symbian
    Replies: 3
    Last Post: 2009-12-11, 13:56
  3. Weird Form behaviour on N73
    By Damo2k in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2008-02-21, 15:43
  4. NACK weird behaviour
    By gfk_75 in forum General Messaging
    Replies: 0
    Last Post: 2005-12-16, 11:49
  5. Weird 6630 behaviour
    By DinkyDino in forum General Development Questions
    Replies: 0
    Last Post: 2005-10-31, 11:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×