osm-directive.js
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
angular.module('focaAdminSeguimiento').directive('osm', function() {
return {
restrict: 'E',
link: function(scope, el, attrs) {
var contenedor = document.createElement('div');
el.append(contenedor);
scope.map = L.map(contenedor).setView([attrs.latitud, attrs.longitud], attrs.zoom);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map);
},
controller: ['$scope', '$filter', function($scope, $filter) {
$scope.markers = [];
$scope.$watch('marcadores', function() {
for(var i in $scope.markers) {
$scope.map.removeLayer($scope.markers[i]);
}
$scope.markers = [];
angular.forEach($scope.marcadores, function(marcador) {
$scope.markers.push(
L.marker([marcador.latitud, marcador.longitud]).addTo($scope.map)
.bindPopup(
'Actividad: ' + marcador.actividad + '<br/>' +
'Fecha: ' + $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') +
' ' + marcador.fecha.slice(11,19) + '<br/>' +
marcador.observaciones
).openPopup()
);
});
});
}],
scope: {
latitud: '=',
longitud: '=',
zoom: '=',
marcadores: '='
}
};
});