|
| 1 | +<!DOCTYPE html> |
| 2 | +<html ng-app="demoApp"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <script src="../bower_components/angular/angular.js"></script> |
| 7 | + <script src="../bower_components/leaflet/dist/leaflet.js"></script> |
| 8 | + <script src="../bower_components/leaflet.markercluster/dist/leaflet.markercluster.js"></script> |
| 9 | + <script src="../dist/angular-leaflet-directive_dev_mapped.js"></script> |
| 10 | + <link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" /> |
| 11 | + <link rel="stylesheet" href="../bower_components/leaflet.markercluster/dist/MarkerCluster.Default.css" /> |
| 12 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 13 | + <script> |
| 14 | + var app = angular.module('demoapp', ['leaflet-directive']); |
| 15 | + |
| 16 | + app.controller('Ctrl', ['$scope', 'leafletData', function($scope, leafletData) { |
| 17 | + angular.extend($scope, { |
| 18 | + center: { |
| 19 | + lat: 48.879633, |
| 20 | + lng: 2.331717, |
| 21 | + zoom: 15 |
| 22 | + }, |
| 23 | + layers: { |
| 24 | + baselayers: { |
| 25 | + osm: { |
| 26 | + name: 'OpenStreetMap', |
| 27 | + url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 28 | + type: 'xyz' |
| 29 | + } |
| 30 | + }, |
| 31 | + overlays: { |
| 32 | + mapdescription: { |
| 33 | + name: 'Markers added', |
| 34 | + type: 'group', |
| 35 | + visible: true |
| 36 | + }, |
| 37 | + points: { |
| 38 | + name: 'Points of interest', |
| 39 | + type: 'group', |
| 40 | + visible: true |
| 41 | + } |
| 42 | + } |
| 43 | + }, |
| 44 | + defaultIcon: {}, |
| 45 | + markers: { |
| 46 | + "mapdescription": [], |
| 47 | + "points": [{ |
| 48 | + "layer": "points", |
| 49 | + "lat": 48.879633, |
| 50 | + "lng": 2.331717, |
| 51 | + "message": "MALL 1" |
| 52 | + }, { |
| 53 | + "layer": "points", |
| 54 | + "lat": 48.879318, |
| 55 | + "lng": 2.33151, |
| 56 | + "message": "MALL 2" |
| 57 | + }] |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + $scope.$on("leafletDirectiveMap.click", function(event, args) { |
| 62 | + var leafEvent = args.leafletEvent; |
| 63 | + // console.log("before", $scope.markers.mapdescription, $scope.markers.points); |
| 64 | + $scope.markers.mapdescription.push({ |
| 65 | + layer: 'mapdescription', |
| 66 | + lat: leafEvent.latlng.lat, |
| 67 | + lng: leafEvent.latlng.lng, |
| 68 | + draggable: true, |
| 69 | + icon: '' |
| 70 | + }); |
| 71 | + // console.log("after", $scope.markers.mapdescription, $scope.markers.points); |
| 72 | + |
| 73 | + }); |
| 74 | + |
| 75 | + $scope.$on("leafletDirectiveMarker.contextmenu", function(event, args) { |
| 76 | + var marker_index = parseInt(args.modelName.replace('mapdescription.', '')); |
| 77 | + $scope.markers.mapdescription.splice(marker_index, 1); |
| 78 | + |
| 79 | + }); |
| 80 | + |
| 81 | + |
| 82 | + }]); |
| 83 | + </script> |
| 84 | +</head> |
| 85 | + |
| 86 | +<body ng-controller="Ctrl"> |
| 87 | + <leaflet center="center" markers="markers" markers-nested="true" layers="layers"></leaflet> |
| 88 | +</body> |
| 89 | + |
| 90 | +</html> |
0 commit comments