Evented

提供事件绑定、移除等相关方法。Map、Layer等都继承了Evented类。


示例

//绑定地图点击事件

map.on('click', function(e) {
    alert(e.latlng);//e就是事件类MouseEvent
} );

//如果事件需要移除,需将事件响应定义为独立函数

function onClick(e) {
    alert(e.latlng);
}
map.on('click', onClick);
map.off('click', onClick);

方法

方法名 返回值 描述
on(< String > type,< Function> fn(Event),< Object > context?) this 绑定事件处理方法,回调函数的参数就是事件对象
off(< String > type,< Function> fn(Event),< Object > context?) this 移除事件处理方法,如果不传递fn函数,删除对应事件的所有处理方法
off() this 移除所有事件处理方法
fire( type, data?, propagate?) this 激发指定类型的事件

results matching ""

    No results matching ""