import { Component, ViewEncapsulation, Injector, OnInit, DoCheck, ViewChild, Input } from "@angular/core"; import { appModuleAnimation } from "@shared/animations/routerTransition"; import { AppComponentBase } from "@shared/common/app-component-base"; import { Router, ActivatedRoute } from "@angular/router"; import * as moment from 'moment'; import { LocationServiceProxy, LocationListDto } from "@shared/service-proxies/service-proxies"; import { MapFlyOutComponent } from "@app/shared/layout/flyout/map/map-flyout.component"; import { empty } from "rxjs"; declare var $: any; @Component({ templateUrl: './locator.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styles:['agm-map {height: 69vh;}'] }) export class LocatorComponent extends AppComponentBase implements OnInit{ todaysDate: Date; @Input() markers: marker[] = []; @Input() latestLog: marker[] = []; @Input() delmarkers: marker[] = []; route: Array = []; active: number; locations: LocationListDto[] = []; filters: { locationFilter: number; statusFilter: number; typeFilter: number; startDate: Date; endDate: Date; } = {}; zoom: number = 8; // initial center position for the map lat: number = 34.044971; lng: number = -118.291243; map: any; pin: { path: string; fillColor: string; fillOpacity: number; strokeColor: string; strokeWeight: number; scale: number; labelOrigin: { x: number; y: number; }; }; @ViewChild('mapFlyOutComponent', {static: false}) mapFlyOutComponent: MapFlyOutComponent; constructor( injector: Injector, private router: Router, private _locationServiceProxy: LocationServiceProxy, private activatedRoute: ActivatedRoute, ) { super(injector); this.todaysDate = new Date(Date.now()); this.filters.startDate = this.todaysDate; this.filters.endDate = this.todaysDate; } ngOnInit(): void { this.activatedRoute.paramMap.subscribe(params => { this.filters.locationFilter = +params.get("location"); this.filters.startDate = new Date(params.get("dateStart")); this.filters.endDate = new Date(params.get("dateEnd")); this.route = [+params.get("id")]; this.active = 1; }) let that = this; this.todaysDate = new Date(Date.now()); this.spinnerService.show(); this.getLocationsOnLoad().then(function(result){ if(that.route[0] != 0){ $('#map_datepicker .form-control').val( moment(that.filters.startDate).format('YYYY-MM-DD') + ' / ' + moment(that.filters.endDate).format('YYYY-MM-DD')); }else{ $('#map_datepicker .form-control').val( moment(that.todaysDate).format('YYYY-MM-DD') + ' / ' + moment(that.todaysDate).format('YYYY-MM-DD')); } $('#hiddenStartDateMap').val(that.filters.startDate); $('#hiddenEndDateMap').val(that.filters.endDate); that.spinnerService.hide(); }); $('#map_datepicker').daterangepicker({ buttonClasses: ' btn', applyClass: 'btn-primary', cancelClass: 'btn-secondary' }, function(start, end, label) { $('#map_datepicker .form-control').val( start.format('YYYY-MM-DD') + ' / ' + end.format('YYYY-MM-DD')); $('#hiddenStartDateMap').val(start.format('YYYY-MM-DD')); $('#hiddenEndDateMap').val(end.format('YYYY-MM-DD')); that.filters.startDate = $('#hiddenStartDateMap').val(); that.filters.endDate = $('#hiddenEndDateMap').val(); }); // $("#locationSelectInputMap").val(that.filters.locationFilter); $('#locationSelectInputMap').on('change', function(){ $("#locationSelectInputMap").val($(this).val()); that.filters.locationFilter = $("#locationSelectInputMap").val(); }); } getLocationsOnLoad() { let that = this; return new Promise(function(resolve, reject){ that._locationServiceProxy.getLocation(undefined, undefined, undefined, undefined, undefined) .subscribe(result => { $('#locationSelectInputMap').select2(); that.locations = result.items; if(that.filters.locationFilter != 0){ $("#locationSelectInputMap").val(that.filters.locationFilter); }else{ that.filters.locationFilter = result.items[0].id; $("#locationSelectInputMap").val(result.items[0].id); resolve(result.items[0].id); } }); }); } // ngDoCheck() { // // ... // console.log(this.filters); // } onChange(event){ console.log(event); } showFlyOut(): void { this.mapFlyOutComponent.loadFlyOut(); } mapReady(event: any) { this.map = event; // this.pin = { // path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z', // fillColor: '#FFF', // fillOpacity: 1, // strokeColor: '#000', // strokeWeight: 1, // scale: 1, // labelOrigin: { x: 0, y: -30 }}; this.markers = []; this.latestLog = []; this.delmarkers = []; } clickedMarker(label: string, index: number) { // console.log(`clicked the marker: ${label || index}`) } } // just an interface for type safety. interface marker { lat: number; lng: number; label?: string; draggable: boolean; icon?: { path: string; fillColor: string; fillOpacity: number; strokeColor: string; strokeWeight: number; scale: number; labelOrigin: { x: number; y: number; } }; driverName: string; orderId:string; eta:string; color?:string; }