使用 angular-leaflet-directive 右键单击地图上的标记时如何创建上下文菜单
how to create context menu when right clicking on marker on a map using angular-leaflet-directive
我是 angular-leaflet-directive 的新手。
我想在右键单击标记时有一个上下文菜单。
我找不到任何 angular 方式的例子。
谁能指导实现它。
angular-leaflet-directive 中是否存在该功能?因为我在文档中找不到任何相关信息。
首先从此 link
下载 angular 上下文菜单所需的文件
这里是例子,
<!DOCTYPE html>
<html ng-app="demoapp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<script src="http://tombatossals.github.io/angular-leaflet-directive/dist/angular-leaflet-directive.min.js"></script>
<script src=" leaflet.contextmenu-src"></script>
<link rel="stylesheet" href="leaflet.contextmenu.css" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller('MarkersSimpleController', ['$scope', function($scope) {
$scope.showCoordinates = function(e) {
alert(e.latlng);
}
var mainMarker = {
lat: 51,
lng: 0,
focus: true,
draggable: true,
message: "hey marker",
contextmenu: true,
contextmenuWidth: 140,
contextmenuItems: [{
text: 'Show coordinates',
callback: $scope.showCoordinates
}]
};
angular.extend($scope, {
london: {
lat: 51.505,
lng: -0.09,
zoom: 8
},
markers: {
mainMarker: angular.copy(mainMarker)
},
position: {
lat: 51,
lng: 0
},
events: { // or just {} //all events
markers: {
enable: ['dragend']
//logic: 'emit'
}
}
});
$scope.$on("leafletDirectiveMarker.dragend", function(event, args) {
$scope.position.lat = args.model.lat;
$scope.position.lng = args.model.lng;
});
}]);
</script>
</head>
<body ng-controller="MarkersSimpleController">
<!-- <leaflet lf-center="london" markers="markers" height="480px" width="100%"></leaflet> EVENTS WILL STILL FIRE but all will for each directive-->
<!-- NOTICE events attribute is optional it is more for options in whitelisting (enable), blacklisting (disable), and logic (emit or broadcast) -->
<leaflet lf-center="london" event-broadcast="events" markers="markers" height="480px" width="100%"></leaflet>
<h1>Markers simple example</h1>
<p>Initial marker position (lat/lng): <strong ng-bind="markers.mainMarker.lat"></strong> / <strong ng-bind="markers.mainMarker.lng"></strong></p>
<p>Actual marker position (lat/lng): <strong ng-bind="position.lat"></strong> / <strong ng-bind="position.lng"></strong></p>
</p>
</body>
</html>
Plunker link 同样
我是 angular-leaflet-directive 的新手。
我想在右键单击标记时有一个上下文菜单。
我找不到任何 angular 方式的例子。
谁能指导实现它。
angular-leaflet-directive 中是否存在该功能?因为我在文档中找不到任何相关信息。
首先从此 link
下载 angular 上下文菜单所需的文件这里是例子,
<!DOCTYPE html>
<html ng-app="demoapp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<script src="http://tombatossals.github.io/angular-leaflet-directive/dist/angular-leaflet-directive.min.js"></script>
<script src=" leaflet.contextmenu-src"></script>
<link rel="stylesheet" href="leaflet.contextmenu.css" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller('MarkersSimpleController', ['$scope', function($scope) {
$scope.showCoordinates = function(e) {
alert(e.latlng);
}
var mainMarker = {
lat: 51,
lng: 0,
focus: true,
draggable: true,
message: "hey marker",
contextmenu: true,
contextmenuWidth: 140,
contextmenuItems: [{
text: 'Show coordinates',
callback: $scope.showCoordinates
}]
};
angular.extend($scope, {
london: {
lat: 51.505,
lng: -0.09,
zoom: 8
},
markers: {
mainMarker: angular.copy(mainMarker)
},
position: {
lat: 51,
lng: 0
},
events: { // or just {} //all events
markers: {
enable: ['dragend']
//logic: 'emit'
}
}
});
$scope.$on("leafletDirectiveMarker.dragend", function(event, args) {
$scope.position.lat = args.model.lat;
$scope.position.lng = args.model.lng;
});
}]);
</script>
</head>
<body ng-controller="MarkersSimpleController">
<!-- <leaflet lf-center="london" markers="markers" height="480px" width="100%"></leaflet> EVENTS WILL STILL FIRE but all will for each directive-->
<!-- NOTICE events attribute is optional it is more for options in whitelisting (enable), blacklisting (disable), and logic (emit or broadcast) -->
<leaflet lf-center="london" event-broadcast="events" markers="markers" height="480px" width="100%"></leaflet>
<h1>Markers simple example</h1>
<p>Initial marker position (lat/lng): <strong ng-bind="markers.mainMarker.lat"></strong> / <strong ng-bind="markers.mainMarker.lng"></strong></p>
<p>Actual marker position (lat/lng): <strong ng-bind="position.lat"></strong> / <strong ng-bind="position.lng"></strong></p>
</p>
</body>
</html>
Plunker link 同样