Documentos de Académico
Documentos de Profesional
Documentos de Cultura
@Component({
selector: 'ns-maps',
templateUrl: './maps.component.html',
styles: [
` #map { height: 100%;}
.th {border: 1px solid black}
}`
],
providers: [
CultivosService
]
})
export class MapsComponent implements OnInit, AfterViewInit {
componentCultivoId = Components.SuggestCultivo;
componentVariedadId = Components.SuggestVariedad;
data$: any;
cultivoEncontrado: string;
centroDeCostoEncontrado: string;
variedadEncontrada: string;
etapaFenologicaEncontrada: string;
nombreIngresado: string;
estadoSeleccionado: string;
fechaInicio: Date = new Date('2019-10-18');
fechaFin: Date = new Date('2020-01-18');
hectareas: Number;
drawingManager: any;
map: any;
cultivo =
{
path: [[]],
estado: '',
tipoCultivo: '',
plaga: true,
humedad: 10
};
filtro = {
nombreFiltro: '',
tipoFiltro: '',
estadoFiltro: ''
};
infowindow = new google.maps.InfoWindow({
content: ''
});
element: HTMLDivElement;
data: any;
constructor(el: ElementRef, private service: CultivosService, private cdr:
ChangeDetectorRef) {
this.element = el.nativeElement;
}
ngAfterViewInit() {
this.initMap();
}
update() {
this.gcultivos.forEach(item => item.setMap(null));
this.gmarkers1.forEach(item => item.setMap(null));
this.grutas.forEach(item => item.setMap(null));
this.gcultivos = [];
this.gmarkers1 = [];
this.grutas = [];
this.rutas = [];
if (this.cultivos !== null) {
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.cultivos.length; i++) {
this.addCultivo(this.cultivos[i], this.map, i, !this.administrador, false);
}
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.rutas.length; i++) {
this.addRuta(this.rutas[i], this.map);
}
}
}
crearHerramientasDeDibujo(map: GoogleMap) {
this.drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: ['polygon', 'polyline']
},
markerOptions: { icon:
'https://developers.google.com/maps/documentation/javascript/examples/full/images/b
eachflag.png' },
});
this.drawingManager.setMap(null);
if (this.draw) {
this.drawingManager.setMap(map);
}
google.maps.event.addListener(this.drawingManager, 'polylinecomplete',
(polyline) => {
const tipoRuta = window.prompt('Ingresa el tipo de ruta', 'Evaluador o
Aplicador');
const nuevaRuta = [polyline.getPath(), tipoRuta];
this.rutas.push(nuevaRuta);
this.addRuta(this.rutas[this.rutas.length - 1], map);
polyline.setMap(null);
});
}
centrarMapa(latitud: number, longitud: number) {
this.map.setCenter(
new google.maps.LatLng(+latitud, +longitud)
);
this.map.setZoom(17);
}
eliminarNuevoCultivo() {
this.cultivoAux.setMap(null);
this.ocultarNuevoCultivoForm();
}
guardarNuevoCultivo() {
const variedad = this.labelVariedadActual;
const estado = 'Bien';
//const nombre = this.nombreIngresado;
//const etapaFen = this.etapaFenologicaEncontrada;
if (variedad !== undefined) {
let conPlaga: boolean;
if (estado === 'Bien') {
conPlaga = false;
} else {
conPlaga = true;
}
const nCultivo = { coordenadas: this.cultivoAux.getPath(), estado: 'Bien',
tipocultivo: variedad, plaga: conPlaga, humedad: 5 };
this.cultivos.push(nCultivo);
this.addCultivo(nCultivo, this.map, this.cultivos.length - 1, true, true);
this.ocultarNuevoCultivoForm();
this.eCultivo.emit(variedad);
this.mostrarConfirmarForm();
} else {
alert('Complete todos los datos.');
}
this.coordenadas = [];
}
obtenerIdFenologia(fenologiaSeleccionado: any) {
this.idFenologiaActual = +fenologiaSeleccionado.id;
}
obtenerIdCultivo(cultivoSeleccionado: any) {
this.idCultivoActual = +cultivoSeleccionado.id;
}
obtenerIdVariedad(variedadSeleccionada: any) {
this.idVariedadActual = +variedadSeleccionada.id;
this.labelVariedadActual = variedadSeleccionada.label;
}
confirmarCreacionCultivo() {
let fechainicioSiembra = new Date(this.fechaInicio);
fechainicioSiembra.setDate(fechainicioSiembra.getDate() + 1);
let fechaFinSiembra = new Date(this.fechaFin);
fechaFinSiembra.setDate(fechaFinSiembra.getDate() + 1);
this.service.insertarSiembra(
this.idCultivoActual,
this.idVariedadActual,
google.maps.geometry.spherical.computeArea(this.cultivoAux.getPath()),
fechainicioSiembra,
fechaFinSiembra,
this.idCentroCosto
).subscribe(
(idsiembra) => {
if (!idsiembra) {
return console.error('No existe el id perro');
}
editarCultivo() {
this.mostrarEditarForm(this.cultivoAux);
this.ocultarOpcionesCultivoForm();
this.mostrarConfirmarForm();
}
verCultivo() {
let txtPlaga = '';
if (this.cultivoAux.plaga) {
txtPlaga = 'Si';
} else {
txtPlaga = 'No';
}
this.modal.open({ coordenadas: this.cultivoAux.getPath().getAt(0).toString(),
tipo: this.cultivoAux.tipoCultivo, color: this.cultivoAux.strokeColor, estado:
this.cultivoAux.estado, centrocosto: this.cultivoAux.centrocosto });
this.ocultarOpcionesCultivoForm();
}
//Los campos de cultivo deben llamarse como en el json
async addCultivo(cultivo: any, mapa: GoogleMap, id: any, habilitado: boolean,
dibujado: boolean): Promise<void> {
let coordenadasAux: any[] = [];
if (cultivo.coordenadas === undefined) {
return;
}
// tslint:disable-next-line: prefer-for-of
if (!dibujado) {
if (cultivo.coordenadas === null || cultivo.coordenadas === undefined) {
return;
}
for (let i = 0; i < cultivo.coordenadas.length; i++) {
let vlat = parseFloat(cultivo.coordenadas[i].lat);
let vlng = parseFloat(cultivo.coordenadas[i].lng);
coordenadasAux.push({ lat: vlat, lng: vlng });
}
} else {
coordenadasAux = cultivo.coordenadas;
}
const path = coordenadasAux;
const tipoCultivo = cultivo.tipocultivo;
const plaga = cultivo.plaga;
const imagen = '';
const idsiembra = cultivo.idsiembra;
const centrocosto = cultivo.centrocosto;
let txtPlaga = '';
const humedad = 0;
let color = '';
const rojo = '#FF3333';
const amarillo = '#FFF333';
const gris = '#9C9C9C';
const verde = '#39FF33';
const borde = '#FFCCFF';
let marcador;
const infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(150, 100),
content: 'Hola\n' + 'Jhosecc saca locro \n'
});
if (this.etiquetas != null) {
subetiquetasAux = this.etiquetas.slice();
}
if (habilitado) {
google.maps.event.addListener(nuevoCultivo, 'click', (event) => {
this.mostrarOpcionesCultivoForm(nuevoCultivo);
nuevoCultivo.infowindow.open(this.map);
});
}
nuevoCultivo.setMap(mapa);
this.gcultivos.push(nuevoCultivo);
const marcadorCultivo = [id, cultivo.tipoCultivo, bounds.getCenter().lat(),
bounds.getCenter().lng(), cultivo.variedad];
this.addMarker(marcadorCultivo, nuevoCultivo, mapa);
this.cultivoAux = nuevoCultivo;
return Promise.resolve();
}
this.evaluaciones = await
this.service.listarEvaluaciones(idsiembra).toPromise();
if ( this.evaluaciones.length === 0 ) {
return 'SE';
}
const numeroSubtiquetas = this.etiquetas.reduce( ( a, etiqueta) => {
etiqueta.children.forEach( subetiqueta => {
labelsSubEtiquetas.push(subetiqueta.nombre || '');
umbrales.push((subetiqueta.umbral1 || '').split('-'));
umbrales.push((subetiqueta.umbral3 || '').split('-'));
umbrales.push((subetiqueta.umbral2 || '').split('-'));
});
return a + (etiqueta.children || []).length;
}, 0);
console.log('Cantidad de subetiquetas', numeroSubtiquetas);
console.log('estos son los umbrales prro', umbrales);
console.log('estos son los nombres guau guau', labelsSubEtiquetas);
// SE LEEN TODAS LAS EVALUACIONES EN EL PRIMER FOR, Y DENTRO DE ELLA CADA VALOR
DE LA SUBETIQUETA;
// tslint:disable-next-line: prefer-for-of
for (let numeroEvaluacion = 0; numeroEvaluacion < this.evaluaciones.length;
numeroEvaluacion++) {
if (this.evaluaciones[numeroEvaluacion].children !== undefined) {
for (let i = 0; i < totalSubEtiquetas; i++) {
let valorAnalizado = 0;
if (this.evaluaciones[numeroEvaluacion].children[i]) {
valorAnalizado =
this.evaluaciones[numeroEvaluacion].children[i].valornumerico;
}
cultivo.marcador = nuevoMarcador;
this.gmarkers1.push(nuevoMarcador);
}
obtenerDatos(event) {
this.modal2.show();
}
mostrarNuevoCultivoForm() {
this.nuevoCultivoForm.show();
}
ocultarNuevoCultivoForm() {
this.nuevoCultivoForm.hide();
}
mostrarEditarForm(cultivo: any) {
let color = '';
const rojo = '#FF3333';
const amarillo = '#FFF333';
// const gris = '#9C9C9C';
const verde = '#39FF33';
switch (cultivo.estado) {
case 'Grave': color = rojo; break;
case 'Peligro': color = amarillo; break;
case 'Bien': color = verde; break;
}
mostrarConfirmarForm() {
this.confirmarForm.show();
}
ocultarConfirmarForm() {
this.confirmarForm.hide();
}
mostrarOpcionesCultivoForm(cultivo: any) {
this.cultivoAux = cultivo;
this.opcionesCultivoForm.show();
}
ocultarOpcionesCultivoForm() {
this.opcionesCultivoForm.hide();
}
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.gcultivos.length; i++) {
// Obtenemos el cultuvo actual
cultivo = this.gcultivos[i];
if (cultivosSeleccionados.length === 0) {
filtroCultivoActivo = false;
}
if (umbralesSeleccionados.length === 0) {
filtroUmbralActivo = false;
}
if (aprobado) {
// volvemos visibles al cultivo y su marcador
cultivo.setVisible(true);
if (filtroMarcadoresActivo) {
this.gmarkers1[i].setVisible(true);
} else {
this.gmarkers1[i].setVisible(false);
}
} else {
// volvemos invisibles al cultivo y su marcador
cultivo.setVisible(false);
this.gmarkers1[i].setVisible(false);
cultivo.infowindow.close();
}
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.grutas.length; i++) {
// Obtenemos el cultuvo actual
ruta = this.grutas[i];
if (filtroRuta) {
ruta.setVisible(true);
} else {
ruta.setVisible(false);
}
}
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.gcultivos.length; i++) {
// Obtenemos el cultuvo actual
cultivo = this.gcultivos[i];
}
}
getCoordenadas(): string {
let cords = '';
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.coordenadas.length; i++) {
cords += this.coordenadas[0] + '\n';
}
return cords;
}
}