Está en la página 1de 15

import { GoogleMap } from '@agm/core/services/google-maps-types';

import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, EventEmitter,


Input, OnInit, Output, ViewChild } from '@angular/core';
import { ModalDialogComponent } from '@app/libraries/modal/modal.component';
import { CultivosService } from 'src/app/services/cultivos.service';
import { ModalComponent } from '../modal/modal.component';
import { Components } from '@app/config/components.config';
import { resolve } from 'dns';
// In your App's module:
declare const google: any;

export interface Variedadd {


label: string;
value: string;
}

@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;

@ViewChild('modal', { static: true }) modal: ModalComponent;


@ViewChild('mod', { static: true }) modal2: ModalDialogComponent;
@ViewChild('nuevoCultivoForm', { static: true }) nuevoCultivoForm:
ModalDialogComponent;
@ViewChild('confirmarForm', { static: true }) confirmarForm:
ModalDialogComponent;
@ViewChild('opcionesCultivoForm', { static: true }) opcionesCultivoForm:
ModalDialogComponent;
coordenadas: any[] = [];
@Input() draw: boolean;
@Input() latitud = -8.098920;
@Input() longitud = -78.947724;
@Input() puntos = [];
@Input() rutas = [];
@Input() cultivos = [];
@Input() code: string;
@Input() idCentroCosto: number;
variedadesOpt = [];
@Output() sender = new EventEmitter();
variedadesSeleccionadas: string[] = [];
evaluaciones: any[] = [];
etiquetas: any[] = [];
listaCultivos: any[] = [];
listaEtapasFenologicas: any[];
idCultivoActual = 0;
idVariedadActual = 0;
idNivel: number;
idLote = 2;
labelVariedadActual: string;
idFenologiaActual = 1;

@Output() eCultivo = new EventEmitter<string>();

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;

listaEstados: string[] = ['Bien', 'Peligro', 'Grave'];


listaVariedades: string[] = [];
cultivosFiltrados: any[];
centrosDeCostosFiltrados: any[];
variedadesFiltradas: any[];
etapasFenologicasFiltradas: any[];
estadosFiltrados: any[];

@Input() administrador: boolean;


cultivoAux: any;
gmarkers1 = [];
grutas = [];
gcultivos = [];
data2 = {};

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);
}
}
}

async initMap(): Promise<void> {


this.map = new google.maps.Map(this.element.querySelector('#map'), {
center: { lat: this.latitud, lng: this.longitud },
zoom: 16,
mapTypeId: 'satellite',
polygon: this.gcultivos,
polyline: this.grutas,
marker: this.gmarkers1,
});
await this.update();
if (this.administrador) {
this.crearHerramientasDeDibujo(this.map);
}
return Promise.resolve();
}

marcarVariedades(list: Variedadd[], list2: string[]) {


list.forEach(item => {
list2.push(item.value);
});
}
ngOnInit(): void {
}

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, 'polygoncomplete', (polygon)


=> {
for (let i = 0; i < polygon.getPath().getLength(); i++) {
var nuevasCoordenadas = new Object();
nuevasCoordenadas = {
lat: polygon.getPath().getAt(i).lat().toString(),
lng: polygon.getPath().getAt(i).lng().toString()
};
this.coordenadas.push(nuevasCoordenadas);
}
// const estado = window.prompt('Ingresa el estado', 'grave, bien, peligro');
// const tipo = window.prompt('Ingresa el tipo', 'Pera');
polygon.setMap(null);
this.cultivoAux = polygon;
this.hectareas =
google.maps.geometry.spherical.computeArea(this.cultivoAux.getPath());
if (this.hectareas >= 1000) {
this.mostrarNuevoCultivoForm();
} else {
alert('El área del nuevo cultivo es muy pequeña');
}
});

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');
}

const bounds = new google.maps.LatLngBounds();


