none
How to disable map zoom on "plus" key press? RRS feed

  • Question

  • Hi All,
    I am trying to disable zoom-action on "plus" key using handler on "keypress" event.

    Here is code:

    Microsoft.Maps.Events.addHandler(map, 'keypress',  function(e) {
            if (e.charCode == 43) {
                e.handled = true;
                return false;
            }
    });

    Seems like e.handled = true; trick works fine for other events, but not for 'keypress' event.

    Have you any advice on how to disable "plus"-action (and deep zoom on "cmd +" on safari MAC)?

    Thanks.

    Friday, February 8, 2013 1:51 PM

Answers

  • Hello, 

    What you can easily do is to catch the keydown event (rather than keypress) and prevent the default action based on the keycode (rather than the charCode): 

    Microsoft.Maps.Events.addHandler(map, 'keydown',  function(e) {
    	if (e.keyCode === 187) {
    		e.handled = true;
    		return false;
    	}
    });
    
    Hope this will help.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/

    Monday, February 18, 2013 9:20 AM
    Moderator

All replies

  • Hello, 

    What you can easily do is to catch the keydown event (rather than keypress) and prevent the default action based on the keycode (rather than the charCode): 

    Microsoft.Maps.Events.addHandler(map, 'keydown',  function(e) {
    	if (e.keyCode === 187) {
    		e.handled = true;
    		return false;
    	}
    });
    
    Hope this will help.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/

    Monday, February 18, 2013 9:20 AM
    Moderator
  • Yes, this way it works fine.

    Thank you!

    Monday, February 18, 2013 2:32 PM