Leaflet JS:在定义事件处理程序之前,需要实例化事件对象

时间:2012-11-06 20:37:20

标签: javascript leaflet

我正在尝试基于leaflet js map class上location()方法的成功创建事件处理程序

这就是我现在所拥有的:

function initMap() {
    var map = L.map('map').locate({setView: false});

    map.on('locationfound', function(s) {
        map.setView(s.latlng).setZoom(14);
    });

    map.on('locationerror', function(e) {
        message: 'Sorry, We were unable to determine your current location.';
    });

    L.tileLayer('http://{s}.tile.cloudmade.com/0e35616818144f159fa412e57f190939/997/256/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
        maxZoom: 18
    }).addTo(map);
}

在定义事件处理程序之前是否需要启动'或'e',或者s和e通过事件处理程序将角色假定为LocationEvent对象。如果是这样,那么这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

不需要启动它。作为事件侦听器传递的函数将自动以某些对象作为参数(在本例中为位置数据)进行调用。

相关问题