let coordenadasJson = [];
for (let j = 0; j < this.cultivoAux.getPath().length; j++) {
bounds.extend(this.cultivoAux.getPath().getAt(j));
coordenadasJson.push(
{
latitud: this.cultivoAux.getPath().getAt(j).lat().toString(),
longitud: this.cultivoAux.getPath().getAt(j).lng().toString()
}
);
}
this.service.insertarCoordenadas(idsiembra,
JSON.stringify(coordenadasJson)).subscribe(response => {
// // actualizar coordenadas de la base de datos con las de cultivoAux
const pos = new google.maps.LatLng(bounds.getCenter().lat(),
bounds.getCenter().lng());
this.cultivoAux.marcador.setOptions({ position: pos });
this.cultivoAux.setOptions({ editable: false, fillColor: '#9C9C9C',
strokeColor: '#9C9C9C' });
});
},
(err) => console.log('Ocurrió un error', err),
() => this.ocultarConfirmarForm()
);
// tslint:disable-next-line: prefer-for-of
}

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'
});

cultivo.estado = await this.analizarSiembra(cultivo.idsiembra);


console.log('Ya se ejecutó prro');
switch (cultivo.estado) {
case 'Grave': color = rojo; break;
case 'Peligro': color = amarillo; break;
case 'Bien': color = verde; break;
case 'SE': color = gris; break;
}
if (!habilitado) {
color = gris;
}
if (plaga) {
txtPlaga = 'Si';
} else {
txtPlaga = 'No';
}
let evaluacionesAux = [];
let subetiquetasAux = [];
if (this.evaluaciones != null) {
evaluacionesAux = this.evaluaciones.slice();
}

if (this.etiquetas != null) {
subetiquetasAux = this.etiquetas.slice();
}

let nuevoCultivo = new google.maps.Polygon({


paths: path,
strokeColor: color,
strokeOpacity: 1,
strokeWeight: 1,
fillColor: color,
fillOpacity: 0.5,
editable: false,
estado: cultivo.estado,
plaga,
humedad,
tipoCultivo,
infowindow,
imagen,
marcador,
idsiembra,
centrocosto,
evaluaciones: evaluacionesAux,
subetiquetas: subetiquetasAux
});

const bounds = new google.maps.LatLngBounds();


for (let j = 0; j < nuevoCultivo.getPath().length; j++) {
bounds.extend(nuevoCultivo.getPath().getAt(j));
}

nuevoCultivo.addListener('click', (event) => {


mapa.setZoom(16.5);
mapa.setCenter({ lat: bounds.getCenter().lat(), lng: bounds.getCenter().lng()
});
nuevoCultivo.infowindow.open(this.map);
});

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();
}

async analizarSiembra(idsiembra): Promise<string> {


console.log('ID siembra', idsiembra);
const umbrales: any[] = [];
const labelsSubEtiquetas: any[] = [];

this.etiquetas = await this.service.listarSubEtiquetas(idsiembra).toPromise();

this.evaluaciones = await
this.service.listarEvaluaciones(idsiembra).toPromise();

// if (this.evaluaciones.length === 0 || this.etiquetas.length === 0) {


// return 'SE';
// }

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);

let estado = '';


let resultadosAnalisis = 0;
let totalSubEtiquetas = 0;

// 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;
}

if (valorAnalizado >= +umbrales[i][0][0] && valorAnalizado <=


+umbrales[i][0][1] && resultadosAnalisis < 1) {
resultadosAnalisis = 1;
}
if (valorAnalizado >= +umbrales[i][1][0] && valorAnalizado <=
+umbrales[i][1][1] && resultadosAnalisis < 2) {
resultadosAnalisis = 2;
}
if (valorAnalizado >= +umbrales[i][2][0] && valorAnalizado <=
+umbrales[i][2][1]) {
resultadosAnalisis = 3;
}
}
}
}
switch (resultadosAnalisis) {
case 1: estado = 'Bien'; break;
case 2: estado = 'Peligro'; break;
case 3: estado = 'Grave'; break;
default: estado = 'SE'; break;
}
return Promise.resolve(estado);
}

