import { Component, ViewChild, Injector, Output, EventEmitter, Directive, ViewContainerRef } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { GetOrderStatusTypeForViewDto, OrderStatusTypeDto, GeocodeIdInput, DriverProximityDetails, AcceptProximityInput, ProximityServiceProxy, DriverProximityServiceProxy, AddressIdInput, ControllerRouteDetailServiceProxy, CustomerServiceProxy, GetCurrentDriverLocation } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import { AgmInfoWindow } from '@agm/core'; import { finalize } from 'rxjs/operators'; import { AppSessionService } from '@shared/common/session/app-session.service'; import * as moment from 'moment'; import { lt, result } from 'lodash'; import { ILatLng } from './customer-map.directive'; // the will keep typescript from throwing errors w.r.t the google object declare var google: any; @Component({ selector: 'viewCustomerMapModal', styleUrls: ["./customer-portal.component.css"], templateUrl: './customer-map.component.html' }) export class CustomerMapModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); previousIW: AgmInfoWindow; active = false; saving = false; item: GetCurrentDriverLocation; lat1: number; lat2: number; long1: number; long2: number; lat: number = 34.044971; lng: number = -118.291243; map: any; origin: ILatLng = { latitude: 38.889931, longitude: -77.009003 }; // New York City, NY, USA destination: ILatLng = { latitude: 40.730610, longitude: -73.935242 }; displayDirections = true; zoom = 22; routeCode: string; driverName: string; appSession: AppSessionService; googleMap = null; isEnabledLaboratory: boolean; sameGeocode: boolean; driverPage: boolean; infoWindowOpened = null previous_info_window = null constructor( injector: Injector, private viewContainerRef: ViewContainerRef, private _customerServiceProxy: CustomerServiceProxy, ) { super(injector); this.previousIW = null; } ngOnInit(): void { this.isEnabledLaboratory = abp.features.isEnabled('App.ControllerRouteManagementFeature.RouteDetailsManagementFeature'); } show(orderId: number): void { this.spinnerService.show(); this._customerServiceProxy.getCurrentDriverLocation(orderId) .subscribe(result => { if (result != null) { this.item = result; this.driverName = this.item.driverName; let x: ILatLng = { longitude: this.item.driverLong, latitude: this.item.driverLat, } let y: ILatLng = { longitude: this.item.clinicLong, latitude: this.item.clinicLat, } this.origin = x; this.destination = y; this.lat1 = this.item.driverLat; this.lat2 = this.item.clinicLat; this.long1 = this.item.driverLong; this.long2 = this.item.clinicLong; this.active = true; this.modal.show(); } else { this.message.warn('', 'Failed to load Map'); } this.spinnerService.hide(); }); } close(): void { this.active = false; this.modal.hide(); } mapReady(event?: any) { this.map = event; } getParentComponent() { return this.viewContainerRef['_data'].componentView.component.viewContainerRef['_view'].component } recenterMap(lt, lg) { this.lat = lt; this.lng = lg; this.zoom = 14; } close_window() { if (this.previous_info_window != null) { this.previous_info_window.close() } } select_marker(data, infoWindow) { if (this.previous_info_window == null) this.previous_info_window = infoWindow; else { this.infoWindowOpened = infoWindow this.previous_info_window.close() } this.previous_info_window = infoWindow } }