Close infoWindow with ESC key?

2292
4
06-26-2011 11:08 PM
StephenLead
Regular Contributor III
Has anyone implemented a listener to close the infoWindow when the ESC key is pressed?

If so are you able to share the code, so I don't reinvent the wheel?

Thanks,
Steve
0 Kudos
4 Replies
HemingZhu
Occasional Contributor III
Has anyone implemented a listener to close the infoWindow when the ESC key is pressed?

If so are you able to share the code, so I don't reinvent the wheel?

Thanks,
Steve


Though i have not done this, it should be straightforward. Something like this.

dojo.connect (map, "onKeyDown", function (key){ if (key.keyCode == 27) { map.infoWindow.hide(); } }); //ESC keyCode =27. keyCode =0 means no key press
0 Kudos
derekswingley1
Frequent Contributor II
Nice one hzhu! Now, what do I need to do to get you to start using code tags? ;)
0 Kudos
DanielYim
New Contributor II
As the Internet moves to the "Web 3.0" paradigm, I think it's almost necessary to incorporate the keyboard as a part of my mapping applications. So personally, I use Shortcuts.js to handle the mapping of all of my keyboard shortcuts.

It's as simple as adding this to your HTML:
<script type="text/javascript" src="shortcuts.js"></script>


And then adding the following to your Javascript's init or dojo.addOnLoad:
    // Define some keyboard shortcuts
    var kbdOptions = {
        disable_in_input: true,
        propagate: false
    };
    shortcut.add("Escape", function() {
        N.myMap.infoWindow.hide();
    }, kbdOptions);


Other examples: I use F for full extent, I for the identify tool, Q and W for prev/next extent.
It really helps the powerusers out there make the most out of your application, without them needing to fumble around with toolbars.
0 Kudos
StephenLead
Regular Contributor III
Daniel, this is great - thanks
0 Kudos