addMarker(marker, cultivo: any, map: GoogleMap): void {


const category = marker[4];
const title = marker[1];
const pos = new google.maps.LatLng(marker[2], marker[3]);
const content = marker[1];
const nuevoMarcador = new google.maps.Marker({
title,
position: pos,
category,
map
});

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;
}

cultivo.setOptions({ editable: true, fillColor: color, strokeColor: color });


}

mostrarConfirmarForm() {
this.confirmarForm.show();
}

ocultarConfirmarForm() {
this.confirmarForm.hide();
}

mostrarOpcionesCultivoForm(cultivo: any) {
this.cultivoAux = cultivo;
this.opcionesCultivoForm.show();
}

ocultarOpcionesCultivoForm() {
this.opcionesCultivoForm.hide();
}

addRuta(ruta, mapa: GoogleMap): void {


let color = '';
if (ruta[1] === 'Evaluador') {
color = '#2233AA';
}
if (ruta[1] === 'Aplicador') {
color = '#804000';
}
this.grutas.push(new google.maps.Polyline({
path: ruta[0],
geodesic: true,
strokeColor: color,
editable: true,
strokeOpacity: 1,
strokeWeight: 2,
map: mapa,
tipo: ruta[1],
}
));
}

generarRuta(cultivo, map: GoogleMap) {


let lados;
const nroVertices = cultivo.getPath().length;
if (nroVertices === 4) {
lados = [4][3];
}
}

filtrar(umbralesSeleccionados: string[], cultivosSeleccionados: string[],


filtroPlagaActivo: boolean,
filtroMarcadoresActivo: boolean, rutasSeleccionadas: string[],
cultivosApagados: boolean): void {
let cultivo;
let ruta;
let aprobado = false;
let filtroPlaga = false;
let filtroUmbral = false;
let filtroCultivo = false;
let filtroRuta = false;

let filtroUmbralActivo = true;


let filtroCultivoActivo = true;

// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.gcultivos.length; i++) {
// Obtenemos el cultuvo actual
cultivo = this.gcultivos[i];

// Comparamos filtros semáforo y si encontramos uno salimos del bucle


for (let j = 0; j < umbralesSeleccionados.length; j++) {
if (cultivo.estado === umbralesSeleccionados[j]) {
filtroUmbral = true;
j = umbralesSeleccionados.length;
} else {
filtroUmbral = false;
}
}

for (let j = 0; j < cultivosSeleccionados.length; j++) {


if (cultivo.tipoCultivo === cultivosSeleccionados[j]) {
filtroCultivo = true;
j = cultivosSeleccionados.length;
} else {
filtroCultivo = false;
}
}

// Comparamos plaga de filtro y cultivo


if (filtroPlagaActivo === cultivo.plaga) {
filtroPlaga = false;
} else {
filtroPlaga = true;
}

if (cultivosSeleccionados.length === 0) {
filtroCultivoActivo = false;
}
if (umbralesSeleccionados.length === 0) {
filtroUmbralActivo = false;
}

if (filtroPlagaActivo && !filtroCultivoActivo && !filtroUmbralActivo) {


if (filtroPlaga) {
aprobado = true;
} else {
aprobado = false;
}
} else {
aprobado = true;
}

if (filtroCultivoActivo && !filtroPlagaActivo && !filtroUmbralActivo) {


if (filtroCultivo) {
aprobado = true;
} else {
aprobado = false;
}
} else {
if (!filtroPlagaActivo && !filtroUmbralActivo) {
aprobado = true;
}
}

if (filtroUmbralActivo && !filtroPlagaActivo && !filtroCultivoActivo) {


if (filtroUmbral) {
aprobado = true;
} else {
aprobado = false;
}
} else {
if (!filtroPlagaActivo && !filtroCultivoActivo) {
aprobado = true;
}
}

if (filtroPlagaActivo && !filtroCultivoActivo && filtroUmbralActivo) {


if (filtroPlaga && filtroUmbral) {
aprobado = true;
} else {
aprobado = false;
}
}

if (filtroPlagaActivo && filtroCultivoActivo && !filtroUmbralActivo) {


if (filtroPlaga && filtroCultivo) {
aprobado = true;
} else {
aprobado = false;
}
}

if (filtroPlagaActivo && filtroCultivoActivo && filtroUmbralActivo) {


if (filtroPlaga && filtroCultivo && filtroUmbral) {
aprobado = true;
} else {
aprobado = false;
}
}

if (!filtroPlagaActivo && filtroCultivoActivo && filtroUmbralActivo) {


if (filtroCultivo && filtroUmbral) {
aprobado = true;
} else {
aprobado = 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();
}

// cuando no hay filtros


if (!filtroPlagaActivo && umbralesSeleccionados.length === 0 &&
cultivosSeleccionados.length === 0) {
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.gcultivos.length; i++) {
cultivo = this.gcultivos[i];
// volvemos visibles al cultivo y su marcador
if (filtroMarcadoresActivo) {
this.gmarkers1[i].setVisible(true);
} else {
this.gmarkers1[i].setVisible(false);
}
cultivo.setVisible(true);
}
}
for (let i = 0; i < this.gcultivos.length; i++) {
if (cultivosApagados || umbralesSeleccionados.length === 0 ||
cultivosSeleccionados.length === 0) {
// tslint:disable-next-line: prefer-for-of
// volvemos visibles al cultivo y su marcador
if (filtroMarcadoresActivo && cultivo.visible &&
(umbralesSeleccionados.length === 0 && cultivosSeleccionados.length === 0)) {
this.gmarkers1[i].setVisible(true);
} else {
this.gmarkers1[i].setVisible(false);
}
this.gcultivos[i].setOptions({
fillOpacity: 0
});
} else {
this.gcultivos[i].setOptions({
fillOpacity: 0.5
});
}
}

// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this.grutas.length; i++) {
// Obtenemos el cultuvo actual
ruta = this.grutas[i];

// Comparamos filtros y si encontramos uno salimos del bucle


for (let j = 0; j < rutasSeleccionadas.length; j++) {
if (ruta.tipo === rutasSeleccionadas[j]) {
filtroRuta = true;
j = rutasSeleccionadas.length;
} else {
filtroRuta = false;
}
}

if (filtroRuta) {
ruta.setVisible(true);
} else {
ruta.setVisible(false);
}
}

