osm-directive.js
1.64 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
39
40
41
42
43
angular.module('focaModalLocalizar').directive('osmDireccion', function() {
return {
restrict: 'E',
link: function(scope, el, attrs) {
var contenedor = document.createElement('div');
contenedor.className = 'w-100 h-50 mt-3';
el.append(contenedor);
scope.map = L.map(contenedor).setView([-32.89214159952345, -68.84572999101856], attrs.zoom);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map);
},
controller: ['$scope', '$timeout', function($scope, $timeout) {
//resuelve bug mapa gris en modales
$timeout(function() {
$scope.map.invalidateSize();
}, 100);
$scope.markers = [];
$scope.$watchGroup(['latitud', 'longitud'], function() {
for(var i in $scope.markers) {
$scope.map.removeLayer($scope.markers[i]);
}
$scope.markers.push(
L.marker([$scope.latitud, $scope.longitud], {draggable: true})
.addTo($scope.map)
.on('dragend', function() {
$scope.latitud = this.getLatLng().lat;
$scope.longitud = this.getLatLng().lng;
$scope.$apply();
})
);
});
$scope.$on('moveMap', function(evt, data) {
$scope.map.panTo(new L.LatLng(data.latitud, data.longitud));
});
}],
scope: {
latitud: '=',
longitud: '=',
zoom: '='
}
};
});