osm-directive.js
7.39 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
angular.module('focaLogisticaPedidoRuta').directive('focaLogistica', function() {
return {
restrict: 'E',
link: function(scope, el, attrs) {
var contenedor = document.createElement('div');
contenedor.className = 'border border-light rounded';
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', '$compile', 'focaModalService',
function($scope, $filter, $compile, focaModalService) {
$scope.markers = [];
$scope.verProductos = function(id) {
var parametrosModal = {
titulo: 'Productos',
query: '/articulos/remito/' + id,
soloMostrar: true,
size: 'md',
columnas: [
{
nombre: 'Producto',
propiedad: 'descripcion'
},
{
nombre: 'Cantidad',
propiedad: 'cantidad'
}
]
};
focaModalService.modal(parametrosModal).then();
};
$scope.$watch('marcadores', function() {
for(var i in $scope.markers) {
$scope.map.removeLayer($scope.markers[i]);
}
$scope.markers = [];
angular.forEach($scope.marcadores, function(marcador) {
var observacion =
'Vendedor: ' + marcador.idVendedor + ' - ' +
(
marcador.vendedor ?
marcador.vendedor.NOM :
''
) + '<br/>';
observacion += 'Fecha: ' +
$filter('date')(marcador.fechaRemito.slice(0,10), 'dd/MM/yyyy') + ' ' +
marcador.fechaRemito.slice(11,19) + '<br/>';
observacion += 'Remito Nº: ' + $filter('comprobante')([
marcador.sucursal,
marcador.numeroRemito
]) + '<br/>';
observacion += 'Cliente: ' +
marcador.cliente.NOM;
// if($scope.parametros.individual) {
if (marcador.orden) {
observacion = 'Orden: ' + marcador.orden + '<br/>' + observacion;
}
if (marcador.distancia) {
observacion += '<br/>Distancia a casa central: ' +
marcador.distancia + 'km';
}
var icon;
if (marcador.idUsuarioProceso) {
observacion += '<br/>';
observacion += '<strong>';
observacion += 'Fecha de entrega: ' + marcador
.cisternaMovimientos[0].cisternaCarga.fechaReparto.substring(0, 10);
observacion += '<br/>';
observacion += 'Vehículo: ' + marcador
.cisternaMovimientos[0].cisternaCarga.cisterna.vehiculo.codigo;
observacion += '<br/>';
observacion += 'Transportista: ' + marcador
.cisternaMovimientos[0].cisternaCarga.cisterna.vehiculo.transportista
.NOM;
observacion += '</strong>';
//Asignado ROJO
icon = new L.Icon({
iconUrl: 'img/marker-icon-2x-red.png',
shadowUrl: 'img/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
} else {
observacion += '<br/>';
observacion += '<i class="fa fa-map-marker marcador fa-4x" aria-hidden="true"'+
'class="form-control" ondragend="dropEnd()" ondragstart=\'drag(event, '+
JSON.stringify(marcador)+')\' draggable="true"></i><br><b>(Arrastrar icono)</b>';
observacion += '<button title="Ver productos" class="btn btn-secondary' +
' float-right informacion"'+
'ng-click="verProductos('+marcador.id+')">' + //id del Remito
'<i class="fa fa-info" aria-hidden="true"></i>' +
'</button>';
//Sin asignar VERDE
icon = new L.Icon({
iconUrl: 'img/marker-icon-2x-green.png',
shadowUrl: 'img/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
}
//COMPILO HTML PARA QUE FUNCIONE BOTON EN POPUP
observacion = '<div class="disable-selection">' + observacion + '</div>';
var compiledHtml = $compile(angular.element(observacion))($scope);
//Primero verifico si punto de desscarga, si lo hay extraigo lat y long desde alli
if (marcador.remitoPuntoDescarga.length) {
$scope.markers.push(
L.marker(
[marcador.remitoPuntoDescarga.puntoDescarga[0].latitud,
marcador.remitoPuntoDescarga.puntoDescarga[0].longitud], {icon: icon})
.addTo($scope.map)
.bindPopup(compiledHtml[0])
.bindTooltip('Haga click para seleccionar')
);
}
//Si no existe punto de descarga, se selecciona la primera direccion
//con latitud y longitud desde los Datos del cliente.
else if (marcador.cliente.direcciones.length) {
$scope.markers.push(
L.marker(
[marcador.cliente.direcciones[0].DATO,
marcador.cliente.direcciones[1].DATO], {icon: icon})
.addTo($scope.map)
.bindPopup(compiledHtml[0])
.bindTooltip('Haga click para seleccionar')
);
} else {
console.log('Los remitos filtrados no contienen datos de latitud y longitud',marcador);
}
//abre marcador del primer punto
//$scope.markers[0].openPopup();
});
});
}],
scope: {
latitud: '=',
longitud: '=',
zoom: '=',
marcadores: '=',
parametros: '='
}
};
});