[ka-Map-users] Customize key press on viewport

Paul Spencer pspencer at dmsolutions.ca
Wed May 17 07:45:37 EDT 2006


David,

In general, I like this as it is minimally invasive.  That being  
said, I'm not sure I like the way this is handled currently.  For  
instance, what if you want/need to change the other key handlers?

An alternate solution can be accomplished using a custom subclass of  
kaNavigator:

function dbNavigator( oKaMap ) {
     kaNavigator.apply(this,[oKaMap]);
     for (var p in kaNavigator.prototype) {
         if (!dbNavigator.prototype[p])
             dbNavigator.prototype[p]= kaNavigator.prototype[p];
     }
}

dbNavigator.prototype.onkeypress = function(e) {
     e = (e)?e:((event)?event:null);
     if (e) {
         var charCode=(e.charCode)?e.charCode:e.keyCode;
         switch(charCode) {
             case xx:
                 break;
             default:
	        kaTool.prototype.onkeypress.apply(this, [e]);
         }
     }
}

This would allow you to handle any keypress and defer the rest to the  
kaTool subclass handler (for instance), while using dbNavigator  
exactly like kaNavigator.  It also involves no changes to the cvs  
version of the code :)

Cheers

Paul

On 16-May-06, at 4:35 PM, David Badke wrote:

> I wanted to handle arbitrary key press events when the navigator  
> tool is active. I originally added a case to the kaTool.onkeypress  
> function, but I didn't like changing the core code like that. So  
> I've come up with another way, which I am hoping the illustrious ka- 
> Map crew will accept in the cvs.
>
> 1. Change kaTool.onkeypress function 'default' case from:
>
>          default:
>              b = false;
> to:
>          default:
>             b = false;
>             if (this.userKeyPress)
>                  b = this.userKeyPress(charCode);
>
> 2. If you want to add key press handling, after the navigator tool  
> is initialized (startUp.js), add:
>
>         myKaNavigator.userKeyPress = myKeyPress;
>
> where myKeyPress is something like:
>
>         function myKeyPress(charCode) {
>           result = true;
>           switch (charCode) {
>             case nn:
>               ... whatever ...
>               break;
>                       default:
>               result = false;
>           }
>           return result;
>         }
>
> If myKaNavigator.userKeyPress is not set, nothing happens, same as  
> before.
>
>
> Comments? Better ways to do this?
>
> David
>
>
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users

+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+






More information about the ka-Map-users mailing list