import {Component, ViewEncapsulation} from '@angular/core'; import {ApiService} from '../api.service'; import { ChartsConfigService } from './chartConfigs.service'; declare var google: any; interface IDistrictKiev { districtName: String; buildingsCount: Number; } @Component({ selector: 'heating', encapsulation: ViewEncapsulation.None, styles: [require('./heating.scss')], template: require('./heating.html') }) export class Heating { private CHANGE_CHART_TIME: number = 4000; private CHANGE_CHART_MAXUMUM: number = 12; DistrictStatistics: Object[] = []; mapPoint: Object[] = []; OrganizationStatistics: Object[] = []; DistrictWeek: Array = []; DistrictWeekArray: Array = []; DistrictKiev: IDistrictKiev[] = []; DistrictTmp: Object[]; problemPoints: Array = []; freezePoints: Array = []; public chartState: number = 2; ChartCO: Object; ChatrTmp: Object; constructor(private _apiService: ApiService, private _chartsConfigService: ChartsConfigService) { for (let i = 0; i < 10; i++) { this.DistrictWeekArray.push(this.DistrictWeek); this.DistrictWeekArray[i] = []; } for (let i = 0; i < 4; i++) { this.DistrictKiev.push( { districtName: 'Загально по Киеву', buildingsCount: 0 } ); } } changeChart() { if (this.chartState < this.CHANGE_CHART_MAXUMUM - 1) { this.DistrictTmp = this.DistrictWeekArray[this.chartState - 1]; } else { this.DistrictTmp = this.DistrictKiev; } this.chartState++; this.chartState == this.CHANGE_CHART_MAXUMUM ? this.chartState = 1 : false; this.ChartCO = this._chartsConfigService.getChartConfig(this.DistrictTmp); } ngOnInit() { this._apiService.getHeatingPointStates().then(data => { data.forEach(item => { if (item.state == 2) { this.problemPoints.push({ location: new google.maps.LatLng(item.latitude, item.longitude), weight: 2 }); } if (item.state != 2) { this.freezePoints.push({ location: new google.maps.LatLng(item.latitude, item.longitude), weight: 1 }); } }); }) .then(() => { let mapProp = { center: new google.maps.LatLng(50.450090972, 30.523414806), zoom: 12 }; let map = new google.maps.Map(document.getElementById("map"), mapProp); let problemGradient = [ 'rgba(248, 255, 61, 0)', 'rgba(248, 255, 61, 1)', 'rgba(255, 196, 89, 0.85)' ]; let freezeGradient = [ 'rgba(0, 0, 0, 0)', 'rgba(255, 0, 0, 1)', 'rgba(255, 20, 36, 0.75)', 'rgba(255, 20, 36, 0.5)', 'rgba(255, 20, 36, 0.7)', 'rgba(255, 0, 0, 0.75)' ]; let problemmap = new google.maps.visualization.HeatmapLayer({ data: this.problemPoints, map: map, opacity: 1, maxIntensity: 1 }); let freezemap = new google.maps.visualization.HeatmapLayer({ data: this.freezePoints, map: map, opacity: 1, maxIntensity: 1 }); problemmap.set('gradient', problemGradient); problemmap.set('radius', 8); freezemap.set('gradient', freezeGradient); freezemap.set('radius', 8); }); this._apiService.getHeatingDistrictStatistics().then(data => { data.forEach(item => { this.DistrictWeekArray[item.districtId - 1][item.state - 1] = item; this.DistrictKiev[item.state - 1].buildingsCount += item.buildingsCount; }); }) .then(() => { this.DistrictTmp = this.DistrictWeekArray[0]; this.ChartCO = this._chartsConfigService.getChartConfig(this.DistrictTmp); }) .then(() => { setInterval(() => { this.changeChart(); }, this.CHANGE_CHART_TIME); }); this._apiService.getHeatingOrganizationStatistics().then(data => { this.OrganizationStatistics = data; }); } }