Map navigation using keys

686
2
11-22-2011 01:16 AM
JasonSandall
New Contributor
I have noticed that the keyboard navigation keys (arrow and + - keys) are only active when the mouse cursor is over the map.

Is there a way to activate keyboard navigation when the mouse isn't positioned over the map?

Many Thanks
Jason
0 Kudos
2 Replies
HemingZhu
Occasional Contributor III
I have noticed that the keyboard navigation keys (arrow and + - keys) are only active when the mouse cursor is over the map.

Is there a way to activate keyboard navigation when the mouse isn't positioned over the map?

Many Thanks
Jason


You can implement your own navigation by useing onkeypress event(or some other key relate events) on certain key. It is supported by most the html tags and javascript doc. example: onkeypress="javascriptFunction(k){if (k.keyCode=(keycode value of whatever key you choose))  dosomemapnavigation;}"
0 Kudos
JasonSandall
New Contributor
Yes thanks for replying, you are correct.  I have already implemented that work-around.  I was a little disappointed that the esri japi code only works with the mouse.  Not very good for accessibility.  This is the code I ended up using:

map.disableKeyboardNavigation();
dojo.connect(document,"onkeydown",trapkey);     

function trapkey(evt){
    var evt=(evt) ? evt : ((event) ? event : null);
    var node=(evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if(node.type==undefined){
        if(evt.keyCode==40){map.panDown();return false;}
        if(evt.keyCode==39){map.panRight();return false;}
        if(evt.keyCode==38){map.panUp();return false;}
        if(evt.keyCode==37){map.panLeft();return false;}
        if(evt.keyCode==187){map.setLevel(map.getLevel()+1);return false;}
        if(evt.keyCode==189){map.setLevel(map.getLevel()-1);return false;}
    } else {return true;}
}
0 Kudos