【问题标题】:Detecting right click position on angular leaflet map检测角度传单地图上的右键单击位置
【发布时间】:2015-05-26 20:01:29
【问题描述】:

我有一个显示使用angular-leaflet-directive 0.7.11 的地图的移动页面,并声明了我需要的事件,如下所示:

$scope.map = {
    events: [
        'mousedown',
        'contextmenu'
    ],
    ...
}

$scope.$on('leafletDirectiveMap.mousedown', function (event) {
    debugger;
});

在调试器语句所在的位置,event 变量不包含有关单击地图的位置的信息。触发contextmenu 事件时,该指令提供了相同的event 格式。

事实上,如果我检查整个event 变量,它只是一个Object,而不是Event

the docs 错了吗? the example 有什么遗漏吗?如何获取我右键单击(长按)的特定位置的 X/Y Lat/Lng?

【问题讨论】:

    标签: angular-leaflet-directive


    【解决方案1】:

    您需要使用“leafletEvent”。试试这个:

    myApp.controller('YourController', ['$scope', 'leafletEvent', function($scope) {
    
        $scope.$on('leafletDirectiveMap.mousedown', function (event, leafletEvent) {
            leafletData.getMap().then(function(map) {
                map.on('click', function(e) {
                    console.log('e');
                    console.log(e);
                    console.log('e.latlng:');
                    console.log(e.latlng); // L.LatLng {lat: 19.642587534013046, lng: -4.5703125}
                });
            });
        });
    }]);
    

    【讨论】:

    • 正确!参数 #2 (leafletEvent) 没有记录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多