Commit 942356475a84783f141ca5a8b29c474222ea49a4

Authored by Marcelo Puebla
1 parent 89b5f90e00
Exists in develop

Change

Codigo identado
Showing 2 changed files with 49 additions and 48 deletions   Show diff stats
src/js/osm-directive.js
1 angular.module('focaModalLocalizar').directive('osmDireccion', function() { 1 angular.module('focaModalLocalizar')
2 .directive('osmDireccion', function () {
2 return { 3 return {
3 restrict: 'E', 4 restrict: 'E',
4 link: function(scope, el, attrs) { 5 link: function (scope, el, attrs) {
5 var contenedor = document.createElement('div'); 6 var contenedor = document.createElement('div');
6 el.append(contenedor); 7 el.append(contenedor);
7 scope.map = L.map(contenedor).setView([-32.89214159952345, -68.84572999101856], attrs.zoom); 8 scope.map = L.map(contenedor).setView([-32.89214159952345, -68.84572999101856], attrs.zoom);
8 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);
9 }, 10 },
10 controller: ['$scope', '$timeout', function($scope, $timeout) { 11 controller: ['$scope', '$timeout', function ($scope, $timeout) {
11 //resuelve bug mapa gris en modales 12 //resuelve bug mapa gris en modales
12 $timeout(function() { 13 $timeout(function () {
13 $scope.map.invalidateSize(); 14 $scope.map.invalidateSize();
14 }, 100); 15 }, 100);
15 16
16 $scope.markers = []; 17 $scope.markers = [];
17 $scope.$watchGroup(['latitud', 'longitud'], function() { 18 $scope.$watchGroup(['latitud', 'longitud'], function () {
18 for(var i in $scope.markers) { 19 for (var i in $scope.markers) {
19 $scope.map.removeLayer($scope.markers[i]); 20 $scope.map.removeLayer($scope.markers[i]);
20 } 21 }
21 $scope.markers.push( 22 $scope.markers.push(
22 L.marker([$scope.latitud, $scope.longitud], {draggable: true}) 23 L.marker([$scope.latitud, $scope.longitud], { draggable: true })
23 .addTo($scope.map) 24 .addTo($scope.map)
24 .on('dragend', function() { 25 .on('dragend', function () {
25 $scope.latitud = this.getLatLng().lat; 26 $scope.latitud = this.getLatLng().lat;
26 $scope.longitud = this.getLatLng().lng; 27 $scope.longitud = this.getLatLng().lng;
27 $scope.$apply(); 28 $scope.$apply();
28 }) 29 })
29 ); 30 );
30 }); 31 });
31 32
32 $scope.$on('moveMap', function(evt, data) { 33 $scope.$on('moveMap', function (evt, data) {
33 $scope.map.panTo(new L.LatLng(data.latitud, data.longitud)); 34 $scope.map.panTo(new L.LatLng(data.latitud, data.longitud));
34 }); 35 });
35 }], 36 }],
36 scope: { 37 scope: {
37 latitud: '=', 38 latitud: '=',
38 longitud: '=', 39 longitud: '=',
39 zoom: '=' 40 zoom: '='
40 } 41 }
41 }; 42 };
42 }); 43 });
43 44
1 angular.module('focaModalLocalizar') 1 angular.module('focaModalLocalizar')
2 .service('focaModalLocalizarService', [ 2 .service('focaModalLocalizarService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) { 5 function ($http, API_ENDPOINT) {
6 return { 6 return {
7 getLatLng: function(direccion) { 7 getLatLng: function (direccion) {
8 return $http.get('https://nominatim.openstreetmap.org/search', {params: direccion}); 8 return $http.get('https://nominatim.openstreetmap.org/search', { params: direccion });
9 }
10 };
11 } 9 }
12 ]); 10 };
11 }