×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    3

    How to disable an eventListener ?

    I am using a simple event listener to get coordinates of any clicked point. But i want to control it from a checkbox inside another div to listen it or not. How can i disable this ? Code below;
    Code:
    var noteContainer = new NoteContainer({
    	id: "coordinateOnClickUi",
    	parent: document.getElementById("uiContainer"),
    	title: "Menu",
    	content:
    		'<p><input type="checkbox" id="editle" onclick="startEdit()"/> Add Point</p>'
    		
    });
    eventlistener;
    Code:
    function startEdit(){
    if($('#editle').is(":checked")){
    
    map.addListener(CLICK, function (evt) {
    	var coord = map.pixelToGeo(evt.displayX, evt.displayY);
     
    ...
    
    	infoBubbles.openBubble(inf_content, coord );
            marker =  new nokia.maps.map.StandardMarker(coord, {
    			draggable: true
    		});
            map.objects.add(marker);
    	
    	// Clear the logger
    	positionLogger.clear();
    	
    	// We now print the latitude & longitude to the logger
    	positionLogger.log(
    		"Clicked at position: <br />latitude: " + 
    		coord.latitude + "<br /> longitude: " + coord.longitude);
    });
    }
                    else
    		{
    			//???????????????????????
    		}
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: How to disable an eventListener ?

    To disable an event listener, you merely need to call EventTarget.removeListener(), passing in the function you wish to remove. Therefore in your example you would need to explicitly create the function as a variable, and disable it when necessary. e.g.

    Code:
    function SomeObject(){
    	that = this;
    	this.myDragFunction =   function(evt){
           		// ... do your stuff here
    	}
    
    	if(!this.evtTarget) {
            	/// create the event target if necessary, you could use an existing event object such as a map here.
    		this.evtTarget =  nokia.maps.dom.EventTarget( document.getElementById( "groundoverlay")).enableDrag());
    		this.enableDrag();
    	}
    
    	this.enableDrag= function(mapDisplay){
    		that.evtTarget.addListener("drag", that.myDragFunction);
    	};
    
    	this.disableDrag= function(mapDisplay){
    		that.evtTarget.removeListener("drag", that.myDragFunction);
    	}
    }
    So in your case it will merely be: map.addListener("click", myFunction); and map.removeListener("click", myFunction);

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    3

    Re: How to disable an eventListener ?

    Thanks for great collaboration and support, it worked out properly

Similar Threads

  1. Disable wi-fi
    By shweta_912 in forum Symbian C++
    Replies: 2
    Last Post: 2011-07-21, 10:30
  2. how to disable red-eye
    By wujun8217 in forum Symbian C++
    Replies: 1
    Last Post: 2008-09-02, 05:56
  3. Events or Eventlistener problems...
    By alr1976 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-03-30, 18:49
  4. how can i disable this?
    By chintankanani11 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-10-02, 16:43
  5. disable t9
    By brain_dead00 in forum Symbian C++
    Replies: 3
    Last Post: 2005-04-08, 10:29

Posting Permissions

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