⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 2 页
字号:
OpenLayers.Events = OpenLayers.Class({    /**      * Constant: BROWSER_EVENTS     * {Array(String)} supported events      */    BROWSER_EVENTS: [        "mouseover", "mouseout",        "mousedown", "mouseup", "mousemove",         "click", "dblclick",        "resize", "focus", "blur"    ],    /**      * Property: listeners      * {Object} Hashtable of Array(Function): events listener functions       */    listeners: null,    /**      * Property: object      * {Object}  the code object issuing application events      */    object: null,    /**      * Property: element      * {DOMElement}  the DOM element receiving browser events      */    element: null,    /**      * Property: eventTypes      * {Array(String)}  list of support application events      */    eventTypes: null,    /**      * Property: eventHandler      * {Function}  bound event handler attached to elements      */    eventHandler: null,    /**      * APIProperty: fallThrough      * {Boolean}      */    fallThrough: null,    /**     * Constructor: OpenLayers.Events     * Construct an OpenLayers.Events object.     *     * Parameters:     * object - {Object} The js object to which this Events object  is being     * added element - {DOMElement} A dom element to respond to browser events     * eventTypes - {Array(String)} Array of custom application events      * fallThrough - {Boolean} Allow events to fall through after these have     *                         been handled?     */    initialize: function (object, element, eventTypes, fallThrough) {        this.object     = object;        this.element    = element;        this.eventTypes = eventTypes;        this.fallThrough = fallThrough;        this.listeners  = {};        // keep a bound copy of handleBrowserEvent() so that we can        // pass the same function to both Event.observe() and .stopObserving()        this.eventHandler = OpenLayers.Function.bindAsEventListener(            this.handleBrowserEvent, this        );        // if eventTypes is specified, create a listeners list for each         // custom application event.        if (this.eventTypes != null) {            for (var i = 0; i < this.eventTypes.length; i++) {                this.addEventType(this.eventTypes[i]);            }        }                // if a dom element is specified, add a listeners list         // for browser events on the element and register them        if (this.element != null) {            this.attachToElement(element);        }    },    /**     * APIMethod: destroy     */    destroy: function () {        if (this.element) {            OpenLayers.Event.stopObservingElement(this.element);        }        this.element = null;        this.listeners = null;        this.object = null;        this.eventTypes = null;        this.fallThrough = null;        this.eventHandler = null;    },    /**     * APIMethod: addEventType     * Add a new event type to this events object.     * If the event type has already been added, do nothing.     *      * Parameters:     * eventName - {String}     */    addEventType: function(eventName) {        if (!this.listeners[eventName]) {            this.listeners[eventName] = [];        }    },    /**     * Method: attachToElement     *     * Parameters:     * element - {HTMLDOMElement} a DOM element to attach browser events to     */    attachToElement: function (element) {        for (var i = 0; i < this.BROWSER_EVENTS.length; i++) {            var eventType = this.BROWSER_EVENTS[i];            // every browser event has a corresponding application event             // (whether it's listened for or not).            this.addEventType(eventType);                        // use Prototype to register the event cross-browser            OpenLayers.Event.observe(element, eventType, this.eventHandler);        }        // disable dragstart in IE so that mousedown/move/up works normally        OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);    },    /**     * APIMethod: register     * Register an event on the events object.     *     * When the event is triggered, the 'func' function will be called, in the     * context of 'obj'. Imagine we were to register an event, specifying an      * OpenLayers.Bounds Object as 'obj'. When the event is triggered, the      * context in the callback function will be our Bounds object. This means     * that within our callback function, we can access the properties and      * methods of the Bounds object through the "this" variable. So our      * callback could execute something like:      * :    leftStr = "Left: " + this.left;     *        *                   or     *       * :    centerStr = "Center: " + this.getCenterLonLat();     *     * Parameters:     * type - {String} Name of the event to register     * obj - {Object} The object to bind the context to for the callback#.     *                     If no object is specified, default is the Events's      *                     'object' property.     * func - {Function} The callback function. If no callback is      *                        specified, this function does nothing.     *      *      */    register: function (type, obj, func) {        if (func != null) {            if (obj == null)  {                obj = this.object;            }            var listeners = this.listeners[type];            if (listeners != null) {                listeners.push( {obj: obj, func: func} );            }        }    },    /**     * APIMethod: registerPriority     * Same as register() but adds the new listener to the *front* of the     *     events queue instead of to the end.     *         *     TODO: get rid of this in 3.0 - Decide whether listeners should be      *     called in the order they were registered or in reverse order.     *     *     * Parameters:     * type - {String} Name of the event to register     * obj - {Object} The object to bind the context to for the callback#.     *                If no object is specified, default is the Events's      *                'object' property.     * func - {Function} The callback function. If no callback is      *                   specified, this function does nothing.     */    registerPriority: function (type, obj, func) {        if (func != null) {            if (obj == null)  {                obj = this.object;            }            var listeners = this.listeners[type];            if (listeners != null) {                listeners.unshift( {obj: obj, func: func} );            }        }    },        /**     * APIMethod: unregister     *     * Parameters:     * type - {String}      * obj - {Object} If none specified, defaults to this.object     * func - {Function}      */    unregister: function (type, obj, func) {        if (obj == null)  {            obj = this.object;        }        var listeners = this.listeners[type];        if (listeners != null) {            for (var i = 0; i < listeners.length; i++) {                if (listeners[i].obj == obj && listeners[i].func == func) {                    listeners.splice(i, 1);                    break;                }            }        }    },    /**      * Method: remove     * Remove all listeners for a given event type. If type is not registered,     *     does nothing.     *     * Parameters:     * type - {String}      */    remove: function(type) {        if (this.listeners[type] != null) {            this.listeners[type] = [];        }    },    /**     * APIMethod: triggerEvent     * Trigger a specified registered event     *      * Parameters:     * type - {String}      * evt - {Event}      */    triggerEvent: function (type, evt) {        // prep evt object with object & div references        if (evt == null) {            evt = {};        }        evt.object = this.object;        evt.element = this.element;        // execute all callbacks registered for specified type        // get a clone of the listeners array to        // allow for splicing during callbacks        var listeners = (this.listeners[type]) ?                            this.listeners[type].slice() : null;        if ((listeners != null) && (listeners.length > 0)) {            for (var i = 0; i < listeners.length; i++) {                var callback = listeners[i];                var continueChain;                if (callback.obj != null) {                    // use the 'call' method to bind the context to callback.obj                    continueChain = callback.func.call(callback.obj, evt);                } else {                    continueChain = callback.func(evt);                }                    if ((continueChain != null) && (continueChain == false)) {                    // if callback returns false, execute no more callbacks.                    break;                }            }            // don't fall through to other DOM elements            if (!this.fallThrough) {                           OpenLayers.Event.stop(evt, true);            }        }    },    /**     * Method: handleBrowserEvent     * Basically just a wrapper to the triggerEvent() function, but takes      *     care to set a property 'xy' on the event with the current mouse      *     position.     *     * Parameters:     * evt - {Event}      */    handleBrowserEvent: function (evt) {        evt.xy = this.getMousePosition(evt);         this.triggerEvent(evt.type, evt)    },    /**     * Method: getMousePosition     *      * Parameters:     * evt - {Event}      *      * Returns      * {<OpenLayers.Pixel>} The current xy coordinate of the mouse, adjusted     *                      for offsets     */    getMousePosition: function (evt) {        if (!this.element.offsets) {            this.element.offsets = OpenLayers.Util.pagePosition(this.element);            this.element.offsets[0] += (document.documentElement.scrollLeft                         || document.body.scrollLeft);            this.element.offsets[1] += (document.documentElement.scrollTop                         || document.body.scrollTop);        }        return new OpenLayers.Pixel(            (evt.clientX + (document.documentElement.scrollLeft                         || document.body.scrollLeft)) - this.element.offsets[0]                         - (document.documentElement.clientLeft || 0),             (evt.clientY + (document.documentElement.scrollTop                         || document.body.scrollTop)) - this.element.offsets[1]                         - (document.documentElement.clientTop || 0)        );     },    CLASS_NAME: "OpenLayers.Events"});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -