Commit 46ea32e0a9963aca0aa1224416297da0afa969e3
1 parent
b3172e5814
Exists in
master
no heigh
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
src/js/osm-directive.js
1 | angular.module('focaModalPuntoDescarga').directive('osmPuntoDescarga', function() { | 1 | angular.module('focaModalPuntoDescarga').directive('osmPuntoDescarga', function() { |
2 | return { | 2 | return { |
3 | restrict: 'E', | 3 | restrict: 'E', |
4 | link: function(scope, el, attrs) { | 4 | link: function(scope, el, attrs) { |
5 | var contenedor = document.createElement('div'); | 5 | var contenedor = document.createElement('div'); |
6 | contenedor.className = 'w-100 h-50 mt-3'; | 6 | contenedor.className = 'w-100 mt-3'; |
7 | el.append(contenedor); | 7 | el.append(contenedor); |
8 | scope.map = L.map(contenedor); | 8 | scope.map = L.map(contenedor); |
9 | L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map); | 9 | L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map); |
10 | }, | 10 | }, |
11 | controller: ['$scope', '$timeout', function($scope, $timeout) { | 11 | controller: ['$scope', '$timeout', function($scope, $timeout) { |
12 | //resuelve bug mapa gris en modales | 12 | //resuelve bug mapa gris en modales |
13 | $timeout(function() { | 13 | $timeout(function() { |
14 | $scope.map.invalidateSize(); | 14 | $scope.map.invalidateSize(); |
15 | }, 100); | 15 | }, 100); |
16 | 16 | ||
17 | $scope.markers = []; | 17 | $scope.markers = []; |
18 | $scope.$watchGroup(['latitud', 'longitud'], function() { | 18 | $scope.$watchGroup(['latitud', 'longitud'], function() { |
19 | for(var i in $scope.markers) { | 19 | for(var i in $scope.markers) { |
20 | $scope.map.removeLayer($scope.markers[i]); | 20 | $scope.map.removeLayer($scope.markers[i]); |
21 | } | 21 | } |
22 | $scope.map.setView([$scope.latitud, $scope.longitud], 14); | 22 | $scope.map.setView([$scope.latitud, $scope.longitud], 14); |
23 | $scope.markers.push( | 23 | $scope.markers.push( |
24 | L.marker([$scope.latitud, $scope.longitud], {draggable: true}) | 24 | L.marker([$scope.latitud, $scope.longitud], {draggable: true}) |
25 | .addTo($scope.map) | 25 | .addTo($scope.map) |
26 | .on('dragend', function() { | 26 | .on('dragend', function() { |
27 | $scope.latitud = this.getLatLng().lat; | 27 | $scope.latitud = this.getLatLng().lat; |
28 | $scope.longitud = this.getLatLng().lng; | 28 | $scope.longitud = this.getLatLng().lng; |
29 | $scope.$apply(); | 29 | $scope.$apply(); |
30 | }) | 30 | }) |
31 | ); | 31 | ); |
32 | }); | 32 | }); |
33 | }], | 33 | }], |
34 | scope: { | 34 | scope: { |
35 | latitud: '=', | 35 | latitud: '=', |
36 | longitud: '=', | 36 | longitud: '=', |
37 | zoom: '=' | 37 | zoom: '=' |
38 | } | 38 | } |
39 | }; | 39 | }; |
40 | }); | 40 | }); |
41 | 41 |