new SuperMap.Events(object, element, eventTypes, fallThrough, options)
Name | Type | Default | Description |
---|---|---|---|
object |
Object |
Current event object has been added to JS object. |
|
element |
HTMLElement |
Respond DOM element of browser event. |
|
eventTypes |
Array.<string> |
Customize application event block. |
|
fallThrough |
boolean | false |
optional
Whether to allow the passing up of the event after being handled. If false, the passing up of the event is not allowed. |
options |
Object |
Selection of event object. |
Members
-
(constant) BROWSER_EVENTSArray.<string>
-
Supported events. Its default: [ "mouseover", "mouseout","mousedown", "mouseup", "mousemove", "click", "dblclick", "rightclick", "dblrightclick","resize", "focus", "blur","touchstart", "touchmove", "touchend","keydown", "MSPointerDown", "MSPointerUp", "pointerdown", "pointerup", "MSGestureStart", "MSGestureChange", "MSGestureEnd","contextmenu" ]
-
clearMouseListenerObject
-
-
elementHTMLElement
-
Respond DOM element of browser event.
-
eventHandlerfunction
-
An event handler object bound to an element.
-
eventTypesArray.<string>
-
A list of supported event types.
-
extensionCountObject
-
-
extensionsObject
-
Event extensions registered with this instance. Keys are event types, values are event object.
Example
Below is a minimal extension that provides the “foostart” and “fooend” event types, which replace the native “click” event type if clicked on an element with the css class “foo”: SuperMap.Events.foostart = SuperMap.Class({ initialize: function(target) { this.target = target; this.target.register("click", this, this.doStuff, {extension: true}); // only required if extension provides more than one event type this.target.extensions["foostart"] = true; this.target.extensions["fooend"] = true; }, destroy: function() { var target = this.target; target.unregister("click", this, this.doStuff); delete this.target; // only required if extension provides more than one event type delete target.extensions["foostart"]; delete target.extensions["fooend"]; }, doStuff: function(evt) { var propagate = true; if (SuperMap.Event.element(evt).className === "foo") { propagate = false; var target = this.target; target.triggerEvent("foostart"); window.setTimeout(function() { target.triggerEvent("fooend"); }, 1000); } return propagate; } }); // only required if extension provides more than one event type SuperMap.Events.fooend = SuperMap.Events.foostart;
-
fallThroughboolean
-
Whether to allow the passing up of the event after being handled. If false, the passing up of the event is not allowed.
-
includeXYboolean
-
Determines whether to create .xy property to the mouse event in the browser. Generally, it is set to false. If set to true, the .xy property will be automatically generated for the mouse event during event passing. The getMousePosition function can be called on related event handler according to the evt.object property of the event object.This option typically defaults to false for performance reasons: when creating an events object whose primary purpose is to manage relatively positioned mouse events within a div, it may make sense to set it to true.This option is also used to control whether the events object caches offsets If this is false, it will not: the reason for this is that it is only expected to be called many times if the includeXY property is set to true. If you set this to true, you are expected to clear the offset cache manually (using this.clearMouseCache()) if the border of the element changes or the location of the element in the page changes.
Example
function named(evt) { this.xy = this.object.events.getMousePosition(evt); }
-
listenersObject
-
Hashtable of Array(function): events listener functions
-
objectObject
-
Current event object has been added to JS object.
Methods
-
addEventType(eventName)
Events.js, line 185 -
Adds a new event type to current event object. If the event type has already been added before, nothing will be done.
Name Type Description eventName
string The event name.
-
attachToElement(element)
Events.js, line 197 -
Bind the browser event to the DOM element.
Name Type Description element
HTMLDOMElement The DOM element be bound the browser event
-
clearMouseCache()
Events.js, line 461 -
clear the mouse cache.
-
destroy()
Events.js, line 157 -
Removes all event observation and processing for the current feature element.
-
getMousePosition(evt){SuperMap.Pixel}
Events.js, line 475 -
Name Type Description evt
Event The event object.
Returns:
Type Description SuperMap.Pixel The x,y coordinates of the current mouse point. -
handleBrowserEvent(evt)
Events.js, line 428 -
The Packing to the triggerEvent function. Set xy attribute(XY coordinates of the current mouse point) for the event object.
Name Type Description evt
Event The event object.
-
on(object)
Events.js, line 233 -
Convenience method for registering listeners with a common scope. Internally, this method calls.
Name Type Description object
Object The object to be added listening.
Example
// register a single listener for the "loadstart" event events.on({"loadstart": loadStartListener}); // this is equivalent to the following events.register("loadstart", undefined, loadStartListener); // register multiple listeners to be called with the same `this` object events.on({ "loadstart": loadStartListener, "loadend": loadEndListener, scope: object }); // this is equivalent to the following events.register("loadstart", object, loadStartListener); events.register("loadend", object, loadEndListener);
-
register(type, obj, func, priority)
Events.js, line 266 -
Registers an event for the event object. While the event is triggered, the func function will be called. Now suppose SuperMap.Bounds as obj, and when the event is triggered, the context of the callback function will be taken as the Bounds object.
Name Type Default Description type
string Name of event registrant.
obj
Object this.object optional The callback bound to the object.
func
function optional The callback function. If there is no specified callback, this function will do nothing.
priority
boolean | Object optional If true, add the new monitor event before the event queue.
-
registerPriority(type, obj, func)
Events.js, line 303 -
The same registration method, but with the addition of a new listener event query instead of the end of the method.
Name Type Default Description type
string Name of event registrant.
obj
Object this.object optional The callback bound to the object.
func
function optional The callback function. If there is no specified callback, this function will do nothing.
-
remove(type)
Events.js, line 369 -
Delete all the listener of an event type. If the event type is not registered, no operation is done.
Name Type Description type
string Event type.
-
triggerEvent(type, evt){boolean}
Events.js, line 380 -
Triggers a specified registered event.
Name Type Description type
string The type of event triggered.
evt
Event The event object.
Returns:
Type Description boolean Returned listener object. If false is returned, the listening will be stopped. -
un(object)
Events.js, line 315 -
Convenience method for registering listeners with a common scope. Internally, this method calls
Name Type Description object
Object Remove the listener's object.
Example
// unregister a single listener for the "loadstart" event events.un({"loadstart": loadStartListener}); // this is equivalent to the following events.unregister("loadstart", undefined, loadStartListener); // unregister multiple listeners with the same `this` object events.un({ "loadstart": loadStartListener, "loadend": loadEndListener, scope: object }); // this is equivalent to the following events.unregister("loadstart", object, loadStartListener); events.unregister("loadend", object, loadEndListener);
-
unregister(type, obj, func)
Events.js, line 346 -
Cancellation of registration.
Name Type Default Description type
string Event type.
obj
Object this.object optional The callback bound to the object.
func
function optional The callback function. If there is no specified callback, this function will do nothing.