keyboard.js
来自「用来在地图上做操作GIS,在地图上做标记」· JavaScript 代码 · 共 107 行
JS
107 行
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/release-license.txt * for the full text of the license. *//** * @requires OpenLayers/Handler.js * @requires OpenLayers/Events.js * * Class: OpenLayers.handler.Keyboard * A handler for keyboard events. Create a new instance with the * <OpenLayers.Handler.Keyboard> constructor. * * Inherits from: * - <OpenLayers.Handler> */OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, { /* http://www.quirksmode.org/js/keys.html explains key x-browser key handling quirks in pretty nice detail */ /** * Constant: KEY_EVENTS * keydown, keypress, keyup */ KEY_EVENTS: ["keydown", "keypress", "keyup"], /** * Property: eventListener * {Function} */ eventListener: null, /** * Constructor: OpenLayers.Handler.Keyboard * Returns a new keyboard handler. * * Parameters: * control - {<OpenLayers.Control>} The control that is making use of * this handler. If a handler is being used without a control, the * handlers setMap method must be overridden to deal properly with * the map. * callbacks - {Object} An object containing a single function to be * called when the drag operation is finished. The callback should * expect to recieve a single argument, the pixel location of the event. * Callbacks for 'keydown', 'keypress', and 'keyup' are supported. * options - {Object} Optional object whose properties will be set on the * handler. */ initialize: function(control, callbacks, options) { OpenLayers.Handler.prototype.initialize.apply(this, arguments); // cache the bound event listener method so it can be unobserved later this.eventListener = OpenLayers.Function.bindAsEventListener( this.handleKeyEvent, this ); }, /** * Method: destroy */ destroy: function() { this.deactivate(); this.eventListener = null; OpenLayers.Handler.prototype.destroy.apply(this, arguments); }, /** * Method: activate */ activate: function() { if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { for (var i = 0; i < this.KEY_EVENTS.length; i++) { OpenLayers.Event.observe( window, this.KEY_EVENTS[i], this.eventListener); } return true; } else { return false; } }, /** * Method: deactivate */ deactivate: function() { var deactivated = false; if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { for (var i = 0; i < this.KEY_EVENTS.length; i++) { OpenLayers.Event.stopObserving( window, this.KEY_EVENTS[i], this.eventListener); } deactivated = true; } return deactivated; }, /** * Method: handleKeyEvent */ handleKeyEvent: function (evt) { if (this.checkModifiers(evt)) { this.callback(evt.type, [evt.charCode || evt.keyCode]); } }, CLASS_NAME: "OpenLayers.Handler.Keyboard"});
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?