export var Evented = Class.extend(this);
定義了基于事件的類彩郊,如Map找岖、Marker等。
Generally, events allow you to execute some function when something happens with an object靴患,例如
map.on('click', function(e) {
alert(e.latlng);
} );
leaflet通過引用處理事件監(jiān)聽,例如
function onClick(e) { ... }
map.on('click', onClick);
map.off('click', onClick);
方法
- on(type:String, fn:Function, context?:Object):this
向某個對象的type類型的事件添加監(jiān)聽函數(shù)涉瘾,可指定監(jiān)聽函數(shù)的上下文(this)
types可以是一個types/handlers的map,如
{click: onClick, mousemove: onMouseMove}
- off(type:String, fn?:Function, context?:Object):this
@alternative
@method off(eventMap:Object):this 刪除type/listener對
刪除之前添加的監(jiān)聽,若未指定函數(shù),會刪除對象某個事件的所有監(jiān)聽函數(shù)
- fire(type:String, data?: Object, propagate?: Boolean):this
觸發(fā)指定類型的事件捷兰,可提供數(shù)據(jù)對象-監(jiān)聽函數(shù)的第一個參數(shù)包含它的屬性,可指定事件是否可傳播給父元素 - listens(type:String):Boolean
若指定的事件有對應(yīng)的監(jiān)聽函數(shù)立叛,則返回true - once: function(types, fn, context)
- addEventParent(obj:Object):this
- removeEventParent(obj:Evented):this