filtrarSiembras(umbralesSeleccionados: string[], cultivosSeleccionados: string[],


centrosDeCostosSeleccionados: string[]): void {
let cultivo;

let filtroUmbral = false;


let filtroCultivo = false;
let filtroCentroDeCosto = 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];

// Comparamos filtros semáforo y si encontramos uno salimos del bucle


for (let j = 0; j < umbralesSeleccionados.length; j++) {
if (cultivo.estado === umbralesSeleccionados[j]) {
filtroUmbral = true;
j = umbralesSeleccionados.length;
} else {
filtroUmbral = false;
}
}

for (let j = 0; j < cultivosSeleccionados.length; j++) {


if (cultivo.tipoCultivo === cultivosSeleccionados[j]) {
filtroCultivo = true;
j = cultivosSeleccionados.length;
} else {
filtroCultivo = false;
}
}

for (let j = 0; j < centrosDeCostosSeleccionados.length; j++) {


if (cultivo.centrocosto === centrosDeCostosSeleccionados[j]) {
filtroCentroDeCosto = true;
j = centrosDeCostosSeleccionados.length;
} else {
filtroCentroDeCosto = false;
}
}

if (filtroCultivo && filtroUmbral && filtroCentroDeCosto) {


cultivo.setVisible(true);
this.gmarkers1[i].setVisible(true);
} else {
// volvemos invisibles al cultivo y su marcador
cultivo.setVisible(false);
cultivo.infowindow.close();
this.gmarkers1[i].setVisible(false);
}

}
}

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;
}
}

También podría gustarte