diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8c44076..f85abf2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -112,7 +112,7 @@ console.log(token); } } - this.contactService.dealerInfo(this.url == 'localhost:4200' ?'oneqlik.in':this.url ).subscribe( + this.contactService.dealerInfo(this.url == 'localhost:4200' ?'www.oneqlik.in':this.url ).subscribe( data => { this.userData = data diff --git a/src/app/contact.service.ts b/src/app/contact.service.ts index cc6c38f..5f658a9 100644 --- a/src/app/contact.service.ts +++ b/src/app/contact.service.ts @@ -25,7 +25,7 @@ import { map, take } from 'rxjs/operators'; @Injectable() export class ContactService { totalTicketCount:BehaviorSubject = new BehaviorSubject(10); - +latLongAddress={}; dev_url = environment.hostUrl; dev_url2= environment.hostUrl2 //dev_url = 'http://localhost:3000'; @@ -438,7 +438,7 @@ getCurrentLocation(id,from,to){ getCurrentLocation1(id,from,to,satelite){ if(satelite==undefined){ return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to) -.map(res => res.json()); + .map(res => res.json()); } else{ return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to+'&satelite='+satelite) @@ -1637,7 +1637,6 @@ addPOICol(poipayload){ .map(res => res.json()); } - setlanguage(payload){ return this.http.post(this.dev_url +'/users/set_user_setting',payload) .map(res => res.json()); @@ -1650,8 +1649,19 @@ getLanguages(payload){ getAddressByApi(latlng){ + if(this.latLongAddress[latlng.long+'_'+latlng.lat]) { + console.log('get address for cache'); + return Observable.of(this.latLongAddress[latlng.long+'_'+latlng.lat]); + } else { + return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng) + .map(res => res.json()); + } - return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng) + +} +getAddressByApiBulk(latlng){ + + return this.http.post(this.dev_url +'/googleAddress/getGoogleAddressBulk',latlng) .map(res => res.json()); } diff --git a/src/app/device-report/distance-report/distance-report.component.ts b/src/app/device-report/distance-report/distance-report.component.ts index 953ae3a..8d0b238 100644 --- a/src/app/device-report/distance-report/distance-report.component.ts +++ b/src/app/device-report/distance-report/distance-report.component.ts @@ -580,25 +580,43 @@ testTable() { if (that.reportArr.length != 0) { var j = 0; var finalArr = []; - for (var i = 0; i < that.reportArr.length; i++) { - - that.clocation_1(that.reportArr[i], function (err, succ) { - if (err) { - console.log(err); - j++; - } else { - finalArr.push(succ); - console.log(finalArr); - j++; - if (j === that.reportArr.length) { - that.Load = false; - callback({ data: finalArr }); - } + + let latLongArray :any[] = []; + that.reportArr.forEach((deData)=>{ + let latLng = { + lat: deData.startLat ? deData.startLat : 0, + long: deData.startLng ? deData.startLng : 0 + } + latLongArray.push(latLng) + }) + + that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + that.reportArr.forEach((deData,index)=>{ + let latLng = { + lat: deData.startLat ? deData.startLat : 0, + long: deData.startLng ? deData.startLng : 0 } + that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[index]; + that.clocation_1(deData, function (err, succ) { + if (err) { + console.log(err); + j++; + } else { + finalArr.push(succ); + console.log(finalArr); + j++; + if (j === that.reportArr.length) { + that.Load = false; + callback({ data: finalArr }); + } + } + }) }) - - - } + + }) + + + } else { that.Load = false; that.firstcall=true; @@ -792,13 +810,6 @@ tab:any; long: latlngObj.startLng ? latlngObj.startLng : 0 } - - // if () { - // latLng = { - // lat: 0, - // long: 0 - // } - // } outerThis.contactService.getAddressByApi(latLng).subscribe(res => { if (res.message == "Address not found in databse") { diff --git a/src/app/location/location.component.ts b/src/app/location/location.component.ts index e51ca93..f26ad9b 100644 --- a/src/app/location/location.component.ts +++ b/src/app/location/location.component.ts @@ -26,11 +26,11 @@ import { FormControl } from '@angular/forms'; import { ShoRoutePlanComponent } from './sho-route-plan/sho-route-plan.component'; -declare var jsPDF : any; -declare var html2canvas:any +declare var jsPDF: any; +declare var html2canvas: any declare var swal: any; -declare var ol:any; +declare var ol: any; /* import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner'; */ @@ -49,19 +49,20 @@ declare var RadialGauge: any; }) export class LocationComponent implements OnInit, OnDestroy { @ViewChild(SidemenuFuelComponent) child1: SidemenuFuelComponent; - @ViewChild('main')main:ElementRef; + @ViewChild('main') main: ElementRef; modelChanged: Subject = new Subject(); - area=0; + area = 0; toppings = new FormControl(); - isLastPosition =false; + isLastPosition = false; toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato']; imei + latLongAddress={}; // private fuelComponent: SidemenuFuelComponent; - showLabels:boolean=true; - showAddress:boolean=false; + showLabels: boolean = true; + showAddress: boolean = false; showSocketData: boolean = false; - satelliteDisabled:boolean=false - immobilizeChk:boolean = false; + satelliteDisabled: boolean = false + immobilizeChk: boolean = false; testData: any; reloadCOmponent: boolean; mapWidth: string; @@ -102,12 +103,12 @@ export class LocationComponent implements OnInit, OnDestroy { longitudeInDMS: any; toggleGeofence: (choice: any) => void; toggleGeofence1: (choice: any) => void; - enabletrail:boolean = false; + enabletrail: boolean = false; parkingButtonShow; selectedDevice showHistory: boolean = false; togglePOI: (choice: any) => void; - togglePOI1: (choice: any) => void; + togglePOI1: (choice: any) => void; colorTheme = 'theme-dark-blue'; last_speed: string; DealerID: any; @@ -140,9 +141,9 @@ export class LocationComponent implements OnInit, OnDestroy { navId: String; deviceList: any = []; to: string; - tab_1 : boolean =false; - tab_2:boolean =false; - tab_3:boolean= false; + tab_1: boolean = false; + tab_2: boolean = false; + tab_3: boolean = false; from: string; total_vech: any; idle_vech: any; @@ -150,7 +151,7 @@ export class LocationComponent implements OnInit, OnDestroy { maintanance: any; expiredDevices: any; OutOfReach: any; - totalDevices:any; + totalDevices: any; no_data: any; Running: any; idle_duration: any; @@ -183,36 +184,36 @@ export class LocationComponent implements OnInit, OnDestroy { liveLocationMarkerObj: any; darkModeSwitch: boolean = false; tttttt: any = []; - tabIndexValue: any = "0"; - tempDevInfo: any; - cummulative_Distance: number =0; - token_identifier: string; - contentAdd: string; - historyAdress: any = ''; - gpsDataArr: any; - ext_voltage: any; - seekBarValue: any=200; - sliderValue: number = 0; - indexValue: any; - status_cmdq: any; - intervalTimeOut:any; - immobilizeCount: number; - ImmErrMsg: string; - showErr: boolean =false; - unlocked: boolean =false; - errIcon:boolean=false; - locked: boolean=false; - shoError:any; - private socket_Notify; - dealer_Permission: any; - adbtn: string; - markerArray: any; - satelite=5; - dataSelect2:any; - newArr=[{"value":"1"},{"value":"2"},{"value":"3"},{"value":"4"},{"value":"5"},{"value":"6"},{"value":"7"},{"value":"8"},{"value":"9"}, - {"value":"10"},{"value":"11"},{"value":"12"},{"value":"13"},{"value":"14"},{"value":"15"}] - distanceVariation: any; - digitalInput: any; + tabIndexValue: any = "0"; + tempDevInfo: any; + cummulative_Distance: number = 0; + token_identifier: string; + contentAdd: string; + historyAdress: any = ''; + gpsDataArr: any; + ext_voltage: any; + seekBarValue: any = 200; + sliderValue: number = 0; + indexValue: any; + status_cmdq: any; + intervalTimeOut: any; + immobilizeCount: number; + ImmErrMsg: string; + showErr: boolean = false; + unlocked: boolean = false; + errIcon: boolean = false; + locked: boolean = false; + shoError: any; + private socket_Notify; + dealer_Permission: any; + adbtn: string; + markerArray: any; + satelite = 5; + dataSelect2: any; + newArr = [{ "value": "1" }, { "value": "2" }, { "value": "3" }, { "value": "4" }, { "value": "5" }, { "value": "6" }, { "value": "7" }, { "value": "8" }, { "value": "9" }, + { "value": "10" }, { "value": "11" }, { "value": "12" }, { "value": "13" }, { "value": "14" }, { "value": "15" }] + distanceVariation: any; + digitalInput: any; myaccount() { this.cond = false @@ -226,7 +227,7 @@ export class LocationComponent implements OnInit, OnDestroy { // dialogRef.afterClosed().subscribe(result => { // if(result == "succ"){ - // console.log("Updated") + // console.log("Updated") // } // }); @@ -235,15 +236,15 @@ export class LocationComponent implements OnInit, OnDestroy { filterStates1(val) { // console.log("===>",val) if (val) { - const filterValue: any = val ; 1 + const filterValue: any = val; 1 this.dataSelect2 = this.newArr.filter(function (d) { - // console.log("inside Search Method=>",d); - return d.value.toLocaleLowerCase().indexOf(filterValue.toLocaleLowerCase())>-1; + // console.log("inside Search Method=>",d); + return d.value.toLocaleLowerCase().indexOf(filterValue.toLocaleLowerCase()) > -1; }); - if(this.dataSelect2.length!=0){ - this.satelite=val - // console.log("searched model=>",this.dataSelect2,"----------",this.satelite); - } + if (this.dataSelect2.length != 0) { + this.satelite = val + // console.log("searched model=>",this.dataSelect2,"----------",this.satelite); + } return this.dataSelect2; } } @@ -328,7 +329,7 @@ export class LocationComponent implements OnInit, OnDestroy { else if (divid == "shrlcnd") { this.data_descip = "Please Select any Device"; launch_toast(); - }else if(divid === 'added'){ + } else if (divid === 'added') { this.data_descip = "Device added"; launch_toast(); } @@ -805,7 +806,7 @@ export class LocationComponent implements OnInit, OnDestroy { deviceToTrack = [] live(b) { // console.log(b); - + this.mappp = true; this.MapLoad = true; this.historyData = false @@ -832,18 +833,18 @@ export class LocationComponent implements OnInit, OnDestroy { // } // console.log('devId=>',devId); if (devId) { - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("11111111111111"); - + this.livetrack(devId); } - + } else { - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("111111111112222"); this.livetrack(null); } - + } } cancells() { @@ -859,8 +860,8 @@ export class LocationComponent implements OnInit, OnDestroy { //Main Declaration of LiveTrack Function ********************* livetrack(a) { // console.log("ID==========",a); - this.markerArray=[]; - var count =0 ; + this.markerArray = []; + var count = 0; var that = this; this.SpeedMeter2 = false this.PlayData = false; @@ -882,7 +883,7 @@ export class LocationComponent implements OnInit, OnDestroy { this.socket.removeAllListeners(this.deviceToTrack[e]) } this.deviceToTrack = []; - + for (let i = 0; i < this.foods.length; i++) { if (this.foods[i].deviceType == "Tracker") { @@ -938,7 +939,7 @@ export class LocationComponent implements OnInit, OnDestroy { let flag2; let locations = [] // =============== ~animation functions ===================== - + var carIcon = { // path: car, url: '/assets/images/liveTrackIcons/rcar.png', @@ -1000,7 +1001,7 @@ export class LocationComponent implements OnInit, OnDestroy { strokeColor: 'white', strokeWeight: .10, fillOpacity: 1, - fillColor: 'blue', + fillColor: 'blue', //fillColor: '#b75656', offset: '5%', // rotation: parseInt(heading[i]), @@ -1115,16 +1116,16 @@ export class LocationComponent implements OnInit, OnDestroy { "tractor": tractorIcon, "bus": busIcon, "user": userIcon, - "jcb" : jcbIcon, - "ambulance" : ambulanceIcon - + "jcb": jcbIcon, + "ambulance": ambulanceIcon + } // console.log('deviceListdeviceListdeviceListdeviceList',this.deviceToTrack); this.flightPathArr = []; this.tttttt = []; - var tempTimeInterval:any; + var tempTimeInterval: any; // console.log("Runnig ON Change"); @@ -1144,7 +1145,7 @@ export class LocationComponent implements OnInit, OnDestroy { } } - + for (var x = 0; x < this.deviceToTrack.length; x++) { var newChannel = this.deviceToTrack[x].toString(); var date = new Date().setHours(0, 0, 0, 0) @@ -1152,39 +1153,39 @@ export class LocationComponent implements OnInit, OnDestroy { this.socket.emit('initLive', newChannel, date); //console.log("newChannel",newChannel,"date",date); - + } - + var r function channelListener(newChannel) { return function (msg, initData, deviceInfo) { - + outerThis.tempDevInfo = {}; - outerThis.flightPathArr.push({ lat: msg.latDecimal, lng: msg.longDecimal }); - if(outerThis.enabletrail == true){ + outerThis.flightPathArr.push({ lat: msg.latDecimal, lng: msg.longDecimal }); + if (outerThis.enabletrail == true) { outerThis.draw_flight_trail(outerThis.flightPathArr); } - - // console.log('device object coming from service',outerThis.deviceList) + + // console.log('device object coming from service',outerThis.deviceList) // if((a != null) && (a != undefined)&&(outerThis.navId != 'locationComponent')){ // if (deviceInfo.status != 'RUNNING') { // outerThis.addressConversion(msg); // } - + // }else{ - // console.log('no address api call'); + // console.log('no address api call'); // } // console.log('outerThis.deviceList',outerThis.deviceList); outerThis.deviceList.filter(function (dd, index) { - - if(dd.Device_ID === deviceInfo.Device_ID){ - deviceInfo['checked'] = dd.checked; - } + + if (dd.Device_ID === deviceInfo.Device_ID) { + deviceInfo['checked'] = dd.checked; + } }) // console.log('1345678909876543267898765432345676543=>',deviceInfo.checked); - + if (outerThis.deviceToTrack.length == 1) { outerThis.deviceList.filter(function (colHilight, i) { outerThis.deviceList[i]['playPause'] = true; @@ -1202,33 +1203,33 @@ export class LocationComponent implements OnInit, OnDestroy { if (msg.speed) { outerThis.deviceList[i].last_speed = msg.speed; } - - + + if (outerThis.currentPage === 1) { outerThis.showSocketData = true; // console.log({"colHilight=>":colHilight}); - + // console.log({"msg=>":msg}); outerThis.showSocketData = true; // date satellites ignition port - if(msg.date== undefined){ + if (msg.date == undefined) { msg['date'] = colHilight.last_ping_on } - if(msg.satellites == undefined){ + if (msg.satellites == undefined) { msg['satellites'] = colHilight.satellites } - if(msg.ignition == undefined){ - msg['ignition'] = colHilight.last_ACC ; + if (msg.ignition == undefined) { + msg['ignition'] = colHilight.last_ACC; } - if(msg.port == undefined){ - msg['port'] = colHilight.port ; + if (msg.port == undefined) { + msg['port'] = colHilight.port; } - + outerThis.socketData = msg; outerThis.getSystemLogs(colHilight); outerThis.deviceCQ(colHilight); @@ -1239,31 +1240,32 @@ export class LocationComponent implements OnInit, OnDestroy { } }) - + } this.lat = deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[1] : null; this.lng = deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[0] : null; - + r = 0 if (coords[newChannel] === null || coords[newChannel] === undefined) coords[newChannel] = []; outerThis.mainmap = true; if (initData == 'ping' || (initData == 'initPing' && coords[newChannel].length == 0)) { // console.log('deviceInfo=>',deviceInfo); // addressConversion====================================================== - if(outerThis.navId != 'locationComponent'){ - outerThis.liveAdd =''; - outerThis.tempDevInfo = deviceInfo ; - - let d_lat = msg.latDecimal?msg.latDecimal : deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[1] : null; - let d_lng = msg.longDecimal?msg.longDecimal : deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[0] : null; - + if (outerThis.navId != 'locationComponent') { + outerThis.liveAdd = ''; + outerThis.tempDevInfo = deviceInfo; + + let d_lat = msg.latDecimal ? msg.latDecimal : deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[1] : null; + let d_lng = msg.longDecimal ? msg.longDecimal : deviceInfo.last_loc ? deviceInfo.last_loc.coordinates[0] : null; + var latlng_1 = { "lat": d_lat, - "long": d_lng + "long": d_lng } - outerThis.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - if(res.message == "Address not found in databse"){ + + outerThis.contactService.getAddressByApi(latlng_1).subscribe(res => { + if (res.message == "Address not found in databse") { let geocoder = new google.maps.Geocoder(); let t_latlng = new google.maps.LatLng(d_lat, d_lng); @@ -1275,29 +1277,29 @@ export class LocationComponent implements OnInit, OnDestroy { if (data[0] != null) { outerThis.liveAdd = data[0].formatted_address; // console.log(outerThis.liveAdd); - outerThis.saveAddress(d_lat, d_lng,outerThis.liveAdd) + outerThis.saveAddress(d_lat, d_lng, outerThis.liveAdd) } else { // console.log("No address available") outerThis.liveAdd = "No address available"; } } else { - + outerThis.liveAdd = 'NA'; - - + + } - + }) - }else{ - + } else { + outerThis.liveAdd = res.address; } // console.log("ADDRESS---->",outerThis.liveAdd); - + }) } - + // addressConversion========================================================= this.latLongArr = []; @@ -1308,13 +1310,13 @@ export class LocationComponent implements OnInit, OnDestroy { } outerThis.MapLoad = false outerThis.test_Data = msg.currentFuel; - + var x = msg.speed; const heading = parseFloat(msg.heading); const message = 'IMEI: ' + msg.imei + ' Speed: ' + msg.speed + 'Km/hr'; if (msg.interpolated == null || msg.interpolated === undefined) { - + this.lat = msg.latDecimal; this.lng = msg.longDecimal; // console.log("lat long= >",this.lat,this.lng); @@ -1325,28 +1327,28 @@ export class LocationComponent implements OnInit, OnDestroy { did: msg.imei } - if((a != null) && (a != undefined)&&(outerThis.navId != 'locationComponent')){ + if ((a != null) && (a != undefined) && (outerThis.navId != 'locationComponent')) { var geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(msg.latDecimal, msg.longDecimal); - + } - + var request = { latLng: latlng }; - - var latlng_1 = - { - "lat": msg.latDecimal, - "long": msg.longDecimal - } - - + var latlng_1 = + { + "lat": msg.latDecimal, + "long": msg.longDecimal + } + + + //address function end here } else { - + for (let k = 0; k < msg.interpolated.length; k++) { if (msg.interpolated[k].location.latitude == null || msg.interpolated[k].location.longitude == null) { // console.log("Lattitude Longitude if location.lattitude is null=>",msg.interpolated[k].location.latitude,msg.interpolated[k].location.longitude); @@ -1375,7 +1377,7 @@ export class LocationComponent implements OnInit, OnDestroy { // converting Address - + var geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(msg.latDecimal, msg.longDecimal); @@ -1385,73 +1387,73 @@ export class LocationComponent implements OnInit, OnDestroy { - + var latlng_1 = { "lat": msg.latDecimal, - "long": msg.longDecimal + "long": msg.longDecimal } // if((a != null) && (a != undefined) &&(outerThis.navId != 'locationComponent')){ // outerThis.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - + // if(res.message == "Address not found in databse"){ // geocoder.geocode(request, function (data, status) { // if (status == google.maps.GeocoderStatus.OK) { // if (data[0] != null) { // outerThis.liveAdd = data[0].formatted_address; - console.log(outerThis.liveAdd); + console.log(outerThis.liveAdd); // outerThis.saveAddress(msg.latDecimal, msg.longDecimal,outerThis.liveAdd) // } else { - console.log("No address available") + console.log("No address available") // outerThis.liveAdd = "No address available"; // } // } // else { - + // outerThis.liveAdd = 'NA'; - - + + // } - + // }) // }else{ - + // outerThis.liveAdd = res.address; // } // }) // } - - + + //address function end here } } - + var boxCheck = deviceInfo.checked; // that.socketData=deviceInfo; // console.log('checkbox value coming from =>',deviceInfo,boxCheck); if (!isMapInit) { - - initialize(this.lat, this.lng, newChannel); - - + + initialize(this.lat, this.lng, newChannel); + + } // console.log(boxCheck); - - if(boxCheck === true){ - initializeMarker(that.elementRef, this.lat, this.lng, newChannel, deviceInfo.Device_Name, deviceInfo.status, deviceInfo.status_updated_at, deviceInfo.last_ping_on, msg, initData, deviceInfo.iconType, deviceInfo); - } - - + + if (boxCheck === true) { + initializeMarker(that.elementRef, this.lat, this.lng, newChannel, deviceInfo.Device_Name, deviceInfo.status, deviceInfo.status_updated_at, deviceInfo.last_ping_on, msg, initData, deviceInfo.iconType, deviceInfo); + } + + if ((initData == 'ping') || (status == 'RUNNING')) { - if(boxCheck === true){ + if (boxCheck === true) { animateMarker(that.elementRef, marker, speed, heading, true, newChannel, deviceInfo.Device_Name, deviceInfo.status, deviceInfo.status_updated_at, deviceInfo.last_ping_on, msg, initData, deviceInfo.iconType, deviceInfo); } - + } flag = false; } @@ -1467,7 +1469,7 @@ export class LocationComponent implements OnInit, OnDestroy { // console.log('lastPingOn=>',_devInfo.last_ping_on) - + // console.log('statusstatusstatusstatusstatus=>', status); var deviceSpeed = (status == 'STOPPED') ? 0 : msg.speed; @@ -1542,12 +1544,12 @@ export class LocationComponent implements OnInit, OnDestroy { var lastLat = _devInfo.last_location.lat; var lastlong = _devInfo.last_location.long; // console.log("INDDDDDDDDDDDDDDDDDDDDDDDDDDDDEH"); - + contentString = '
' + - '
'+ - '' + + '
' + + '' + '

' + deviceName + '

' + - '
'+ + '
' + '
' + '
' + "Last updated" + @@ -1577,7 +1579,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Name" + '
' + '
' + - '

' + (outerThis.DriverName?outerThis.DriverName:'NA') + '

' + + '

' + (outerThis.DriverName ? outerThis.DriverName : 'NA') + '

' + '
' + '
' + '
' + @@ -1585,7 +1587,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Number" + '
' + '
' + - '

' + (outerThis.DriverNumber?outerThis.DriverNumber:'NA') + '

' + + '

' + (outerThis.DriverNumber ? outerThis.DriverNumber : 'NA') + '

' + '
' + '
' + '
' + @@ -1603,8 +1605,8 @@ export class LocationComponent implements OnInit, OnDestroy { '
' + '

' + deviceData + '

' + '
' + - '
' - + '' + } else if (initData == 'ping') { @@ -1614,10 +1616,10 @@ export class LocationComponent implements OnInit, OnDestroy { var lastlong = _devInfo.last_location.long; contentString = "" contentString = '
' + - '
'+ - '' + - '

' + deviceName + '

' + - '
'+ + '
' + + '' + + '

' + deviceName + '

' + + '
' + '
' + '
' + "Last updated" + @@ -1647,7 +1649,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Name" + '
' + '
' + - '

' + ( outerThis.DriverName?outerThis.DriverName:'NA') + '

' + + '

' + (outerThis.DriverName ? outerThis.DriverName : 'NA') + '

' + '
' + '
' + '
' + @@ -1655,7 +1657,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Number" + '
' + '
' + - '

' + (outerThis.DriverNumber?outerThis.DriverNumber:'NA') + '

' + + '

' + (outerThis.DriverNumber ? outerThis.DriverNumber : 'NA') + '

' + '
' + '
' + '
' + @@ -1673,9 +1675,9 @@ export class LocationComponent implements OnInit, OnDestroy { '
' + '

' + deviceData + '

' + '
' + - '
' - // '' + - // '' + '' + // '' + + // '' // '
Device : ' // + deviceName + ' (' + device + ')

Last Updated : ' @@ -1687,13 +1689,13 @@ export class LocationComponent implements OnInit, OnDestroy { // + '

' } - + marker[device]['infowindow'].setContent(contentString); // console.log("Inside Infowindow"); - + function goToPoint() { // console.log("Inside function!!!") - + let lat = marker[device].position.lat(); let lng = marker[device].position.lng(); // tslint:disable-next-line:prefer-const @@ -1731,53 +1733,53 @@ export class LocationComponent implements OnInit, OnDestroy { function moveMarker() { // console.log("deltaLat",deltaLat,"deltaLng",deltaLng); - + lat += deltaLat; lng += deltaLng; - + i += step; let markerDOM: any; var liveSpeed = parseInt(msg.speed); if (i < distance) { - + if (status == "OUT OF REACH") { // icons[iconType].url = '/assets/images/liveTrackIcons/outofreach_car.png'; icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - } else if (status == "STOPPED") { - if(liveSpeed >= 1){ + } else if (status == "STOPPED") { + if (liveSpeed >= 1) { icons[iconType].url = "/assets/images/liveTrackIcons/running_car.png"; - markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - }else{ + markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); + } else { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); } - + } else if (status == "RUNNING") { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - } else if (status == "NO DATA") { + } else if (status == "NO DATA") { icons[iconType].url = "/assets/image/no_data.png"; - markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); + markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); } else if (status == "IDLING") { - - if(liveSpeed >= 1){ + + if (liveSpeed >= 1) { icons[iconType].url = "/assets/images/liveTrackIcons/running_car.png"; markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - }else{ + } else { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); } - + } - + // console.log(msg.ignition, ) // _devInfo var head = google.maps.geometry.spherical.computeHeading(marker[device].getPosition(), new google.maps.LatLng(lat, lng)); // console.log("HEAD__===",head,"Marker==>",marker[device].getPosition(),"LAT LONG=>",new google.maps.LatLng(lat, lng),"==>",lat,lng); - + if ((head != 0) || (head == NaN)) { // icons[iconType].rotation = head; if (markerDOM) { @@ -1815,31 +1817,31 @@ export class LocationComponent implements OnInit, OnDestroy { // icons[iconType].url = '/assets/images/liveTrackIcons/outofreach_car.png'; icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - } else if (status == "STOPPED") { - if(liveSpeed >= 1){ + } else if (status == "STOPPED") { + if (liveSpeed >= 1) { icons[iconType].url = "/assets/images/liveTrackIcons/running_car.png"; markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - }else{ + } else { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); } - + } else if (status == "RUNNING") { // icons[iconType].url = "/assets/images/liveTrackIcons/running_car.png"; icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - } else if (status == "NO DATA") { + } else if (status == "NO DATA") { icons[iconType].url = "/assets/image/no_data.png"; - markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - }else if (status == "IDLING") { - if(liveSpeed >= 1){ + markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); + } else if (status == "IDLING") { + if (liveSpeed >= 1) { icons[iconType].url = "/assets/images/liveTrackIcons/running_car.png"; markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - }else{ - icons[iconType].url = that.iconSelector(status, iconType, msg); - markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); + } else { + icons[iconType].url = that.iconSelector(status, iconType, msg); + markerDOM = elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); } - + } // ========================= commented on 1-4-2019 ================================ // console.log('STATUS2==>',status); @@ -1854,7 +1856,7 @@ export class LocationComponent implements OnInit, OnDestroy { // } // ========================= commented on 1-4-2019 ================================ - + var head = google.maps.geometry.spherical.computeHeading(marker[device].getPosition(), dest) // console.log("head : " + marker[device].getPosition() + ',' + dest) if ((head != 0) || (head == NaN)) { @@ -1910,36 +1912,38 @@ export class LocationComponent implements OnInit, OnDestroy { function initialize(lat, long, device) { // initialize: (lat, long, device)=> { - if(outerThis.showAddress){ + if (outerThis.showAddress) { // console.log("!isMapInit=______________________________________________________________________________________-----------",isMapInit); var latlng_1 = - { - "lat": lat, - "long": long - } - outerThis.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - if(res.message == "Address not found in databse"){ - let geocoder = new google.maps.Geocoder(); - let t_latlng = new google.maps.LatLng(lat, long); - - let request = { - latLng: t_latlng - }; - geocoder.geocode(request, function (data, status) { - if (status == google.maps.GeocoderStatus.OK) { - if (data[0] != null) { - outerThis.liveAdd = data[0].formatted_address; - }else{ - outerThis.liveAdd ="N/A" - } - } - }) - }else{ - outerThis.liveAdd= res.address; - } - outerThis.showAddress=false - }) + { + "lat": lat, + "long": long + } + // on socket call + + outerThis.contactService.getAddressByApi(latlng_1).subscribe(res => { + if (res.message == "Address not found in databse") { + let geocoder = new google.maps.Geocoder(); + let t_latlng = new google.maps.LatLng(lat, long); + + let request = { + latLng: t_latlng + }; + geocoder.geocode(request, function (data, status) { + if (status == google.maps.GeocoderStatus.OK) { + if (data[0] != null) { + outerThis.liveAdd = data[0].formatted_address; + } else { + outerThis.liveAdd = "N/A" + } + } + }) + } else { + outerThis.liveAdd = res.address; + } + outerThis.showAddress = false + }) } // console.log("Lattitude Longitude", lat ,long,device,outerThis.liveAdd); @@ -2106,9 +2110,9 @@ export class LocationComponent implements OnInit, OnDestroy { map.setZoom(parseInt(this.value)); } - - - + + + google.maps.event.addListener(map, 'zoom_changed', function (event) { // console.log("event" + event); @@ -2262,7 +2266,7 @@ export class LocationComponent implements OnInit, OnDestroy { }); allSourceDestinationMarkers.push(marker); // console.log(allSourceDestinationMarkers); - + var destinationIcon = "http://www.googlemapsmarkers.com/v1/D/" + "FF3300" + "/FFFFFF/000000/ ";//colorForPath var pinImage1 = new google.maps.MarkerImage(destinationIcon); @@ -2337,7 +2341,7 @@ export class LocationComponent implements OnInit, OnDestroy { "lng": pois[i].poi.location.coordinates[0] }); - var poiIcon="/assets/images/liveTrackIcons/building.jpg" + var poiIcon = "/assets/images/liveTrackIcons/building.jpg" // var poiIcon="https://img.icons8.com/ios-filled/50/000000/building-with-rooftop-terrace.png" // building.jpeg // var poiIcon = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png"; @@ -2352,35 +2356,35 @@ export class LocationComponent implements OnInit, OnDestroy { poiMarkers.push(marker); var infobox_numberPlate = new InfoBox({ - content: "
" + pois[i].poi.poiname + "
", - disableAutoPan: false, - maxWidth: 150, - alignBottom: true, - pixelOffset: new google.maps.Size(-25, -20), - zIndex: null, - boxStyle: { - opacity: 1, - zIndex: 999, - width: "auto", - padding: "2px" - }, - closeBoxURL: "", - infoBoxClearance: new google.maps.Size(1, 1) - }); + content: "
" + pois[i].poi.poiname + "
", + disableAutoPan: false, + maxWidth: 150, + alignBottom: true, + pixelOffset: new google.maps.Size(-25, -20), + zIndex: null, + boxStyle: { + opacity: 1, + zIndex: 999, + width: "auto", + padding: "2px" + }, + closeBoxURL: "", + infoBoxClearance: new google.maps.Size(1, 1) + }); - infobox_numberPlate.open(map, marker); + infobox_numberPlate.open(map, marker); - // var infoWindow = new google.maps.InfoWindow; + // var infoWindow = new google.maps.InfoWindow; - - // var contentString = ''+pois[i].poi.poiname+'' - // infoWindow.setContent(contentString); - // infoWindow.setPosition(poiData[0]); - // infoWindow.open(map); + // var contentString = ''+pois[i].poi.poiname+'' + // infoWindow.setContent(contentString); + // infoWindow.setPosition(poiData[0]); + + // infoWindow.open(map); } @@ -2396,8 +2400,8 @@ export class LocationComponent implements OnInit, OnDestroy { function initializeMarker(elementRef, lat, long, device, deviceName, status, since, lastUpdatedTime, msg, initData, iconType, _devInfo) { // console.log("Initialize marker called"); // console.log("Vehicle Speed",msg.speed); - - + + outerThis.latToPass = lat; outerThis.longToPass = long; @@ -2409,37 +2413,37 @@ export class LocationComponent implements OnInit, OnDestroy { // if((a != null) && (a != undefined)&&(outerThis.navId != 'locationComponent')){ // var geocoder = new google.maps.Geocoder(); // var latlng = new google.maps.LatLng(lat, long); - + // var request = { // latLng: latlng // }; - console.log("staticLatLongVal", lat, long) - - + console.log("staticLatLongVal", lat, long) + + // geocoder.geocode(request, function (data, status) { - + // if (status == google.maps.GeocoderStatus.OK) { // if (data[0] != null) { // liveAddress = data[0].formatted_address; // var add = liveAddress; - + // } else { - + // liveAddress = "No address available"; // } // } // else { - + // liveAddress = 'static address'; - - + + // } - + // }) // } - - + + // ======================================Converting Address============================================================== @@ -2505,8 +2509,8 @@ export class LocationComponent implements OnInit, OnDestroy { } - // console.log(marker[device]); - // console.log(marker); + // console.log(marker[device]); + // console.log(marker); if (marker[device] == null || marker[device] == undefined) { // var lastPing = new Date(_devInfo.last_ping_on).getTime(); @@ -2537,30 +2541,30 @@ export class LocationComponent implements OnInit, OnDestroy { if ((icons[iconType] != null) || (icons[iconType] != undefined)) { if (status == "OUT OF REACH") { icons[iconType].url = that.iconSelector(status, iconType, msg); - - + + // markerDOM = elementRef.nativeElement.querySelector("img[src='/assets/images/liveTrackIcons/outofreach_car.png']"); } else if (status == "STOPPED") { - - icons[iconType].url = that.iconSelector(status, iconType, msg); - - - + + icons[iconType].url = that.iconSelector(status, iconType, msg); + + + // markerDOM = elementRef.nativeElement.querySelector("img[src='/assets/images/liveTrackIcons/stopped_car.png']"); } else if (status == "RUNNING") { icons[iconType].url = that.iconSelector(status, iconType, msg); - - + + // markerDOM = elementRef.nativeElement.querySelector("img[src='/assets/images/liveTrackIcons/running_car.png']"); } else if (status == "NO DATA") { icons[iconType].url = that.iconSelector(status, iconType, msg); - - + + // markerDOM = elementRef.nativeElement.querySelector("img[src='/assets/images/liveTrackIcons/running_car.png']"); } else if (status == "IDLING") { - icons[iconType].url = that.iconSelector(status, iconType, msg); - - + icons[iconType].url = that.iconSelector(status, iconType, msg); + + // markerDOM = elementRef.nativeElement.querySelector("img[src='/assets/images/liveTrackIcons/idle_car.png']"); } } @@ -2580,7 +2584,7 @@ export class LocationComponent implements OnInit, OnDestroy { var m = new google.maps.Marker({ position: new google.maps.LatLng(lat, long), map: map, - icon: icons[iconType], + icon: icons[iconType], }); @@ -2593,28 +2597,28 @@ export class LocationComponent implements OnInit, OnDestroy { // } // outerThis.markerArray.push(mtemp); // console.log('marker Temp array=>',outerThis.markerArray); - + // var sec_last_lat = _devInfo.sec_last_location?_devInfo.sec_last_location.lat:null; // var sec_last_lng = _devInfo.sec_last_location?_devInfo.sec_last_location.long:null; - var Initial_head = _devInfo?parseFloat(_devInfo.heading) : 0; + var Initial_head = _devInfo ? parseFloat(_devInfo.heading) : 0; // var Initial_head = google.maps.geometry.spherical.computeHeading(new google.maps.LatLng(sec_last_lat,sec_last_lng),new google.maps.LatLng(lat,long)); // console.log('Initial_head',Initial_head); - - if(count == 0){ + + if (count == 0) { var marker_init = setTimeout(function () { - var markerDOM_temp = that.elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - if(markerDOM_temp){ + var markerDOM_temp = that.elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); + if (markerDOM_temp) { markerDOM_temp.style.transform = 'rotate(' + Initial_head + 'deg)'; - count = 1 ; + count = 1; clearTimeout(marker_init); - } - - }, 2000) + } + + }, 2000) } - var infobox_numberPlate - if( outerThis.showLabels){ + var infobox_numberPlate + if (outerThis.showLabels) { // console.log("HOWWWWWWWWWWW"); - + infobox_numberPlate = new InfoBox({ content: "
" + deviceName + "
", disableAutoPan: false, @@ -2632,10 +2636,10 @@ export class LocationComponent implements OnInit, OnDestroy { infoBoxClearance: new google.maps.Size(1, 1) }); - }else{ + } else { // console.log("NHOWWWWWWWWWWW"); infobox_numberPlate = new InfoBox({ - content:'', + content: '', disableAutoPan: false, maxWidth: 150, alignBottom: true, @@ -2664,7 +2668,7 @@ export class LocationComponent implements OnInit, OnDestroy { } else { gsm_signal = _devInfo.gsmSignal; } - + @@ -2672,10 +2676,10 @@ export class LocationComponent implements OnInit, OnDestroy { var contentString = '' if (initData == 'initPing') { contentString = '
' + - '
'+ - ''+ - '

' + deviceName + '

' + - '
'+ + '
' + + '' + + '

' + deviceName + '

' + + '
' + '
' + '
' + "Last updated" + @@ -2705,7 +2709,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Name" + '
' + '
' + - '

' + (outerThis.DriverName?outerThis.DriverName:'NA') + '

' + + '

' + (outerThis.DriverName ? outerThis.DriverName : 'NA') + '

' + '
' + '
' + '
' + @@ -2713,7 +2717,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Number" + '
' + '
' + - '

' + (outerThis.DriverNumber?outerThis.DriverNumber:'NA') + '

' + + '

' + (outerThis.DriverNumber ? outerThis.DriverNumber : 'NA') + '

' + '
' + '
' + '
' + @@ -2731,14 +2735,14 @@ export class LocationComponent implements OnInit, OnDestroy { '
' + '

' + deviceData + '

' + '
' + - '
' - - // '
'+ - // '
'+ - // '

'+'StreetView Content'+'

'+ - // +'
' + '
' - // '' + // '
'+ + // '
'+ + // '

'+'StreetView Content'+'

'+ + // +'
' + + // '' } else if (initData == 'ping') { @@ -2746,10 +2750,10 @@ export class LocationComponent implements OnInit, OnDestroy { outerThis.last_speed = msg.speed; contentString = '' contentString = '
' + - '
'+ - ''+ - '

' + deviceName + '

' + - '
'+ + '
' + + '' + + '

' + deviceName + '

' + + '
' + '
' + '
' + "Last updated" + @@ -2779,7 +2783,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Name" + '
' + '
' + - '

' + (outerThis.DriverName?outerThis.DriverName:'NA') + '

' + + '

' + (outerThis.DriverName ? outerThis.DriverName : 'NA') + '

' + '
' + '
' + '
' + @@ -2787,7 +2791,7 @@ export class LocationComponent implements OnInit, OnDestroy { "Driver's Number" + '
' + '
' + - '

' + (outerThis.DriverNumber?outerThis.DriverNumber:'NA') + '

' + + '

' + (outerThis.DriverNumber ? outerThis.DriverNumber : 'NA') + '

' + '
' + '
' + '
' + @@ -2805,14 +2809,14 @@ export class LocationComponent implements OnInit, OnDestroy { '
' + '

' + deviceData + '

' + '
' + - '
' - - // '
'+ - // '
'+ - // '

'+'StreetView Content'+'

'+ - // +'
' + '' - // '' + // '
'+ + // '
'+ + // '

'+'StreetView Content'+'

'+ + // +'
' + + // '' } @@ -2821,7 +2825,7 @@ export class LocationComponent implements OnInit, OnDestroy { var myOptions = { content: contentString , disableAutoPan: false - + , maxWidth: 0 , pixelOffset: new google.maps.Size(-18, -25) , zIndex: null @@ -2842,22 +2846,22 @@ export class LocationComponent implements OnInit, OnDestroy { , alignBottom: true }; m['infowindow'] = new InfoBox(myOptions); - // console.log("Infowindow card",m); + // console.log("Infowindow card",m); var mtemp = { - marker : m, + marker: m, imei: _devInfo.Device_ID, - icon :icons[iconType], + icon: icons[iconType], lat: lat, - lng:long, - infowindow : new InfoBox(myOptions), - number_plate : infobox_numberPlate + lng: long, + infowindow: new InfoBox(myOptions), + number_plate: infobox_numberPlate } outerThis.markerArray.push(mtemp); google.maps.event.addListener(m, 'click', function () { // console.log('Opening Infow window',m); // { lat: , lng: } - var fenway = { lat: m.position.lat(), lng: m.position.lng() }; + var fenway = { lat: m.position.lat(), lng: m.position.lng() }; // console.log("latlnglitrals",m.position.lat(),m.position.lng()); // console.log(fenway); var panorama = new google.maps.StreetViewPanorama( @@ -2870,7 +2874,7 @@ export class LocationComponent implements OnInit, OnDestroy { } } ); - map.setStreetView(panorama); + map.setStreetView(panorama); // console.log('111111111111111111111111111111111111111111111111111=>',this) this['infowindow'].open(map, this); }); @@ -2880,11 +2884,11 @@ export class LocationComponent implements OnInit, OnDestroy { } // console.log(locations) var z = locations - } - - // this.togglePOI(true); - - } + } + + // this.togglePOI(true); + + } flightPathArr: any = []; isTraffic: boolean = false; mapTypeId: any = "roadmap"; @@ -2918,7 +2922,7 @@ export class LocationComponent implements OnInit, OnDestroy { enablePOIComponent = false; toggleMapComponents(option) { - if(this.showHistory){ + if (this.showHistory) { if (option == "route")//route,pointofinterest,geofencing { this.routeDetails1(this.useridd, !this.enableRouteComponent); @@ -2932,7 +2936,7 @@ export class LocationComponent implements OnInit, OnDestroy { } - }else{ + } else { if (option == "route")//route,pointofinterest,geofencing { this.routeDetails(this.useridd, !this.enableRouteComponent); @@ -3100,7 +3104,7 @@ export class LocationComponent implements OnInit, OnDestroy { //this.speed = 200 var iconselected = this.devicon var delay = 100; - + var carIcon = { // path: car, @@ -3229,7 +3233,7 @@ export class LocationComponent implements OnInit, OnDestroy { "tractor": tractorIcon, "bus": busIcon, "user": userIcon, - "ambulance":ambulance + "ambulance": ambulance } var that = this; @@ -3243,24 +3247,24 @@ export class LocationComponent implements OnInit, OnDestroy { // } // this.rangeDetector=false; var km_h = km_h || 50; - + if (!startPos.length) coords.push([startPos[0], startPos[1]]); that.goToPoint = function () { // console.log("Go to point function"); - if(that.rangeDetector === true){ - a= that.indexValue; - target = that.indexValue; + if (that.rangeDetector === true) { + a = that.indexValue; + target = that.indexValue; that.sliderValue = that.indexValue; } var lat = marker.position.lat(); var lng = marker.position.lng(); - that.getAddress(lat,lng); - - if(km_h === 0){ - km_h = 200 ; + that.getAddress(lat, lng); + + if (km_h === 0) { + km_h = 200; } var step = (km_h * 1000 * delay) / 3600000; // in meters var dest = new google.maps.LatLng( @@ -3277,7 +3281,7 @@ export class LocationComponent implements OnInit, OnDestroy { var distance = google.maps.geometry.spherical.computeDistanceBetween(dest, marker.position); // in meters var numStep = distance / step; - + var i = 0; var deltaLat = (coords[target][0] - lat) / numStep; var deltaLng = (coords[target][1] - lng) / numStep; @@ -3286,15 +3290,15 @@ export class LocationComponent implements OnInit, OnDestroy { // console.log("Move Marker Function"); // console.log('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',a,target); // ye wala movemarker function h - outerThis.sliderValue = a; - outerThis.cummulative_Distance = coords[target][3] ; + outerThis.sliderValue = a; + outerThis.cummulative_Distance = coords[target][3]; lat += deltaLat; lng += deltaLng; i += step; // console.log('icons[iconselected].rotation',icons[iconselected].rotation); let markerDOM: any; var status = "RUNNING"; - + if (i < distance) { // let iconType = 'car'; // console.log('iconsiconsiconsiconsiconsicons',icons); @@ -3306,34 +3310,34 @@ export class LocationComponent implements OnInit, OnDestroy { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = that.elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); // console.log('markerDOM',markerDOM); - + var head = google.maps.geometry.spherical.computeHeading(marker.getPosition(), new google.maps.LatLng(lat, lng)); - + // console.log('head',head); - + // if (head != 0) { - // icons[iconselected].rotation = head - - if (markerDOM) { - markerDOM.style.transform = 'rotate(' + head + 'deg)'; - } + // icons[iconselected].rotation = head + + if (markerDOM) { + markerDOM.style.transform = 'rotate(' + head + 'deg)'; + } // } marker.setIcon(icons[iconselected]); marker.setPosition(new google.maps.LatLng(lat, lng)); map.setCenter({ lat: lat, lng: lng }); - + that.start = setTimeout(that.moveMarker, delay); } else { var head = google.maps.geometry.spherical.computeHeading(marker.getPosition(), dest); - - + + // var iconType = 'car'; // console.log(iconType); - + // console.log(icons[iconType]); // console.log(icons[iconType]); // console.log(icons[iconType].url); @@ -3341,9 +3345,9 @@ export class LocationComponent implements OnInit, OnDestroy { icons[iconType].url = that.iconSelector(status, iconType, msg); markerDOM = that.elementRef.nativeElement.querySelector("img[src='" + icons[iconType].url + "']"); - if (markerDOM) { - markerDOM.style.transform = 'rotate(' + head + 'deg)'; - } + if (markerDOM) { + markerDOM.style.transform = 'rotate(' + head + 'deg)'; + } // } marker.setIcon(icons[iconselected]); marker.setPosition(dest); @@ -3356,71 +3360,71 @@ export class LocationComponent implements OnInit, OnDestroy { } } a++ - - + + that.rangeDetector = false; - console.log('iteration', a,coords.length) + console.log('iteration', a, coords.length) // console.log("outside moveMarker function"); if (a > coords.length) { // console.log("Cord.length if condition"); outerThis.speeed2 = 0; outerThis.isLastPosition = true; - + } - else { - outerThis.isLastPosition = false; + else { + outerThis.isLastPosition = false; // console.log("Cord.length else condition"); that.moveMarker(); km_h = outerThis.speed; } } var a = 0; - - + + // console.log("Gotopoint function"); that.goToPoint(); } -rangeDetector:boolean=false; -changeRange(){ - - clearTimeout(this.start); - this.rangeDetector = true; - var rangeVal = document.getElementById("slider1"); -// console.log(rangeVal); - - // var zoomTImeOut = setTimeout(()=>{ - // this.historyMap.setZoom(15); - // clearTimeout(zoomTImeOut); - // },5000) + rangeDetector: boolean = false; + changeRange() { - this.indexValue = rangeVal['value']; + clearTimeout(this.start); + this.rangeDetector = true; + var rangeVal = document.getElementById("slider1"); + // console.log(rangeVal); - if(this.tempMapHistory[0]['flag'] == 'stop'){ - this.marker4.setPosition({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); - this.historyMap.setCenter({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); - // clearTimeout(this.start); - // this.moveMarker(); - this.goToPoint(); - - } - if(this.tempMapHistory[0]['flag'] == 'start'){ - // this.speed = 0 ; - this.marker4.setPosition({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); - this.historyMap.setCenter({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); - this.tempMapHistory[0]['flag'] = 'stop'; - // clearTimeout(this.start); - this.goToPoint(); + // var zoomTImeOut = setTimeout(()=>{ + // this.historyMap.setZoom(15); + // clearTimeout(zoomTImeOut); + // },5000) - } + this.indexValue = rangeVal['value']; -} + if (this.tempMapHistory[0]['flag'] == 'stop') { + this.marker4.setPosition({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); + this.historyMap.setCenter({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); + // clearTimeout(this.start); + // this.moveMarker(); + this.goToPoint(); -zoomSet(){ - this.historyMap.setZoom(15); -} + } + if (this.tempMapHistory[0]['flag'] == 'start') { + // this.speed = 0 ; + this.marker4.setPosition({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); + this.historyMap.setCenter({ lat: this.latLngLine[this.indexValue].lat, lng: this.latLngLine[this.indexValue].lng }); + this.tempMapHistory[0]['flag'] = 'stop'; + // clearTimeout(this.start); + this.goToPoint(); + + } + + } + + zoomSet() { + this.historyMap.setZoom(15); + } @@ -3467,6 +3471,7 @@ zoomSet(){ this.ddid = dev.did this.contactService.getCurrentLocation(this.ddid, fromtime, totime).subscribe((data5) => { + this.latlongObjArr = data5; // console.log("currlocdata=>",data5) // console.log(this.latlongObjArr) @@ -3516,7 +3521,7 @@ zoomSet(){ google.maps.event.addListener(map, 'click', function (me) { - + setInterval(function () { // console.log("Interval Started") if (outerThis.latlongObjArr[outerThis.last_pointer].interpolated == null || outerThis.latlongObjArr[outerThis.last_pointer].interpolated == undefined) { @@ -3616,62 +3621,62 @@ zoomSet(){ } play(playindex) { // console.log('playindex',playindex); - + this.showStatus = true var icontype = this.dev_id.iconType; var tempObj = { "icontype": icontype } var tempDataCoordArr = this.tempMapHistory[playindex].dataArrayCoords; - + tempObj["tempDataCoordArr"] = tempDataCoordArr; - if (this.tempMapHistory[playindex]['flag'] == 'init') { + if (this.tempMapHistory[playindex]['flag'] == 'init') { this.speed = 100; this.animateMarker_history(this.marker4, tempDataCoordArr, 50, icontype); tempObj["marker"] = this.marker4; this.tempMapHistory[playindex]['flag'] = 'stop'; tempObj["flag"] = this.tempMapHistory[playindex]['flag']; - - } else if (this.tempMapHistory[playindex]['flag'] == 'start') { - - this.moveMarker(); - // clearTimeout(this.start); - this.tempMapHistory[playindex]['flag'] = 'stop'; - tempObj["flag"] = this.tempMapHistory[playindex]['flag']; - - } else - if (this.tempMapHistory[playindex]['flag'] == 'stop') { - this.speed = 0; - clearTimeout(this.start); - this.tempMapHistory[playindex]['flag'] = 'start'; - tempObj["flag"] = this.tempMapHistory[playindex]['flag']; - } - if (this.flag == 'reset') { - this.marker4.setPosition({ lat: this.latLngLine[0].lat, lng: this.latLngLine[0].lng }); - this.flag = 'init'; - } + } else if (this.tempMapHistory[playindex]['flag'] == 'start') { + + this.moveMarker(); + // clearTimeout(this.start); + this.tempMapHistory[playindex]['flag'] = 'stop'; + tempObj["flag"] = this.tempMapHistory[playindex]['flag']; + + } else + if (this.tempMapHistory[playindex]['flag'] == 'stop') { + this.speed = 0; + clearTimeout(this.start); + this.tempMapHistory[playindex]['flag'] = 'start'; + tempObj["flag"] = this.tempMapHistory[playindex]['flag']; + } + + if (this.flag == 'reset') { + this.marker4.setPosition({ lat: this.latLngLine[0].lat, lng: this.latLngLine[0].lng }); + this.flag = 'init'; + } } headingName = 'Live Tracking'; playingHistory: boolean = false; - parkingPOINTS=[] + parkingPOINTS = [] fromTIME - stop_locationss=[] + stop_locationss = [] counter maphistory(data) { this.showArea(); this.pdfFunction(this.deviceSelect[0]); this.getTravelPathReport(this.deviceSelect[0]) - if(this.digitalInput==1){ + if (this.digitalInput == 1) { this.workingHoursFunction1(this.deviceSelect[0]) - }else{ + } else { this.workingHoursFunction2(this.deviceSelect[0]) } - this.historyAdress =''; - this.sliderValue=0; + this.historyAdress = ''; + this.sliderValue = 0; this.showSocketData = false; this.Load = true; this.map2load = false; @@ -3696,10 +3701,10 @@ zoomSet(){ this.latLongArr3 = [] to1 = null; - + this.dev_id = this.deviceSelect[0]; // console.log("Trssss",this.deviceSelect[0]); - + var currtime = new Date(); var from1 = new Date(this.datefrom).toISOString(); var to1 = new Date(this.date2).toISOString(); @@ -3707,16 +3712,16 @@ zoomSet(){ var fromtime = new Date(from1).toISOString(); var totime = new Date(to1).toISOString(); - this.fromTIME=new Date(from1).toISOString(); + this.fromTIME = new Date(from1).toISOString(); // console.log(fromtime) var diff = moment(totime).diff(fromtime, 'days') // console.log('difference :' + diff) - - if ((fromtime > totime)||(diff>=31)) { + + if ((fromtime > totime) || (diff >= 31)) { this.Load = false; - let error = (fromtime > totime)?"Error: From Time Never Greater then To Time" : "History is unavailable for more than one month"; + let error = (fromtime > totime) ? "Error: From Time Never Greater then To Time" : "History is unavailable for more than one month"; // let message = "Error: From Time Never Greater then To Time"; let action this.snackBar.open(error, action, { @@ -3740,415 +3745,435 @@ zoomSet(){ // this.ddid = dev.did; // this.devicon = dev.iconType; // console.log(this.navId); - - if(this.navId === 'locationHistory'){ - this.ddid=this.dev_id.did - }else{ - this.ddid=this.dev_id.Device_ID + + if (this.navId === 'locationHistory') { + this.ddid = this.dev_id.did + } else { + this.ddid = this.dev_id.Device_ID } - + // this.ddid = (this.navId === 'locationHistory')? this.dev_id.did : this.dev_id.Device_ID; // console.log("DID",this.ddid,this.dev_id.did); - + this.devicon = this.dev_id.iconType; this.speedArr = []; var counter = 0 - var countTime = setInterval(()=>{ + var countTime = setInterval(() => { counter++ - - },1000) - if(data==1){ + }, 1000) - var ft = new Date(fromtime); - var tt = new Date(totime); - var dname = this.deviceSelect[0]; - - if (this.coloumnClicked === false) { - var tempData = { - fromTime: ft.toLocaleString(), - toTime: tt.toLocaleString(), - device_name: this.deviceName, - device_obj: this.deviceSelect[0], - lineThickness: this.thicknessVal, - idleColor: this.idleColor, - parkingColor: this.parkingColor, - dataColor: this.dataColor, - flag: 'init', + if (data == 1) { + + var ft = new Date(fromtime); + var tt = new Date(totime); + var dname = this.deviceSelect[0]; + + if (this.coloumnClicked === false) { + var tempData = { + fromTime: ft.toLocaleString(), + toTime: tt.toLocaleString(), + device_name: this.deviceName, + device_obj: this.deviceSelect[0], + lineThickness: this.thicknessVal, + idleColor: this.idleColor, + parkingColor: this.parkingColor, + dataColor: this.dataColor, + flag: 'init', + } + } + + this.showTable = true; + this.flag = 'init'; + initialize(); + + this.Load = false; + + + let cluster_arr = []; + + try { + + this.path = flightPath.getPath(); + } catch (error) { + console.log('flightPath.getPath()', error) + } + + + var cumulativeDistance = 0; + + for (let i = this.latlongObjArr.length - 1; i > 0; i--) { + + var d_name = (this.navId === 'locationHistory') ? this.dev_id.viewValue : this.dev_id.Device_Name; + this.speed = this.latlongObjArr[i].speed + "Km/hr"; + this.im = this.latlongObjArr[i].imei; + + this.speedArr.push(this.latlongObjArr[i].speed); + + var heading = this.latlongObjArr[i].heading; + // this.time = gmtDateTime.local().format('h:mm:ss A'); + this.datee = JSON.stringify(this.latlongObjArr[i].insertionTime); + // console.log(JSON.parse(this.datee)); + // var insTime = new Date(this.datee); + this.datee = moment(JSON.parse(this.datee)).format('MMMM Do YYYY, h:mm:ss a'); + + var harshAcc = this.latlongObjArr[i].harshAccel; + var harshBreak = this.latlongObjArr[i].harshBrake; + var harshCorner = this.latlongObjArr[i].harshCorner; + // console.log(harshAcc,harshBreak,harshCorner); + var fill_color = '#00F'; + var stroke_color = '#00A'; + var content = ''; + // + content = `

DEVICE NAME : ` + + d_name + `
IMEI : ` + + this.im + `
DEVICE DATE : ` + + this.datee + `
SPEED : ` + + this.speed + `
Address : ` + + this.contentAdd + `
+
` + var harsh = this.latlongObjArr[i].gforce ? (parseFloat(this.latlongObjArr[i].gforce) / 10) : 0; + if ((harshAcc != undefined) && (harshAcc == 'true')) { + fill_color = '#008000'; + stroke_color = '#008000'; + + if ((harsh != undefined) && (harsh != null)) { + var harshStat = outerThis.harshImpact(harsh); + content = '

Harsh Acceleration


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' + '
' } } - - this.showTable = true; - this.flag = 'init'; - initialize(); - - this.Load = false; - - - let cluster_arr = []; - console.log(flightPath.getPath()); + if ((harshBreak != undefined) && (harshBreak == 'true')) { + fill_color = '#FF0000'; + stroke_color = '#FF0000'; + if ((harsh != undefined) && (harsh != null)) { + var harshStat = outerThis.harshImpact(harsh); + content = '

Harsh Break


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' + '
' - this.path = flightPath.getPath(); - - var cumulativeDistance =0 ; - - for (let i = this.latlongObjArr.length - 1; i > 0; i--) { - - var d_name = (this.navId === 'locationHistory')? this.dev_id.viewValue:this.dev_id.Device_Name; - this.speed = this.latlongObjArr[i].speed + "Km/hr"; - this.im = this.latlongObjArr[i].imei; - - this.speedArr.push(this.latlongObjArr[i].speed); - - var heading = this.latlongObjArr[i].heading; - // this.time = gmtDateTime.local().format('h:mm:ss A'); - this.datee = JSON.stringify(this.latlongObjArr[i].insertionTime); - // console.log(JSON.parse(this.datee)); - // var insTime = new Date(this.datee); - this.datee = moment(JSON.parse(this.datee)).format('MMMM Do YYYY, h:mm:ss a'); - - var harshAcc = this.latlongObjArr[i].harshAccel; - var harshBreak = this.latlongObjArr[i].harshBrake; - var harshCorner = this.latlongObjArr[i].harshCorner; - // console.log(harshAcc,harshBreak,harshCorner); - var fill_color = '#00F'; - var stroke_color = '#00A'; - var content = ''; - // - content = `

DEVICE NAME : ` - + d_name + `
IMEI : ` - + this.im + `
DEVICE DATE : ` - + this.datee + `
SPEED : ` - + this.speed + `
Address : ` - + this.contentAdd + `
-
` - var harsh = this.latlongObjArr[i].gforce ? (parseFloat(this.latlongObjArr[i].gforce) / 10) : 0; - if ((harshAcc != undefined) && (harshAcc == 'true')) { - fill_color = '#008000'; - stroke_color = '#008000'; - - if ((harsh != undefined) && (harsh != null)) { - var harshStat = outerThis.harshImpact(harsh); - content = '

Harsh Acceleration


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' - '
' - } } - if ((harshBreak != undefined) && (harshBreak == 'true')) { - fill_color = '#FF0000'; - stroke_color = '#FF0000'; - if ((harsh != undefined) && (harsh != null)) { - var harshStat = outerThis.harshImpact(harsh); - content = '

Harsh Break


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' - '
' - - } + } + if ((harshCorner != undefined) && (harshCorner == 'true')) { + fill_color = '#c407b1'; + stroke_color = '#c407b1'; + if ((harsh != undefined) && (harsh != null)) { + var harshStat = outerThis.harshImpact(harsh); + content = '

Harsh Corner


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' + '
' } - if ((harshCorner != undefined) && (harshCorner == 'true')) { - fill_color = '#c407b1'; - stroke_color = '#c407b1'; - if ((harsh != undefined) && (harsh != null)) { - var harshStat = outerThis.harshImpact(harsh); - content = '

Harsh Corner


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' - '
' - } + } + + + + if (this.latlongObjArr[i].isPastData != true) { + if (i === 0) { + cumulativeDistance += 0; + } else { + cumulativeDistance += this.latlongObjArr[i].distanceFromPrevious ? parseFloat(this.latlongObjArr[i].distanceFromPrevious) : 0; } - - - - if(this.latlongObjArr[i].isPastData != true){ - if(i === 0){ - cumulativeDistance += 0 ; - }else{ - cumulativeDistance += this.latlongObjArr[i].distanceFromPrevious?parseFloat(this.latlongObjArr[i].distanceFromPrevious):0 ; - } - this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2) ; - }else{ - this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2) ; - } - - - var arr = []; - arr.push(this.latlongObjArr[i].lat); - arr.push(this.latlongObjArr[i].lng); - arr.push(this.latlongObjArr[i].speed); - arr.push(this.latlongObjArr[i].cummulative_distance); - arr.push(this.datee); - arr.push(this.latlongObjArr[i].external_Battery); - let cord = { - lat: this.latlongObjArr[i].lat, - lng: this.latlongObjArr[i].lng - } - this.dataArrayCoords.push(arr); - - - this.latLngLine.push(cord); + this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2); + } else { + this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2); + } + + + var arr = []; + arr.push(this.latlongObjArr[i].lat); + arr.push(this.latlongObjArr[i].lng); + arr.push(this.latlongObjArr[i].speed); + arr.push(this.latlongObjArr[i].cummulative_distance); + arr.push(this.datee); + arr.push(this.latlongObjArr[i].external_Battery); + let cord = { + lat: this.latlongObjArr[i].lat, + lng: this.latlongObjArr[i].lng + } + this.dataArrayCoords.push(arr); + + + this.latLngLine.push(cord); var contentString = '
' + - '
'+ + '
' + '

' + this.deviceName + '

' + '
' - var iconSrc = this.iconSelector("RUNNING","truck",{}); - // 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=S|00FF00|000000' - // this.iconSelector("RUNNING","car",{}); - - var iconDest = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000'; - - // =====================================added============================== - - if (this.latlongObjArr[i].interpolated == null || this.latlongObjArr[i].interpolated == undefined || this.latlongObjArr[i].interpolated.length == 0) { - this.lat = this.latlongObjArr[i].lat; - this.lng = this.latlongObjArr[i].lng; + var iconSrc = this.iconSelector("RUNNING", "truck", {}); + // 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=S|00FF00|000000' + // this.iconSelector("RUNNING","car",{}); + + var iconDest = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000'; + + // =====================================added============================== + + if (this.latlongObjArr[i].interpolated == null || this.latlongObjArr[i].interpolated == undefined || this.latlongObjArr[i].interpolated.length == 0) { + this.lat = this.latlongObjArr[i].lat; + this.lng = this.latlongObjArr[i].lng; + this.path.push(new google.maps.LatLng(this.lat, this.lng)); + + + if (this.dataColor === true) { + var markersPasts = new google.maps.Marker({ + position: new google.maps.LatLng(this.lat, this.lng), + icon: { path: google.maps.SymbolPath.CIRCLE, fillColor: fill_color, fillOpacity: 0.6, strokeColor: stroke_color, strokeOpacity: 0.9, strokeWeight: 5, scale: 2 }, + map: map, + }) + + markersPasts['infowindow'] = new google.maps.InfoWindow({ content: content }); + + + google.maps.event.addListener(markersPasts, 'click', function () { + + var lattitude = markersPasts.position.lat(); + var longitude = markersPasts.position.lng(); + var latlng_1 = + { + "lat": lattitude, + "long": longitude + } + + outerThis.contactService.getAddressByApi(latlng_1).subscribe(res => { + + if (res.message == "Address not found in databse") { + var geocoder = new google.maps.Geocoder(); + var latlng = new google.maps.LatLng(lattitude, longitude); + + var request = { + latLng: latlng + }; + // console.log('latlongVal', request) + var innerThis = this; + this['infowindow'].open(map, innerThis); + geocoder.geocode(request, function (data, status) { + if (status == google.maps.GeocoderStatus.OK) { + if (data[0] != null) { + // innerThis.contentAdd = data[0].formatted_address; + var tempAdd = data[0].formatted_address; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd; + + + } else { + // console.log("No address available") + var tempAdd_1 = "No address available"; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd_1; + + + + } + } + else { + var tempAdd_2 = 'NA'; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd_2; + // console.log('aaaaaaaaaaaaaa',getAddressContent); + + + } + + }) + + } else { + var innerThis_1 = this; + + this['infowindow'].open(map, innerThis_1); + var tempAdd = res.address; + // console.log('innerThis_1.contentAdd',tempAdd); + var chkTmout = setTimeout(function () { + var getAddressContent = document.getElementById('addressBinding'); + // console.log('getAddressContent',getAddressContent); + getAddressContent.innerHTML = 'Address :' + tempAdd; + clearTimeout(chkTmout); + }, 500) + + } + + }) + + + + }) + // cluster_arr.push(markersPast); + + } + + + + if (i == 1) { + markerCurrent = new google.maps.Marker({ + position: new google.maps.LatLng(this.lat, this.lng), + map: map, + icon: iconDest + }); + // outerThis.marker4 = markerCurrent; + map.setCenter(new google.maps.LatLng(this.lat, this.lng)) + flightPath.setMap(map); + zoomToObject(flightPath); + } + if (i == (this.latlongObjArr.length - 1)) { + markerSrc = new google.maps.Marker({ + position: new google.maps.LatLng(this.lat, this.lng), + map: map, + icon: iconSrc, + scaledSize: new google.maps.Size(20, 20), + }); + // markerSrc['infowindow'] = new google.maps.InfoWindow({ content: content }); + const infowindow = new google.maps.InfoWindow({ + content: contentString, + }); + infowindow.open(map, markerSrc); + markerSrc.addListener("click", () => { + infowindow.open(map, markerSrc); + }); + outerThis.marker4 = markerSrc; + } + + + } + else { + + for (let k = 0; k < this.latlongObjArr[i].interpolated.length; k++) { + if (this.latlongObjArr[i].interpolated[k].location.latitude == null || this.latlongObjArr[i].interpolated[k].location.longitude == null) { + this.lat = this.latlongObjArr[i].lat; + this.lng = this.latlongObjArr[i].lng; + } else { + this.lat = this.latlongObjArr[i].interpolated[k].location.latitude; + this.lng = this.latlongObjArr[i].interpolated[k].location.longitude; + } + this.path.push(new google.maps.LatLng(this.lat, this.lng)); - - - if (this.dataColor === true) { + + + if (this.dataColor) { var markersPasts = new google.maps.Marker({ position: new google.maps.LatLng(this.lat, this.lng), icon: { path: google.maps.SymbolPath.CIRCLE, fillColor: fill_color, fillOpacity: 0.6, strokeColor: stroke_color, strokeOpacity: 0.9, strokeWeight: 5, scale: 2 }, map: map, }) - markersPasts['infowindow'] = new google.maps.InfoWindow({ content: content }); - - google.maps.event.addListener(markersPasts, 'click', function () { - - var lattitude = markersPasts.position.lat(); - var longitude = markersPasts.position.lng() ; - var latlng_1 = - { - "lat": lattitude, - "long": longitude - } - outerThis.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - - if(res.message == "Address not found in databse"){ - var geocoder = new google.maps.Geocoder(); - var latlng = new google.maps.LatLng(lattitude, longitude); - - var request = { - latLng: latlng - }; - // console.log('latlongVal', request) - var innerThis = this ; - this['infowindow'].open(map, innerThis); - geocoder.geocode(request, function (data, status) { - if (status == google.maps.GeocoderStatus.OK) { - if (data[0] != null) { - // innerThis.contentAdd = data[0].formatted_address; - var tempAdd = data[0].formatted_address; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd ; - - - } else { - // console.log("No address available") - var tempAdd_1 = "No address available"; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd_1 ; - - - - } - } - else { - var tempAdd_2 = 'NA'; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd_2 ; - // console.log('aaaaaaaaaaaaaa',getAddressContent); - - - } - - }) - - }else{ - var innerThis_1 = this ; - - this['infowindow'].open(map, innerThis_1); - var tempAdd = res.address ; - // console.log('innerThis_1.contentAdd',tempAdd); - var chkTmout = setTimeout(function(){ - var getAddressContent = document.getElementById('addressBinding'); - // console.log('getAddressContent',getAddressContent); - getAddressContent.innerHTML = 'Address :' + tempAdd ; - clearTimeout(chkTmout); - },500) - - } - - }) - - - - }) - // cluster_arr.push(markersPast); - - } - - - - if (i == 1) { - markerCurrent = new google.maps.Marker({ - position: new google.maps.LatLng(this.lat, this.lng), - map: map, - icon: iconDest + // console.log("inside info window function 1"); + this['infowindow'].open(map, this); }); - // outerThis.marker4 = markerCurrent; - map.setCenter(new google.maps.LatLng(this.lat, this.lng)) - flightPath.setMap(map); - zoomToObject(flightPath); - } - if (i == (this.latlongObjArr.length - 1)) { - markerSrc = new google.maps.Marker({ - position: new google.maps.LatLng(this.lat, this.lng), - map: map, - icon: iconSrc, - scaledSize: new google.maps.Size(20, 20), - }); - // markerSrc['infowindow'] = new google.maps.InfoWindow({ content: content }); - const infowindow = new google.maps.InfoWindow({ - content: contentString, - }); - infowindow.open(map, markerSrc); - markerSrc.addListener("click", () => { - infowindow.open(map, markerSrc); - }); - outerThis.marker4 = markerSrc; - } - - - } - else { - - for (let k = 0; k < this.latlongObjArr[i].interpolated.length; k++) { - if (this.latlongObjArr[i].interpolated[k].location.latitude == null || this.latlongObjArr[i].interpolated[k].location.longitude == null) { - this.lat = this.latlongObjArr[i].lat; - this.lng = this.latlongObjArr[i].lng; - } else { - this.lat = this.latlongObjArr[i].interpolated[k].location.latitude; - this.lng = this.latlongObjArr[i].interpolated[k].location.longitude; - } - - this.path.push(new google.maps.LatLng(this.lat, this.lng)); - - - if (this.dataColor) { - var markersPasts = new google.maps.Marker({ - position: new google.maps.LatLng(this.lat, this.lng), - icon: { path: google.maps.SymbolPath.CIRCLE, fillColor: fill_color, fillOpacity: 0.6, strokeColor: stroke_color, strokeOpacity: 0.9, strokeWeight: 5, scale: 2 }, - map: map, - }) - markersPasts['infowindow'] = new google.maps.InfoWindow({ content: content }); - google.maps.event.addListener(markersPasts, 'click', function () { - // console.log("inside info window function 1"); - this['infowindow'].open(map, this); }); - - - } - } - if (i == 1) { - markerCurrent = new google.maps.Marker({ - position: new google.maps.LatLng(this.lat, this.lng), - map: map, - icon: iconDest - }); - - // outerThis.marker4 = markerCurrent; - map.setCenter(new google.maps.LatLng(this.lat, this.lng)) - flightPath.setMap(map); - zoomToObject(flightPath); - - } - - if (i == (this.latlongObjArr.length - 1)) { - markerSrc = new google.maps.Marker({ - position: new google.maps.LatLng(this.lat, this.lng), - map: map, - icon: iconSrc - }) - outerThis.marker4 = markerSrc; - } - } - } - - - - // console.log(this.coloumnClicked) ; - if (this.coloumnClicked === false) { - tempData['dataArrayCoords'] = this.dataArrayCoords; - - } - - // console.log('this.dataArrayCoords',this.dataArrayCoords); - if(this.dataArrayCoords.length<1){ - var fdd = new Date(this.datefrom); - var tdd= new Date(this.date2); - swal("No Data Found", "Vehicle has not moved from" +" "+ moment(fdd).format('LLL') + "to " + moment(tdd).format('LLL')).then((ans)=>{ - // console.log(ans); - - },err=>{ - // console.log(err); - }); - - } - - this.seekBarValue = this.dataArrayCoords.length; - - this.maxSpeedd = Math.max.apply(null, this.speedArr); - this.dis = true; - - this.contactService.getDistance(this.ddid, fromtime, totime,this.satelliteDisabled?this.satelite:undefined).subscribe((data3) => { - - this.data2 = data3; - - // initialize(); - // console.log(this.data2); - let a = this.data2["Distance"] ? this.data2["Distance"] : 0; - if (this.coloumnClicked === false) { - tempData['mileage'] = a; - this.tempMapHistory.push(tempData); - - } - - - - this.total_dis = a; - let b = this.data2["Average Speed"] ? this.data2["Average Speed"] : 0; - this.avg_speed = b; - - this.ideal_time = this.data2["Idle Time"] ? this.minToHoursConversion(this.data2["Idle Time"]) : 0; - if (parseFloat(this.ideal_time) < 0) { - this.ideal_time = 0; - } - - this.historyDataCondition = true; - - var playerSeekbar: any; - $( document ).ready(function() { - playerSeekbar = document.getElementById('slider1'); - console.log( "ready!", playerSeekbar['value']); - playerSeekbar.oninput = function () { - - zoomToObject(flightPath); - outerThis.changeRange(); - - } - }); - }) - + + } + } + if (i == 1) { + markerCurrent = new google.maps.Marker({ + position: new google.maps.LatLng(this.lat, this.lng), + map: map, + icon: iconDest + }); + + // outerThis.marker4 = markerCurrent; + map.setCenter(new google.maps.LatLng(this.lat, this.lng)) + flightPath.setMap(map); + zoomToObject(flightPath); + + } + + if (i == (this.latlongObjArr.length - 1)) { + markerSrc = new google.maps.Marker({ + position: new google.maps.LatLng(this.lat, this.lng), + map: map, + icon: iconSrc + }) + outerThis.marker4 = markerSrc; + } + } + } + + + + // console.log(this.coloumnClicked) ; + if (this.coloumnClicked === false) { + tempData['dataArrayCoords'] = this.dataArrayCoords; + + } + + // console.log('this.dataArrayCoords',this.dataArrayCoords); + if (this.dataArrayCoords.length < 1) { + var fdd = new Date(this.datefrom); + var tdd = new Date(this.date2); + swal("No Data Found", "Vehicle has not moved from" + " " + moment(fdd).format('LLL') + "to " + moment(tdd).format('LLL')).then((ans) => { + // console.log(ans); + + }, err => { + // console.log(err); + }); + + } + + this.seekBarValue = this.dataArrayCoords.length; + + this.maxSpeedd = Math.max.apply(null, this.speedArr); + this.dis = true; + + this.contactService.getDistance(this.ddid, fromtime, totime, this.satelliteDisabled ? this.satelite : undefined).subscribe((data3) => { + + this.data2 = data3; + + // initialize(); + // console.log(this.data2); + let a = this.data2["Distance"] ? this.data2["Distance"] : 0; + if (this.coloumnClicked === false) { + tempData['mileage'] = a; + this.tempMapHistory.push(tempData); + + } + + + + this.total_dis = a; + let b = this.data2["Average Speed"] ? this.data2["Average Speed"] : 0; + this.avg_speed = b; + + this.ideal_time = this.data2["Idle Time"] ? this.minToHoursConversion(this.data2["Idle Time"]) : 0; + if (parseFloat(this.ideal_time) < 0) { + this.ideal_time = 0; + } + + this.historyDataCondition = true; + + var playerSeekbar: any; + $(document).ready(function () { + playerSeekbar = document.getElementById('slider1'); + console.log("ready!", playerSeekbar['value']); + playerSeekbar.oninput = function () { + + zoomToObject(flightPath); + outerThis.changeRange(); + + } + }); + }) + + } - else{ - this.contactService.getCurrentLocation1(this.ddid, fromtime, totime,this.satelliteDisabled?this.satelite:undefined).subscribe((data3:any) => { - if(data3){ + else { + this.contactService.getCurrentLocation1(this.ddid, fromtime, totime, this.satelliteDisabled ? this.satelite : undefined).subscribe((data3: any) => { + if (data3) { clearInterval(countTime); } - + let latLongArray : any[] = []; + data3.forEach((deData)=>{ + latLongArray.push({ + "long":deData.lng, + "lat":deData.lat + }) + + }) + + outerThis.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + data3.forEach((deData,index)=>{ + outerThis.contactService.latLongAddress[deData.lng+'_'+deData.lat] = latLongAddress[index]; + }) + // console.log('countercountercountercountercountercountercounter',counter,data3); var ft = new Date(fromtime); var tt = new Date(totime); var dname = this.deviceSelect[0]; - + if (this.coloumnClicked === false) { var tempData = { fromTime: ft.toLocaleString(), @@ -4160,30 +4185,35 @@ zoomSet(){ parkingColor: this.parkingColor, dataColor: this.dataColor, flag: 'init', - + } } - + this.showTable = true; - this.latlongObjArr = data3; this.flag = 'init'; initialize(); this.Load = false; let cluster_arr = []; // console.log(flightPath.getPath()); + + try { - this.path = flightPath.getPath(); - var cumulativeDistance =0 ; - + this.path = flightPath.getPath(); + } catch (error) { + this.path = []; + console.log('flightPath.getPath()', error) + } + var cumulativeDistance = 0; + for (let i = this.latlongObjArr.length - 1; i > 0; i--) { console.log(this.latlongObjArr[i]); - var d_name = (this.navId === 'locationHistory')? this.dev_id.viewValue:this.dev_id.Device_Name; + var d_name = (this.navId === 'locationHistory') ? this.dev_id.viewValue : this.dev_id.Device_Name; this.speed = this.latlongObjArr[i].speed + "Km/hr"; this.im = this.latlongObjArr[i].imei; // console.log(this.latlongObjArr[i]); - var insertionTime=moment(this.latlongObjArr[i].insTime).format('MMMM Do YYYY, h:mm:ss a'); - var raw=this.latlongObjArr[i].raw; + var insertionTime = moment(this.latlongObjArr[i].insTime).format('MMMM Do YYYY, h:mm:ss a'); + var raw = this.latlongObjArr[i].raw; this.speedArr.push(this.latlongObjArr[i].speed); var heading = this.latlongObjArr[i].heading; @@ -4192,8 +4222,8 @@ zoomSet(){ // console.log(this.latlongObjArr[i],"lakskalskalkl"); // var insTime = new Date(this.datee); this.datee = moment(JSON.parse(this.datee)).format('MMMM Do YYYY, h:mm:ss a'); - var lastLat=this.latlongObjArr[i].lat - var lastlong=this.latlongObjArr[i].lng + var lastLat = this.latlongObjArr[i].lat + var lastlong = this.latlongObjArr[i].lng var harshAcc = this.latlongObjArr[i].harshAccel; var harshBreak = this.latlongObjArr[i].harshBrake; var harshCorner = this.latlongObjArr[i].harshCorner; @@ -4203,22 +4233,22 @@ zoomSet(){ var content = ''; // content=`

DEVICE NAME :$d_name` content = `

DEVICE NAME : ` - + d_name + `
IMEI : ` - + this.im + `
DEVICE DATE : ` - + this.datee + `
SPEED : `+ this.speed + - `
INSERTION TIME : `+ insertionTime + - `
RAW : ` + ' Get Raw Data '+ - `
Address : ` + + d_name + `
IMEI : ` + + this.im + `
DEVICE DATE : ` + + this.datee + `
SPEED : ` + this.speed + + `
INSERTION TIME : ` + insertionTime + + `
RAW : ` + ' Get Raw Data ' + + `
Address : ` + this.contentAdd + '

' - +'
' - // '' - // - + + '
' + // '' + // + var harsh = this.latlongObjArr[i].gforce ? (parseFloat(this.latlongObjArr[i].gforce) / 10) : 0; if ((harshAcc != undefined) && (harshAcc == 'true')) { fill_color = '#008000'; stroke_color = '#008000'; - + if ((harsh != undefined) && (harsh != null)) { var harshStat = outerThis.harshImpact(harsh); content = '

Harsh Acceleration


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' @@ -4232,7 +4262,7 @@ zoomSet(){ var harshStat = outerThis.harshImpact(harsh); content = '

Harsh Break


Impact : ' + harshStat + '
DEVICE NAME : ' + d_name + '
IMEI : ' + this.im + '
DEVICE DATE : ' + this.datee + '
SPEED : ' + this.speed + '
' '
' - + } } if ((harshCorner != undefined) && (harshCorner == 'true')) { @@ -4244,22 +4274,22 @@ zoomSet(){ '
' } } - - - - if(this.latlongObjArr[i].isPastData != true){ - if(i === 0){ - cumulativeDistance += 0 ; - }else{ - cumulativeDistance += this.latlongObjArr[i].distanceFromPrevious?parseFloat(this.latlongObjArr[i].distanceFromPrevious):0 ; - } - this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2) ; - }else{ - this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2) ; + + + + if (this.latlongObjArr[i].isPastData != true) { + if (i === 0) { + cumulativeDistance += 0; + } else { + cumulativeDistance += this.latlongObjArr[i].distanceFromPrevious ? parseFloat(this.latlongObjArr[i].distanceFromPrevious) : 0; + } + this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2); + } else { + this.latlongObjArr[i]['cummulative_distance'] = (cumulativeDistance).toFixed(2); } - - - var arr = []; + + + var arr = []; arr.push(this.latlongObjArr[i].lat); arr.push(this.latlongObjArr[i].lng); arr.push(this.latlongObjArr[i].speed); @@ -4271,17 +4301,17 @@ zoomSet(){ lng: this.latlongObjArr[i].lng } this.dataArrayCoords.push(arr); - - + + this.latLngLine.push(cord); - var contentString = '
' + - '
'+ - '

' + this.deviceName + '

' + - '
' - var iconSrc = this.iconSelector("RUNNING","truck",{}); + var contentString = '
' + + '
' + + '

' + this.deviceName + '

' + + '
' + var iconSrc = this.iconSelector("RUNNING", "truck", {}); // 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=S|00FF00|000000' // this.iconSelector("RUNNING","car",{}); - + var iconDest = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000'; // iconSrc['infowindow'] = new google.maps.InfoWindow({ content: contentString }); // '/assets/images/liveTrackIcons/ocar.png'; @@ -4289,98 +4319,99 @@ zoomSet(){ // this.lat = this.latlongObjArr[i].lat; // this.lng = this.latlongObjArr[i].lng; // this.path.push(new google.maps.LatLng(this.lat, this.lng)); - + // =====================================added============================== - + if (this.latlongObjArr[i].interpolated == null || this.latlongObjArr[i].interpolated == undefined || this.latlongObjArr[i].interpolated.length == 0) { this.lat = this.latlongObjArr[i].lat; this.lng = this.latlongObjArr[i].lng; this.path.push(new google.maps.LatLng(this.lat, this.lng)); - - + + if (this.dataColor === true) { var markersPast = new google.maps.Marker({ position: new google.maps.LatLng(this.lat, this.lng), icon: { path: google.maps.SymbolPath.CIRCLE, fillColor: fill_color, fillOpacity: 0.6, strokeColor: stroke_color, strokeOpacity: 0.9, strokeWeight: 5, scale: 2 }, map: map, }) - + markersPast['infowindow'] = new google.maps.InfoWindow({ content: content }); - + google.maps.event.addListener(markersPast, 'click', function () { - - + + var lattitude = markersPast.position.lat(); - var longitude = markersPast.position.lng() ; + var longitude = markersPast.position.lng(); var latlng_1 = { "lat": lattitude, - "long": longitude + "long": longitude } - outerThis.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - - if(res.message == "Address not found in databse"){ - var geocoder = new google.maps.Geocoder(); - var latlng = new google.maps.LatLng(lattitude, longitude); - - var request = { - latLng: latlng - }; - // console.log('latlongVal', request) - var innerThis = this ; - this['infowindow'].open(map, innerThis); - geocoder.geocode(request, function (data, status) { - if (status == google.maps.GeocoderStatus.OK) { - if (data[0] != null) { - // innerThis.contentAdd = data[0].formatted_address; - var tempAdd = data[0].formatted_address; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd ; - - - } else { - // console.log("No address available") - var tempAdd_1 = "No address available"; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd_1 ; - - - - } - } - else { - var tempAdd_2 = 'NA'; - var getAddressContent = document.getElementById('addressBinding'); - getAddressContent.innerHTML = 'Address :' + tempAdd_2 ; - // console.log('aaaaaaaaaaaaaa',getAddressContent); - - - } - - }) - - }else{ - var innerThis_1 = this ; + let addressRes = outerThis.contactService.latLongAddress[longitude+'_'+lattitude]; - this['infowindow'].open(map, innerThis_1); - var tempAdd = res.address ; + + if (!(addressRes && addressRes.address)) { + var geocoder = new google.maps.Geocoder(); + var latlng = new google.maps.LatLng(lattitude, longitude); + + var request = { + latLng: latlng + }; + // console.log('latlongVal', request) + var innerThis = this; + this['infowindow'].open(map, innerThis); + geocoder.geocode(request, function (data, status) { + if (status == google.maps.GeocoderStatus.OK) { + if (data[0] != null) { + // innerThis.contentAdd = data[0].formatted_address; + var tempAdd = data[0].formatted_address; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd; + + + } else { + // console.log("No address available") + var tempAdd_1 = "No address available"; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd_1; + + + + } + } + else { + var tempAdd_2 = 'NA'; + var getAddressContent = document.getElementById('addressBinding'); + getAddressContent.innerHTML = 'Address :' + tempAdd_2; + // console.log('aaaaaaaaaaaaaa',getAddressContent); + + + } + + }) + + } else { + var innerThis_1 = this; + + this['infowindow'].open(map, innerThis_1); + var tempAdd = addressRes.address; // console.log('innerThis_1.contentAdd',tempAdd); - var chkTmout = setTimeout(function(){ + var chkTmout = setTimeout(function () { var getAddressContent = document.getElementById('addressBinding'); // console.log('getAddressContent',getAddressContent); - getAddressContent.innerHTML = 'Address :' + tempAdd ; + getAddressContent.innerHTML = 'Address :' + tempAdd; clearTimeout(chkTmout); - },500) - + }, 500) + } - - }) - }) - + + + }) + } - - - + + + if (i == 1) { markerCurrent = new google.maps.Marker({ position: new google.maps.LatLng(this.lat, this.lng), @@ -4400,24 +4431,24 @@ zoomSet(){ scaledSize: new google.maps.Size(20, 20), }); markerSrc['infowindow'] = new google.maps.InfoWindow({ content: content }); - const infowindow = new google.maps.InfoWindow({ - content: contentString, - }); - infowindow.open(map, markerSrc); - markerSrc.addListener("click", () => { + const infowindow = new google.maps.InfoWindow({ + content: contentString, + }); infowindow.open(map, markerSrc); + markerSrc.addListener("click", () => { + infowindow.open(map, markerSrc); }); outerThis.marker4 = markerSrc; } - - - + + + } else { - + for (let k = 0; k < this.latlongObjArr[i].interpolated.length; k++) { if (this.latlongObjArr[i].interpolated[k].location.latitude == null || this.latlongObjArr[i].interpolated[k].location.longitude == null) { this.lat = this.latlongObjArr[i].lat; @@ -4426,22 +4457,23 @@ zoomSet(){ this.lat = this.latlongObjArr[i].interpolated[k].location.latitude; this.lng = this.latlongObjArr[i].interpolated[k].location.longitude; } - + this.path.push(new google.maps.LatLng(this.lat, this.lng)); - - + + if (this.dataColor) { var markersPast = new google.maps.Marker({ position: new google.maps.LatLng(this.lat, this.lng), icon: { path: google.maps.SymbolPath.CIRCLE, fillColor: fill_color, fillOpacity: 0.6, strokeColor: stroke_color, strokeOpacity: 0.9, strokeWeight: 5, scale: 2 }, map: map, }) - markersPast['infowindow'] = new google.maps.InfoWindow({ content: content }); - google.maps.event.addListener(markersPast, 'click', function () { + markersPast['infowindow'] = new google.maps.InfoWindow({ content: content }); + google.maps.event.addListener(markersPast, 'click', function () { // console.log("inside info window function 1"); - this['infowindow'].open(map, this); }); - - + this['infowindow'].open(map, this); + }); + + } } if (i == 1) { @@ -4450,14 +4482,14 @@ zoomSet(){ map: map, icon: iconDest }); - + // outerThis.marker4 = markerCurrent; map.setCenter(new google.maps.LatLng(this.lat, this.lng)) flightPath.setMap(map); zoomToObject(flightPath); - + } - + if (i == (this.latlongObjArr.length - 1)) { markerSrc = new google.maps.Marker({ position: new google.maps.LatLng(this.lat, this.lng), @@ -4468,87 +4500,88 @@ zoomSet(){ } } } - + if (this.coloumnClicked === false) { tempData['dataArrayCoords'] = this.dataArrayCoords; - + } - - if(this.dataArrayCoords.length<1){ - var fdd = new Date(this.datefrom); - var tdd= new Date(this.date2); - swal("No Data Found", "Vehicle has not moved from" +" "+ moment(fdd).format('LLL') + "to " + moment(tdd).format('LLL')).then((ans)=>{ - // console.log(ans); - - },err=>{ - // console.log(err); - }); - - } - + + if (this.dataArrayCoords.length < 1) { + var fdd = new Date(this.datefrom); + var tdd = new Date(this.date2); + swal("No Data Found", "Vehicle has not moved from" + " " + moment(fdd).format('LLL') + "to " + moment(tdd).format('LLL')).then((ans) => { + // console.log(ans); + + }, err => { + // console.log(err); + }); + + } + this.seekBarValue = this.dataArrayCoords.length; - + this.maxSpeedd = Math.max.apply(null, this.speedArr); this.dis = true; - - this.contactService.getDistance(this.ddid, fromtime, totime,this.satelliteDisabled?this.satelite:undefined).subscribe((data3) => { - + + this.contactService.getDistance(this.ddid, fromtime, totime, this.satelliteDisabled ? this.satelite : undefined).subscribe((data3) => { + this.data2 = data3; - + // initialize(); - console.log("__________________",this.data2,this.distanceVariation); + console.log("__________________", this.data2, this.distanceVariation); let a = Number(this.data2["Distance"] ? this.data2["Distance"] : 0); // if(this.distanceVariation){ // if(this.distanceVariation[0]=="+"){ // var milege=(a/100)*(Number(this.distanceVariation.substring(1))) - // console.log("MILEGE->",milege,'-',a); + // console.log("MILEGE->",milege,'-',a); // a=a+milege // }else{ // var milege=(a/100)*(Number(this.distanceVariation.substring(1))) - // console.log("MILEGE->",milege,'-',a); + // console.log("MILEGE->",milege,'-',a); // a=a-milege // } // } if (this.coloumnClicked === false) { tempData['mileage'] = a.toFixed(2); this.tempMapHistory.push(tempData); - + } - + this.total_dis = a; let b = this.data2["Average Speed"] ? this.data2["Average Speed"] : 0; this.avg_speed = b; - + this.ideal_time = this.data2["Idle Time"] ? this.minToHoursConversion(this.data2["Idle Time"]) : 0; if (parseFloat(this.ideal_time) < 0) { this.ideal_time = 0; } - + this.historyDataCondition = true; - + var playerSeekbar: any; - $( document ).ready(function() { - playerSeekbar = document.getElementById('slider1'); - console.log( "ready!", playerSeekbar['value']); - playerSeekbar.oninput = function () { - - zoomToObject(flightPath); - outerThis.changeRange(); - - } - }); + $(document).ready(function () { + playerSeekbar = document.getElementById('slider1'); + console.log("ready!", playerSeekbar['value']); + playerSeekbar.oninput = function () { + + zoomToObject(flightPath); + outerThis.changeRange(); + + } + }); }) + }) }); } - + let min_time = this.minIdleTime; - var deviceObjectid = (this.navId === 'locationHistory')?this.dev_id.id: this.dev_id._id; + var deviceObjectid = (this.navId === 'locationHistory') ? this.dev_id.id : this.dev_id._id; // console.log(deviceObjectid); if (this.idleColor === true) { @@ -4556,28 +4589,28 @@ zoomSet(){ } var stop_locations = []; if (this.parkingColor === true) { - // var from1 = new Date(this.datefrom).toISOString(); - // var to1 = new Date(this.date2).toISOString(); + // var from1 = new Date(this.datefrom).toISOString(); + // var to1 = new Date(this.date2).toISOString(); - // var fromtime = new Date(from1).toISOString(); - // var totime = new Date(to1).toISOString(); - // console.log('this.useriddthis.useridd',this.useridd,"IIIIIIIIIIIIIIIi",this.dev_id.id?this.dev_id.id: this.dev_id._id); - var userid=(this.dev_id.user._id != undefined)?this.dev_id.user._id:this.dev_id.user; - this.contactService.stoppage_points(deviceObjectid, fromtime, totime, userid) - // this.contactService.stoppage_report(fromtime,totime,userid,this.dev_id.id?this.dev_id.id: this.dev_id._id) + // var fromtime = new Date(from1).toISOString(); + // var totime = new Date(to1).toISOString(); + // console.log('this.useriddthis.useridd',this.useridd,"IIIIIIIIIIIIIIIi",this.dev_id.id?this.dev_id.id: this.dev_id._id); + var userid = (this.dev_id.user._id != undefined) ? this.dev_id.user._id : this.dev_id.user; + this.contactService.stoppage_points(deviceObjectid, fromtime, totime, userid) + // this.contactService.stoppage_report(fromtime,totime,userid,this.dev_id.id?this.dev_id.id: this.dev_id._id) .subscribe((res) => { // console.log("===========================>",res,this.parkingArr); // this.parkingArr=res let test = res; // let test = res; this.Load = false; - this.stoppageCount = (test.length != 0)?test.length : 0; + this.stoppageCount = (test.length != 0) ? test.length : 0; for (var i = 0; i < test.length; i++) { this.stoppage_container = []; this.stoppage_container.push(test[i].lat); this.stoppage_container.push(test[i].long); - + this.arrival = new Date(test[i].arrival_time); this.stoppage_container.push(this.arrival); this.departure = new Date(test[i].departure_time); @@ -4587,12 +4620,12 @@ zoomSet(){ } - // debugger; - console.log("initParking",stop_locations.length) + // debugger; + console.log("initParking", stop_locations.length) if (stop_locations.length > 0) { // for(var l=0;l{ - - isMapInit = true; - // ============================ - // var pinImage = new google.maps.MarkerImage("https://png.icons8.com/office/30/000000/parking.png"); - var pinImage = new google.maps.MarkerImage("../../assets/image/parkingPoint1.png"); - var infowindow = new google.maps.InfoWindow(); + var callTimeout = setTimeout(() => { - // var marker: any; - var k: any; - var l: number - + isMapInit = true; + // ============================ + // var pinImage = new google.maps.MarkerImage("https://png.icons8.com/office/30/000000/parking.png"); + var pinImage = new google.maps.MarkerImage("../../assets/image/parkingPoint1.png"); + var infowindow = new google.maps.InfoWindow(); - console.log('stoppagelocationArr',stop_locations.length); - var index=stop_locations.length - for (l = 0; l < stop_locations.length; l++) { - index--; - outerThis.latitude = stop_locations[l][0]; - outerThis.longitude = stop_locations[l][1]; - outerThis.arrivalTime = new Date(stop_locations[l][2]).toLocaleString(); - outerThis.departureTime = new Date(stop_locations[l][3]).toLocaleString(); - outerThis.addresslocation = stop_locations[l][4]; - - var fd = new Date(outerThis.arrivalTime).getTime(); - var td = new Date(outerThis.departureTime).getTime(); - var time_difference = td - fd; - var total_min = time_difference / 60000; - var hours = total_min / 60 - var rhours = Math.floor(hours); - var minutes = (hours - rhours) * 60; - var rminutes = Math.round(minutes); - outerThis.Durations = rhours + ':' + rminutes - let marker = new google.maps.Marker({ - position: new google.maps.LatLng(stop_locations[l][0], stop_locations[l][1]), - map: outerThis.historyMap, - // icon: pinImage, - label: {color: '#000', fontSize: '12px', fontWeight: '600', - text: index.toString()} + // var marker: any; + var k: any; + var l: number - }); - google.maps.event.addListener(marker, 'dragend', function () { + console.log('stoppagelocationArr', stop_locations.length); + var index = stop_locations.length + for (l = 0; l < stop_locations.length; l++) { + index--; + outerThis.latitude = stop_locations[l][0]; + outerThis.longitude = stop_locations[l][1]; + outerThis.arrivalTime = new Date(stop_locations[l][2]).toLocaleString(); + outerThis.departureTime = new Date(stop_locations[l][3]).toLocaleString(); + outerThis.addresslocation = stop_locations[l][4]; - this.geocodePosition(marker.getPosition()); - }); - outerThis.historyMap.setCenter(marker.getPosition()); - // console.log(outerThis.parkingPonit(fromtime,stop_locations,l),'erueruu') - // outerThis.counter=l - - // setTimeout(function(){ + var fd = new Date(outerThis.arrivalTime).getTime(); + var td = new Date(outerThis.departureTime).getTime(); + var time_difference = td - fd; + var total_min = time_difference / 60000; + var hours = total_min / 60 + var rhours = Math.floor(hours); + var minutes = (hours - rhours) * 60; + var rminutes = Math.round(minutes); + outerThis.Durations = rhours + ':' + rminutes + let marker = new google.maps.Marker({ + position: new google.maps.LatLng(stop_locations[l][0], stop_locations[l][1]), + map: outerThis.historyMap, + // icon: pinImage, + label: { + color: '#000', fontSize: '12px', fontWeight: '600', + text: index.toString() + } + + }); + + google.maps.event.addListener(marker, 'dragend', function () { + + this.geocodePosition(marker.getPosition()); + }); + outerThis.historyMap.setCenter(marker.getPosition()); + // console.log(outerThis.parkingPonit(fromtime,stop_locations,l),'erueruu') + // outerThis.counter=l + + // setTimeout(function(){ var content = '
Arrival Time-: ' - + outerThis.arrivalTime + '

Departure Time-: ' - + outerThis.departureTime + '

Time Duration-: ' - + outerThis.Durations + '

Latitude-: ' - + outerThis.latitude + '

Longitude-: ' - + outerThis.longitude + '

' + + outerThis.arrivalTime + '

Departure Time-: ' + + outerThis.departureTime + '

Time Duration-: ' + + outerThis.Durations + '

Latitude-: ' + + outerThis.latitude + '

Longitude-: ' + + outerThis.longitude + '

' // console.log("CONTENt",content)
Odo-:'+dataa+' // },2000) // var dataa // console.log(outerThis.fromTIME,outerThis.stop_locationss,outerThis.counter,"))))))))))))))))"); - + // outerThis.contactService.getDistance(outerThis.ddid, outerThis.fromTIME, (outerThis.stop_locationss[l][2]).toISOString(),outerThis.satelliteDisabled?outerThis.satelite:undefined).subscribe((data3:any) => { - // console.log("DADADADADADADAD--->",data3); + // console.log("DADADADADADADAD--->",data3); // dataa=data3.Distance?data3.Distance:'' // content=content+`
Odo-:`+ data3.Distance?data3.Distance:''+'
' // }) - google.maps.event.addListener(marker, 'click', (function (marker,content, infowindow) { - return function () { - // var dataa - // console.log(outerThis.fromTIME,outerThis.stop_locationss,outerThis.counter,"))))))))))))))))"); - - // outerThis.contactService.getDistance(outerThis.ddid, outerThis.fromTIME, (outerThis.stop_locationss[outerThis.counter][2]).toISOString(),outerThis.satelliteDisabled?outerThis.satelite:undefined).subscribe((data3:any) => { - // console.log("DADADADADADADAD--->",data3); - // dataa=data3.Distance?data3.Distance:'' - // // return data3 - // }) - // setTimeout(function(){ - // content=content+`
Odo-:`+ dataa+'
' - // console.log(content,"+++"); - geocodePosition(marker.getPosition(), function (result) { - infowindow.setContent(content); - infowindow.open(map, marker, content); - }); - // }, 2000); + google.maps.event.addListener(marker, 'click', (function (marker, content, infowindow) { + return function () { + // var dataa + // console.log(outerThis.fromTIME,outerThis.stop_locationss,outerThis.counter,"))))))))))))))))"); + + // outerThis.contactService.getDistance(outerThis.ddid, outerThis.fromTIME, (outerThis.stop_locationss[outerThis.counter][2]).toISOString(),outerThis.satelliteDisabled?outerThis.satelite:undefined).subscribe((data3:any) => { + // console.log("DADADADADADADAD--->",data3); + // dataa=data3.Distance?data3.Distance:'' + // // return data3 + // }) + // setTimeout(function(){ + // content=content+`
Odo-:`+ dataa+'
' + // console.log(content,"+++"); + geocodePosition(marker.getPosition(), function (result) { + infowindow.setContent(content); + infowindow.open(map, marker, content); + }); + // }, 2000); + + } + })(marker, content, infowindow)); + + } + clearTimeout(callTimeout); + }, ttVal) - } - })(marker, content, infowindow)); - - } - clearTimeout(callTimeout); - },ttVal) - } - function initialize() { + function initialize() { const myOptions = { - zoom:8, + zoom: 8, center: new google.maps.LatLng(18.602941, 73.777147), mapTypeId: google.maps.MapTypeId.ROADMAP }; - + map = new google.maps.Map(document.getElementById('map2'), myOptions); // console.log('mapmapmapmapmapmapmapmapmapmapmapmapmapmap',map); outerThis.historyMap = map; var trafficLayer = new google.maps.TrafficLayer(); - if(outerThis.isTraffic){ + if (outerThis.isTraffic) { trafficLayer.setMap(map); - }else{ + } else { trafficLayer.setMap(null); } - - + + isMapInit = true; var zoomBar: any; zoomBar = document.getElementById('myRange'); console.log(map.getZoom()); - + map.setZoom(map.getZoom()); - + zoomBar.value = map.getZoom(); - + zoomBar.oninput = function () { // console.log('zoomValue',map.getZoom()); map.setZoom(parseInt(this.value)); @@ -4763,7 +4798,7 @@ zoomSet(){ zoomBar.value = map.getZoom(); }); - + } @@ -4847,7 +4882,7 @@ zoomSet(){ var sourceIcon = "http://www.googlemapsmarkers.com/v1/S/" + "009933" + "/FFFFFF/000000/ ";//colorForPath var pinImage = new google.maps.MarkerImage(sourceIcon); - var marker = new google.maps.Marker({ + var marker = new google.maps.Marker({ position: mapData[0], map: map, icon: pinImage, @@ -4855,7 +4890,7 @@ zoomSet(){ }); allSourceDestinationMarkers.push(marker); // console.log(allSourceDestinationMarkers); - + var destinationIcon = "http://www.googlemapsmarkers.com/v1/D/" + "FF3300" + "/FFFFFF/000000/ ";//colorForPath var pinImage1 = new google.maps.MarkerImage(destinationIcon); @@ -4930,7 +4965,7 @@ zoomSet(){ "lng": pois[i].poi.location.coordinates[0] }); - var poiIcon="/assets/images/liveTrackIcons/building.jpg" + var poiIcon = "/assets/images/liveTrackIcons/building.jpg" // var poiIcon="https://img.icons8.com/ios-filled/50/000000/building-with-rooftop-terrace.png" // building.jpeg // var poiIcon = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png"; @@ -4945,23 +4980,23 @@ zoomSet(){ poiMarkers.push(marker); var infobox_numberPlate = new InfoBox({ - content: "
" + pois[i].poi.poiname + "
", - disableAutoPan: false, - maxWidth: 150, - alignBottom: true, - pixelOffset: new google.maps.Size(-25, -20), - zIndex: null, - boxStyle: { - opacity: 1, - zIndex: 999, - width: "auto", - padding: "2px" - }, - closeBoxURL: "", - infoBoxClearance: new google.maps.Size(1, 1) - }); + content: "
" + pois[i].poi.poiname + "
", + disableAutoPan: false, + maxWidth: 150, + alignBottom: true, + pixelOffset: new google.maps.Size(-25, -20), + zIndex: null, + boxStyle: { + opacity: 1, + zIndex: 999, + width: "auto", + padding: "2px" + }, + closeBoxURL: "", + infoBoxClearance: new google.maps.Size(1, 1) + }); - infobox_numberPlate.open(map, marker); + infobox_numberPlate.open(map, marker); } @@ -5009,30 +5044,30 @@ zoomSet(){ }); - function zoomToObject(obj){ - var bounds = new google.maps.LatLngBounds(); - var points = obj.getPath().getArray(); - for (var n = 0; n < points.length ; n++){ + function zoomToObject(obj) { + var bounds = new google.maps.LatLngBounds(); + var points = obj.getPath().getArray(); + for (var n = 0; n < points.length; n++) { bounds.extend(points[n]); + } + map.fitBounds(bounds); } - map.fitBounds(bounds); -} - this.parkingData(fromtime, totime,this.useridd,this.dev_id); + this.parkingData(fromtime, totime, this.useridd, this.dev_id); - this.notificationData(fromtime, totime,this.useridd,this.dev_id); + this.notificationData(fromtime, totime, this.useridd, this.dev_id); } - parkingPonit(fromtime,stop_locations,l){ + parkingPonit(fromtime, stop_locations, l) { // console.log(fromtime,stop_locations,l,"--------------"); - - var data - this.contactService.getDistance(this.ddid, fromtime, (stop_locations[l][2]).toISOString(),this.satelliteDisabled?this.satelite:undefined).subscribe((data3:any) => { - // console.log("DADADADADADADAD--->",data3.Distance); - data=data3 - return data3 - }) - } + + var data + this.contactService.getDistance(this.ddid, fromtime, (stop_locations[l][2]).toISOString(), this.satelliteDisabled ? this.satelite : undefined).subscribe((data3: any) => { + // console.log("DADADADADADADAD--->",data3.Distance); + data = data3 + return data3 + }) + } harshImpact(harshVal) { @@ -5148,28 +5183,28 @@ zoomSet(){ // if (this.devicess.devices[i].type_of_device == "Tracker") { - let a = { - did: this.devicess.devices[i].Device_ID, - dname: this.devicess.devices[i].Device_Name - } - this.device_imei.push(a); + let a = { + did: this.devicess.devices[i].Device_ID, + dname: this.devicess.devices[i].Device_Name } + this.device_imei.push(a); + } // } this.geoFenceaction(this.device_imei) }); } - minToHoursConversion(num){ - var hours = Math.floor(num / 3600); -num %= 3600; -var minutes = Math.floor(num / 60); -var seconds = num % 60; -// var hours = (num / 60); -// var rhours = Math.floor(hours); -// var minutes = (hours - rhours) * 60; -// var rminutes = Math.round(minutes); - return hours + " hrs " + minutes + " min "; + minToHoursConversion(num) { + var hours = Math.floor(num / 3600); + num %= 3600; + var minutes = Math.floor(num / 60); + var seconds = num % 60; + // var hours = (num / 60); + // var rhours = Math.floor(hours); + // var minutes = (hours - rhours) * 60; + // var rminutes = Math.round(minutes); + return hours + " hrs " + minutes + " min "; } //GeoFence Action @@ -5244,12 +5279,12 @@ var seconds = num % 60; if (type == "Tracker") { //this.router.navigateByUrl("location?_dname="+name+"_id="+id); this.share_id = device; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("111111111133333"); this.livetrack(id) } - + } else { @@ -5262,18 +5297,18 @@ var seconds = num % 60; let mapLanguage = localStorage.getItem('appLang'); this.token_identifier = localStorage.getItem('referrer_token='); // console.log('mapLanguage',mapLanguage); - if((mapLanguage == null)||(mapLanguage == undefined)){ - mapLanguage = 'en'; + if ((mapLanguage == null) || (mapLanguage == undefined)) { + mapLanguage = 'en'; } - if(mapLanguage == 'sp'){ - mapLanguage = 'es'; + if (mapLanguage == 'sp') { + mapLanguage = 'es'; } - if(mapLanguage == 'fa'){ - mapLanguage = 'fas'; + if (mapLanguage == 'fa') { + mapLanguage = 'fas'; } - if(mapLanguage == 'fr'){ - mapLanguage = 'fr'; + if (mapLanguage == 'fr') { + mapLanguage = 'fr'; } @@ -5282,21 +5317,21 @@ var seconds = num % 60; // script.setAttribute("type", "text/javascript"); // script.setAttribute("src", "https://maps.google.com/maps/api/js?libraries=geometry,places,drawing&key=AIzaSyCNT3eO1wPQHUhY_cmQ9N_9BkLzJ_GB9j8&language=" + mapLanguage); // document.getElementsByTagName("head")[0].appendChild(script); - - + + let tblid; let status = false; var cuTime = new Date(); this.currentTime = moment(cuTime).format(); - + this.activatedRoute.queryParams.subscribe((params: Params) => { this.navId = params['pageid']; - - if(this.navId === 'locationHistory'){ + + if (this.navId === 'locationHistory') { this.tabIndexValue = "2"; this.showHistory = true; - this.tab_1 = true; + this.tab_1 = true; this.tab_2 = true; navigator.geolocation.getCurrentPosition(function (position) { var myOptions = { @@ -5308,7 +5343,7 @@ var seconds = num % 60; mapTypeId: google.maps.MapTypeId.ROADMAP }; var mapHistory = new google.maps.Map(document.getElementById("map2"), myOptions); - + var marker = new google.maps.Marker({ center: { lat: position.coords.latitude, @@ -5317,14 +5352,14 @@ var seconds = num % 60; map: mapHistory, title: "Your current location!", }); - + }) } // locationComponent }) - + } fs: any; @@ -5436,21 +5471,21 @@ var seconds = num % 60; if (!this.prev_map) { this.MapLoad = true; if (this.current_map == "True") { - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("111111111144444"); - this.livetrack(null) ; + this.livetrack(null); } - + this.prev_map = window.localStorage.mapLoad_ID; this.showButton = true; } else { // console.log(window.localStorage.mapLoad_ID); - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("111111115555555"); this.livetrack(window.localStorage.mapLoad_ID); } - + this.prev_map = window.localStorage.mapLoad_ID; this.showButton = true; } @@ -5461,22 +5496,22 @@ var seconds = num % 60; } else if (this.current_map == "True") { this.MapLoad = true; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("11111111666666"); - this.livetrack(null); + this.livetrack(null); } - + this.prev_map = window.localStorage.mapLoad_ID; this.showButton = true; } else if (this.prev_map != this.current_map) { this.MapLoad = true; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("1111111777777"); this.livetrack(window.localStorage.mapLoad_ID) } - + this.prev_map = window.localStorage.mapLoad_ID; this.showButton = true; } @@ -5494,25 +5529,25 @@ var seconds = num % 60; datefrom = new Date(); gaugeString: any = 'PERCENTAGE'; gaugeDataticks: any = '0,20,40,60,80,100'; - newFunction(){ - + newFunction() { + } - + ngOnInit() { this.injectData.setGPSConnection(); window["angularComponentRef"] = { component: this, zone: this._ngZone }; this.socket = this.injectData.getSocket_gps(); this.socket.on('connect', function (this) { }); - this.socket_Notify = this.injectData.getSocket_notifIO(); - this.socket_Notify.on('connect', function(this){ - console.log('notify connect ',this); + this.socket_Notify = this.injectData.getSocket_notifIO(); + this.socket_Notify.on('connect', function (this) { + console.log('notify connect ', this); }); - this.bsConfig = Object.assign({dateInputFormat: 'DD-MM-YYYY, h:mm:ss a'}, { containerClass: this.colorTheme }); + this.bsConfig = Object.assign({ dateInputFormat: 'DD-MM-YYYY, h:mm:ss a' }, { containerClass: this.colorTheme }); // console.log('this.bsConfig',this.bsConfig); - + this.to = new Date().toISOString(); var d = new Date(); let a = d.setHours(0, 0, 0, 0) @@ -5585,7 +5620,7 @@ var seconds = num % 60; this.gaugeString = 'LITRE'; // this.gaugeDataticks = '0,20,40,60,80,100'; // window.onload = function () { - // console.log("inside percentage"); + // console.log("inside percentage"); // var gaugeElement = document.getElementById('fuelgauge'); // // gaugeElement.setAttribute('data-units', 'LITRE'); // // gaugeElement.setAttribute('data-major-ticks', "0,80,160,240,320,400,480"); @@ -5594,7 +5629,7 @@ var seconds = num % 60; } - + if (this.superAdmin == true) { this.supadmin = this.useridd; @@ -5633,11 +5668,11 @@ var seconds = num % 60; // console.log("this.fin=>",this.fin); this.fin = this.getData.split("=")[1]; } - // console.log(this.fin); + // console.log(this.fin); }); - if(this.token_identifier != undefined){ + if (this.token_identifier != undefined) { this.fin = null } @@ -5682,24 +5717,24 @@ var seconds = num % 60; this.getDevicebyIdComingFromDashboard(); this.getGeofence_1(); // this.testMap() - this. getGrp() + this.getGrp() this.modelChanged .debounceTime(2000) // wait 300ms after the last event before emitting last event .distinctUntilChanged() // only emit if value is different from previous value .subscribe(myInput => { var searchObj = JSON.parse(myInput); - + this.myInput = searchObj.str; - (searchObj.identifier == 'devSearch') ? this.getDeviceBYfilter('','') : this.getGeofence_1() - + (searchObj.identifier == 'devSearch') ? this.getDeviceBYfilter('', '') : this.getGeofence_1() + }); - this.getUserDetails(); - $('addPOI').click(function() { - alert("GeeksForGeeks"); - }); - + this.getUserDetails(); + $('addPOI').click(function () { + alert("GeeksForGeeks"); + }); + } // className:any; @@ -5714,32 +5749,32 @@ var seconds = num % 60; } localStorage.removeItem('devDetail'); - if(this.status_cmdq!=undefined){ + if (this.status_cmdq != undefined) { clearInterval(this.status_cmdq) } - if(this.intervalTimeOut!=undefined){ + if (this.intervalTimeOut != undefined) { clearTimeout(this.intervalTimeOut); } - - + + window["angularComponentRef"] = null; - if( this.socket_Notify){ + if (this.socket_Notify) { this.socket_Notify.removeAllListeners() } this.injectData.removedGPSConnection(); } - GetRowPacketEvent(data) { - this.contactService.GetRowPacket(data).subscribe((res: any) => { - document.getElementById(data).innerHTML = ''; - document.getElementById('display_row' + data).innerHTML = res.raw ? res.raw : 'NA'; - + GetRowPacketEvent(data) { + this.contactService.GetRowPacket(data).subscribe((res: any) => { + document.getElementById(data).innerHTML = ''; + document.getElementById('display_row' + data).innerHTML = res.raw ? res.raw : 'NA'; - }) - } + + }) + } addpoi(lat) { // var lattitude = JSON.parse(lat); var latlng = JSON.stringify(lat).substring(1, lat.length - 1); @@ -5772,11 +5807,11 @@ var seconds = num % 60; DriverNumber ac; power; - todaysOdo=0; - fuelConsumption=0 + todaysOdo = 0; + fuelConsumption = 0 getAllDevice() { // this.Load = true; - + if (this.dev_by_dashboard != null) { this.disableSearch = true // console.log(this.disableSearch); @@ -5786,23 +5821,23 @@ var seconds = num % 60; this.contactService.alldevices1(this.useridd, this.emailid, this.supadmin, this.dealerid, search_1) .subscribe(res => { this.deviceObj = []; - + var Alldevices = { id: "all", viewValue: "ALL Devices", iconType: "", deviceId: "" } - if(res.devices.length==1){ - this.selectedDevice=res.devices[0]._id - this.parkingButtonShow=res.devices[0].theftAlert==null?'grey':res.devices[0].theftAlert==undefined?'grey':res.devices[0].theftAlert==true?'green':'red' - this.DriverName=res.devices[0].driver_name; + if (res.devices.length == 1) { + this.selectedDevice = res.devices[0]._id + this.parkingButtonShow = res.devices[0].theftAlert == null ? 'grey' : res.devices[0].theftAlert == undefined ? 'grey' : res.devices[0].theftAlert == true ? 'green' : 'red' + this.DriverName = res.devices[0].driver_name; // console.log("DRIVER NAME",this.DriverName,res.devices[0].ac); - this.ac=res.devices[0].ac?res.devices[0].ac:'NA' - this.power=res.devices[0].power?res.devices[0].power:'NA' - this.todaysOdo=res.devices[0].today_odo?res.devices[0].today_odo:0; - this.fuelConsumption=(res.devices[0].Mileage && res.devices[0].total_odo)?(res.devices[0].total_odo/res.devices[0].Mileage):0 - this.DriverNumber=res.devices[0].contact_number + this.ac = res.devices[0].ac ? res.devices[0].ac : 'NA' + this.power = res.devices[0].power ? res.devices[0].power : 'NA' + this.todaysOdo = res.devices[0].today_odo ? res.devices[0].today_odo : 0; + this.fuelConsumption = (res.devices[0].Mileage && res.devices[0].total_odo) ? (res.devices[0].total_odo / res.devices[0].Mileage) : 0 + this.DriverNumber = res.devices[0].contact_number } // console.log("device obj =>",res.devices); this.deviceObj.push(Alldevices); @@ -5817,11 +5852,11 @@ var seconds = num % 60; } this.final = res.devices; - + for (let i = 0; i < this.final.length; i++) { this.final[i]['checked'] = true; // this.deviceList = this.final; - + if (this.final[i].type_of_device == "Tracker") { let a = { value: this.final[i].Device_Name, @@ -5836,18 +5871,18 @@ var seconds = num % 60; } this.foods.push(a); - + } } - + // console.log('this.deviceList=>=>',this.deviceList); - let that= this; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + let that = this; + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log(this.fin, this.fin); // this.deviceList.filter((dl,index)=>{ - // console.log(dl,index); + // console.log(dl,index); // if(dl.Device_ID === this.fin){ // that.deviceList[index]['checked'] = true; // } @@ -5855,7 +5890,7 @@ var seconds = num % 60; // console.log("1111111188888"); this.livetrack(this.fin); } - + for (let y = 0; y < this.foods.length; y++) { if (this.foods[y].did == this.fin) { this.new = this.foods[y]; @@ -5869,40 +5904,40 @@ var seconds = num % 60; // console.log(err); }) } - filterDevicesNew(dlr) { - if ((this.navId === 'locationHistory')) { - if (dlr) { - const filterdealerValue: any = dlr; - this.foods = []; - this.masterFoods.forEach(pp => { - let t = pp.viewValue.toLocaleLowerCase().indexOf(filterdealerValue.toLocaleLowerCase()); - if (t > -1) { - this.foods.push(pp) - } - }); - } else { - this.foods = [...this.masterFoods]; - } - - } - this.sortFoodDataByKey(); - } - sortFoodDataByKey() { - this.foods.sort((a, b) => { - let fa = a.viewValue.toLowerCase(), - fb = b.viewValue.toLowerCase(); + filterDevicesNew(dlr) { + if ((this.navId === 'locationHistory')) { + if (dlr) { + const filterdealerValue: any = dlr; + this.foods = []; + this.masterFoods.forEach(pp => { + let t = pp.viewValue.toLocaleLowerCase().indexOf(filterdealerValue.toLocaleLowerCase()); + if (t > -1) { + this.foods.push(pp) + } + }); + } else { + this.foods = [...this.masterFoods]; + } - if (fa < fb) { - return -1; - } - if (fa > fb) { - return 1; - } - return 0; - }) - } + } + this.sortFoodDataByKey(); + } + sortFoodDataByKey() { + this.foods.sort((a, b) => { + let fa = a.viewValue.toLowerCase(), + fb = b.viewValue.toLowerCase(); + + if (fa < fb) { + return -1; + } + if (fa > fb) { + return 1; + } + return 0; + }) + } filterDevices(dlr) { - + // console.log("=========>",dlr,this.foods); if (dlr.length == 0) { this.deviceSelect = []; @@ -5910,22 +5945,22 @@ var seconds = num % 60; if (dlr) { const filterdealerValue: any = dlr; this.deviceSelect = []; - if((this.navId === 'locationHistory')){ + if ((this.navId === 'locationHistory')) { this.deviceSelect = this.foods.filter(function (pp) { var t = pp.viewValue.toLocaleLowerCase().indexOf(filterdealerValue.toLocaleLowerCase()); return t > -1; }); - + // this.buindhistoryDevice = this.deviceSelect; // console.log("this.deviceSelectthis.deviceSelectthis.deviceSelect",this.deviceSelect); return this.deviceSelect; - }else{ + } else { this.deviceSelect = this.deviceList.filter(function (pp) { var t = pp.Device_ID.toLocaleLowerCase().indexOf(filterdealerValue.toLocaleLowerCase()); return t > -1; }); - + this.buindhistoryDevice = this.deviceSelect; // console.log("this.deviceSelectthis.deviceSelectthis.deviceSelect",this.deviceSelect); // localStorage.setItem('devDetail',JSON.stringify({vehicleId:this.deviceSelect[0].did, @@ -5933,15 +5968,15 @@ var seconds = num % 60; // vehicleType: this.deviceSelect[0].deviceType})) // this.imei=this.deviceSelect[0].did // console.log("IMEI===>",this.imei); - + return this.deviceSelect; } - + } } count: number = 0; iconSelector(status, iconType, msg) { - + // var tempSpeed = msg.speed; // var tempIgn = msg.ignition; @@ -5976,7 +6011,7 @@ var seconds = num % 60; } else if (iconType == 'tractor') { iconUrl = '/assets/images/liveTrackIcons/otractor.png'; return iconUrl; - } else if (iconType == 'jcb') { + } else if (iconType == 'jcb') { iconUrl = '/assets/images/liveTrackIcons/ourjcb.png'; return iconUrl; } @@ -5984,7 +6019,7 @@ var seconds = num % 60; iconUrl = '/assets/images/liveTrackIcons/ambulance_b.png'; return iconUrl; } - else { + else { iconUrl = '/assets/images/liveTrackIcons/user_b.png'; return iconUrl; } @@ -6005,13 +6040,13 @@ var seconds = num % 60; } else if (iconType == 'tractor') { iconUrl = '/assets/images/liveTrackIcons/stractor.png'; return iconUrl; - }else if (iconType == 'jcb') { + } else if (iconType == 'jcb') { iconUrl = '/assets/images/liveTrackIcons/stoppedjcb.png'; return iconUrl; - } else if (iconType == 'ambulance') { + } else if (iconType == 'ambulance') { iconUrl = '/assets/images/liveTrackIcons/ambulance_r.png'; return iconUrl; - }else { + } else { iconUrl = '/assets/images/liveTrackIcons/user_r.png'; return iconUrl; } @@ -6031,11 +6066,11 @@ var seconds = num % 60; } else if (iconType == 'tractor') { iconUrl = '/assets/images/liveTrackIcons/rtractor.png'; return iconUrl; - } else if(iconType == 'jcb'){ + } else if (iconType == 'jcb') { iconUrl = '/assets/images/liveTrackIcons/runningjcb.png'; return iconUrl; - } else if (iconType == 'ambulance') { + } else if (iconType == 'ambulance') { iconUrl = '/assets/images/liveTrackIcons/ambulance_g.png'; return iconUrl; } else { @@ -6058,18 +6093,18 @@ var seconds = num % 60; } else if (iconType == 'tractor') { iconUrl = '/assets/images/liveTrackIcons/itractor.png'; return iconUrl; - }else if(iconType == "jcb" ){ + } else if (iconType == "jcb") { iconUrl = '/assets/images/liveTrackIcons/idlingjcb.png'; - return iconUrl; + return iconUrl; } else if (iconType == 'ambulance') { iconUrl = '/assets/images/liveTrackIcons/ambulance_y.png'; return iconUrl; - } else { + } else { iconUrl = '/assets/images/liveTrackIcons/user_y.png'; return iconUrl; } - }else if (status == "NO DATA") { + } else if (status == "NO DATA") { if (iconType == 'bike') { iconUrl = '/assets/image/no_data.png'; return iconUrl; @@ -6085,7 +6120,7 @@ var seconds = num % 60; } else if (iconType == 'tractor') { iconUrl = '/assets/image/no_data.png'; return iconUrl; - } else if(iconType == 'jcb'){ + } else if (iconType == 'jcb') { iconUrl = '/assets/image/no_data.png'; return iconUrl; } else { @@ -6186,12 +6221,12 @@ var seconds = num % 60; var DeviceObj = JSON.parse(localStorage.getItem('devDetail')); if (DeviceObj != undefined) { // console.log('DeviceObj',DeviceObj); - this.contactService.getdevById(DeviceObj.vehicleId).subscribe((res:any) => { + this.contactService.getdevById(DeviceObj.vehicleId).subscribe((res: any) => { // console.log("lastTripStatus",res); // this.getLastTrip();\ var tempObj = JSON.parse(res['_body']); - this.distanceVariation=tempObj.distanceVariation?tempObj.distanceVariation:undefined - + this.distanceVariation = tempObj.distanceVariation ? tempObj.distanceVariation : undefined + this.IMEI = tempObj._id; @@ -6209,7 +6244,7 @@ var seconds = num % 60; getLastTrip(imei) { // console.log("IMEI==>",imei); - + this.contactService.getLastTripStatus('last_trip', 'Started', imei).subscribe(res => { // console.log("lastTripStatus", res); if (res.message != "No Trip Found") { @@ -6220,7 +6255,7 @@ var seconds = num % 60; this.playPause = true; } var outerThis = this; - this.deviceList.filter(function (colHilight, i) { + this.deviceList.filter(function (colHilight, i) { if (colHilight.Device_ID === imei) { outerThis.deviceList[i].playPause = outerThis.playPause; } @@ -6432,9 +6467,9 @@ var seconds = num % 60; function geocodePosition(pos, callback) { try { - + } catch (error) { - + } var geocoder = new google.maps.Geocoder(); geocoder.geocode({ @@ -6491,7 +6526,7 @@ var seconds = num % 60; // } - AllVeh: any = [{ 'status': 'Total', 'totalCount': '0' },{ 'status': 'Running', 'totalCount': '0' }, { 'status': 'Idle', 'totalCount': '0' }, { 'status': 'Stopped', 'totalCount': '0' }, { 'status': 'Inactive', 'totalCount': '0' }, { 'status': 'No data', 'totalCount': '0' }] + AllVeh: any = [{ 'status': 'Total', 'totalCount': '0' }, { 'status': 'Running', 'totalCount': '0' }, { 'status': 'Idle', 'totalCount': '0' }, { 'status': 'Stopped', 'totalCount': '0' }, { 'status': 'Inactive', 'totalCount': '0' }, { 'status': 'No data', 'totalCount': '0' }] deviceData = [ { @@ -6617,54 +6652,54 @@ var seconds = num % 60; - ]; + ]; myInput: any; - updateLiveTracking(device,ev) { - this.showAddress=true + updateLiveTracking(device, ev) { + this.showAddress = true var that = this; // this.openRightMenu() - if(device){ - // console.log(device); - this.selectedDevice=device._id - this.parkingButtonShow=device.theftAlert==null?'grey':device.theftAlert==undefined?'grey':device.theftAlert==true?'green':'red' - this.DriverName=device.driver_name; - // console.log("DRIVER NAME",this.DriverName,device.ac); - this.ac=device.ac?device.ac:'NA' - this.DriverNumber=device.contact_number + if (device) { + // console.log(device); + this.selectedDevice = device._id + this.parkingButtonShow = device.theftAlert == null ? 'grey' : device.theftAlert == undefined ? 'grey' : device.theftAlert == true ? 'green' : 'red' + this.DriverName = device.driver_name; + // console.log("DRIVER NAME",this.DriverName,device.ac); + this.ac = device.ac ? device.ac : 'NA' + this.DriverNumber = device.contact_number - } - - console.log('this.markerArray________________________--',this.socketData); + } + + console.log('this.markerArray________________________--', this.socketData); this.showSocketData = true; - if(this.socketData) - this.socketData.date=new Date() + if (this.socketData) + this.socketData.date = new Date() this.flightPathArr = []; // localStorage.setItem('devDetail',device) this.temptrackingDev = device.Device_ID; - var td= this.filterDevices(device.Device_ID); - this.tempDevInfo =td[0]; - this.deviceList.filter((dl,index)=>{ - if(dl.Device_ID == device.Device_ID){ - var ilock =that.deviceList[index].ignitionLock; - if((ilock === '1')&&(ev === 'lockchange')){ - + var td = this.filterDevices(device.Device_ID); + this.tempDevInfo = td[0]; + this.deviceList.filter((dl, index) => { + if (dl.Device_ID == device.Device_ID) { + var ilock = that.deviceList[index].ignitionLock; + if ((ilock === '1') && (ev === 'lockchange')) { + that.deviceList[index].ignitionLock = '0'; } - if((ilock === '0')&&(ev === 'lockchange')){ - + if ((ilock === '0') && (ev === 'lockchange')) { + that.deviceList[index].ignitionLock = '1'; } that.deviceList[index].checked = true; - - }else{ + + } else { that.deviceList[index].checked = false; } - + }) - - - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + + + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("1111111199999"); this.livetrack(device.Device_ID); } @@ -6757,7 +6792,7 @@ var seconds = num % 60; this.AllVeh[4].totalCount = this.OutOfReach; this.AllVeh[5].totalCount = this.no_data; // console.log("DAtatatatat---",this.AllVeh); - + }); } @@ -6766,17 +6801,17 @@ var seconds = num % 60; limit: number = 100; firstcall: boolean = false; lastcall: boolean = true; - devReady:boolean=true; - groups=[] - getDeviceBYfilter(i,iden) { - console.log(i,iden); + devReady: boolean = true; + groups = [] + getDeviceBYfilter(i, iden) { + console.log(i, iden); this.currStatus = i; - if (this.currStatus =='Total'){ + if (this.currStatus == 'Total') { this.ngOnInit(); } - else{ + else { if (i == 6) { this.skip = 0; } @@ -6883,10 +6918,10 @@ var seconds = num % 60; this.buindhistoryDevice = []; var DeviceObj = JSON.parse(localStorage.getItem('devDetail')); if (DeviceObj != undefined) { - this.contactService.getdevById(DeviceObj.vehicleId).subscribe((res:any) => { + this.contactService.getdevById(DeviceObj.vehicleId).subscribe((res: any) => { var tempObj = JSON.parse(res['_body']); - this.distanceVariation=tempObj.distanceVariation?tempObj.distanceVariation:undefined - tempObj['checked']=true + this.distanceVariation = tempObj.distanceVariation ? tempObj.distanceVariation : undefined + tempObj['checked'] = true // console.log('tempObjtempObjtempObjtempObj', tempObj); this.temptrackingDev = tempObj.Device_ID; this.buindhistoryDevice.push(tempObj); @@ -6896,7 +6931,7 @@ var seconds = num % 60; // console.log(err); }) } else { - this.getDeviceBYfilter('',''); + this.getDeviceBYfilter('', ''); } } @@ -6904,18 +6939,18 @@ var seconds = num % 60; next() { this.lastcall = false; this.skip += 1; - this.getDeviceBYfilter(this.currStatus,'tclick'); + this.getDeviceBYfilter(this.currStatus, 'tclick'); } refresh() { this.getGraphFunction(); - this.getDeviceBYfilter(this.currStatus,''); + this.getDeviceBYfilter(this.currStatus, ''); } pre() { if (this.skip > 0) { this.skip -= 1; - this.getDeviceBYfilter(this.currStatus,'tclick'); + this.getDeviceBYfilter(this.currStatus, 'tclick'); this.lastcall = false; } else { this.lastcall = true; @@ -6965,11 +7000,11 @@ var seconds = num % 60; if (ev == 0) { this.headingName = 'Live Tracking'; this.showSocketData = true; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { // console.log("1111111111-11-"); this.livetrack(this.temptrackingDev); } - + // this.refresh_map(); } if (ev == 1) { @@ -7093,9 +7128,9 @@ var seconds = num % 60; var yt = moment().subtract(1, 'days'); var ptt = new Date(yt).setHours(0, 0, 0); this.datefrom = new Date(ptt); - var ttt = new Date(yt).setHours(23,59,59); + var ttt = new Date(yt).setHours(23, 59, 59); this.date2 = new Date(ttt); - + // console.log('this.datefrom', this.datefrom); } if (dateid == 'week') { @@ -7135,7 +7170,7 @@ var seconds = num % 60; engineCutStatus = ''; engineCut(device) { this.engineCutStatus = device.ignitionLock; - + var identifyType = typeof (device.user); var userId; if (identifyType == 'string') { @@ -7149,7 +7184,7 @@ var seconds = num % 60; this.contactService.checkForPassword(pload).subscribe(res => { // console.log('resres', res); var engCutPass = res.engine_cut_psd; - if ((engCutPass == undefined)||(this.superAdmin ===true)||(this.custtype === true)) { + if ((engCutPass == undefined) || (this.superAdmin === true) || (this.custtype === true)) { this.immobilizeDevice(device, this.engineCutStatus); } else { let dialogRef = this.dialog.open(ImmobilizeComponent, { @@ -7198,63 +7233,63 @@ var seconds = num % 60; } - callLiveTracking= 0; + callLiveTracking = 0; triggerCmd(cmdObj, deviceCommand) { // console.log("inside triggerCmd function"); - var that = this; - this.callLiveTracking= 0; - // var iurl = '../../assets/image/idle_bus.png'; + var that = this; + this.callLiveTracking = 0; + // var iurl = '../../assets/image/idle_bus.png'; // this.Load = true; - that.errIcon =false; - that.immobilizeCount = 45; + that.errIcon = false; + that.immobilizeCount = 45; that.immobilizeChk = true; - var timer = setInterval(()=>{ + var timer = setInterval(() => { // console.log("that.immobilizeCount--",that.immobilizeCount--); that.immobilizeCount-- // console.log('timer Value',that.immobilizeCount--); - if( that.immobilizeCount=== 0){ + if (that.immobilizeCount === 0) { clearInterval(timer); } - },1000) + }, 1000) this.contactService.addCommandQueue(cmdObj).subscribe(res => { // this.Load = false; // console.log(res); var cmdQId = res._id; // console.log('cmdQId', cmdQId); - this.intervalTimeOut = setTimeout(function(){ + this.intervalTimeOut = setTimeout(function () { let message = "Please Try After Sometime"; // let action // that.snackBar.open(message, action, { // duration: 4000, - - // }); - that.errIcon =true; - that.showErr = true; - that.ImmErrMsg = message ; - that.shoError = setTimeout(()=>{ - that.immobilizeChk = false; - that.showErr = false; - clearTimeout(that.shoError) - },5000) - clearInterval(that.status_cmdq); - clearTimeout(that.intervalTimeOut); - clearInterval(timer); - },45000) + // }); + that.errIcon = true; + that.showErr = true; + that.ImmErrMsg = message; + that.shoError = setTimeout(() => { + that.immobilizeChk = false; + that.showErr = false; + clearTimeout(that.shoError) + }, 5000) + clearInterval(that.status_cmdq); + clearTimeout(that.intervalTimeOut); + + clearInterval(timer); + }, 45000) that.status_cmdq = setInterval(function () { that.contactService.getEngineCutStatus(cmdQId) - .subscribe(res => { - that.locked = false; - that.unlocked = false; + .subscribe(res => { + that.locked = false; + that.unlocked = false; if (res.status == "SUCCESS") { that.Load = false; var cc = '' - if(deviceCommand === 'ON'){ + if (deviceCommand === 'ON') { cc = 'UNLOCKED'; that.unlocked = true; } - if(deviceCommand === 'OFF'){ + if (deviceCommand === 'OFF') { cc = 'LOCKED'; that.locked = true; } @@ -7263,41 +7298,41 @@ var seconds = num % 60; // that.snackBar.open(message, action, { // duration: 4000, // }); - that.showErr = true; - that.ImmErrMsg = message ; - that.shoError = setTimeout(()=>{ - that.immobilizeChk = false; - that.showErr = false; - clearTimeout(that.shoError); - },5000) + that.showErr = true; + that.ImmErrMsg = message; + that.shoError = setTimeout(() => { + that.immobilizeChk = false; + that.showErr = false; + clearTimeout(that.shoError); + }, 5000) // console.log("Console after Getting success",that.callLiveTracking); - - if(that.callLiveTracking === 0){ - that.callLiveTracking = 1; - + + if (that.callLiveTracking === 0) { + that.callLiveTracking = 1; + that.deviceCQ(cmdObj.imei); - that.updateLiveTracking(cmdObj.imei,'lockchange'); + that.updateLiveTracking(cmdObj.imei, 'lockchange'); // that.refresh(); - + } - + clearInterval(timer); clearTimeout(that.intervalTimeOut) clearInterval(that.status_cmdq); // that.immobilizeChk = false; // that.Load = false - + } }, err => { - that.errIcon =true; + that.errIcon = true; let message = "Please Try After Sometime"; - that.showErr = true; - that.ImmErrMsg = message ; - that.shoError = setTimeout(()=>{ - that.immobilizeChk = false; - that.showErr = false; - clearTimeout(that.shoError) - },5000) + that.showErr = true; + that.ImmErrMsg = message; + that.shoError = setTimeout(() => { + that.immobilizeChk = false; + that.showErr = false; + clearTimeout(that.shoError) + }, 5000) let action; that.immobilizeChk = false; clearInterval(timer); @@ -7380,7 +7415,7 @@ var seconds = num % 60; }); var str = (this.currStatus == undefined) ? '' : this.currStatus; this.getGraphFunction(); - this.getDeviceBYfilter(str,''); + this.getDeviceBYfilter(str, ''); }, err => { this.Load = false; @@ -7393,9 +7428,9 @@ var seconds = num % 60; }) } - enableMapTrail(){ - this.enabletrail = !this.enabletrail; - if(this.enabletrail == false){ + enableMapTrail() { + this.enabletrail = !this.enabletrail; + if (this.enabletrail == false) { this.flightPathArr = []; // this.flightPath_live = new google.maps.Polyline({ // path: this.flightPathArr, @@ -7404,86 +7439,86 @@ var seconds = num % 60; // strokeColor: "#0000FF", // strokeWeight: 6 // }); - + this.flightPath_live.setMap(null); - }else{ + } else { var a = [] this.draw_flight_trail(a); } - - - + + + } - flightPath_live:any - elm=0 - draw_flight_trail(flightPathArr){ - var tempTimeInterval ; + flightPath_live: any + elm = 0 + draw_flight_trail(flightPathArr) { + var tempTimeInterval; var that = this; - var time=6000; - // if(that.elm>0){ - // time = 30000 - // } - // that.elm++; - if(flightPathArr.length != 0){ + var time = 6000; + // if(that.elm>0){ + // time = 30000 + // } + // that.elm++; + if (flightPathArr.length != 0) { console.log("ARRAY", flightPathArr); - - if(that.elm){ + + if (that.elm) { flightPathArr.splice(0, 0, that.elm) flightPathArr.join() } console.log("ARRAY", flightPathArr); that.elm = flightPathArr[flightPathArr.length - 1]; - flightPathArr.splice(flightPathArr.length - 1,1); + flightPathArr.splice(flightPathArr.length - 1, 1); console.log("ARRAY2", flightPathArr); clearTimeout(tempTimeInterval); - tempTimeInterval = setTimeout(function(){ - that.flightPath_live = new google.maps.Polyline({ - path: flightPathArr, - geodesic: true, - strokeColor: "#0000FF", - strokeOpacity: 1.0, - strokeWeight: 6 - }); - // console.log(mapData); - that.flightPath_live.setMap(that.mapNew); - },time) - + tempTimeInterval = setTimeout(function () { + that.flightPath_live = new google.maps.Polyline({ + path: flightPathArr, + geodesic: true, + strokeColor: "#0000FF", + strokeOpacity: 1.0, + strokeWeight: 6 + }); + // console.log(mapData); + that.flightPath_live.setMap(that.mapNew); + }, time) + } - + } - saveAddress(lat,lng,address){ + saveAddress(lat, lng, address) { var addressObj = { - "lat":lat, - "long":lng, - "address":address - } - this.contactService.saveAdd(addressObj).subscribe(res=>{ + "lat": lat, + "long": lng, + "address": address + } + this.contactService.saveAdd(addressObj).subscribe(res => { // console.log(res); - },err=>{ + }, err => { // console.log("couldn't save address"); }) } - convertDate(utcDate){ - var convertedDate:any; - if(utcDate != undefined){ + convertDate(utcDate) { + var convertedDate: any; + if (utcDate != undefined) { convertedDate = new Date(utcDate).toLocaleString(); - }else{ + } else { convertedDate = ''; } - - return convertedDate ; + + return convertedDate; } - devIcon : any; + devIcon: any; iconCheck(status, iconType) { - + var devStatus = status.split(" "); if ((iconType == 'car') && (devStatus[0] == "OUT")) { @@ -7498,7 +7533,7 @@ var seconds = num % 60; } else if ((iconType == 'car') && (devStatus[0] == "IDLING")) { this.devIcon = "../../assets/image/idle_car.png"; return this.devIcon; - } else if ((iconType == 'car') && (devStatus[0] == "NO")) { + } else if ((iconType == 'car') && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; } else if ((iconType == 'bike') && (devStatus[0] == "OUT")) { @@ -7514,7 +7549,7 @@ var seconds = num % 60; this.devIcon = "../../assets/image/idle_bike.png"; return this.devIcon; // } - } else if ((iconType == 'bike') && (devStatus[0] == "NO")) { + } else if ((iconType == 'bike') && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; } else if ((iconType == 'bus') && (devStatus[0] == "OUT")) { @@ -7565,40 +7600,40 @@ var seconds = num % 60; return this.devIcon; } else if ((iconType == 'ambulance') && (devStatus[0] == "OUT")) { - + this.devIcon = "../../assets/images/liveTrackIcons/ambulance_b.png"; return this.devIcon; } else if ((iconType == 'ambulance') && (devStatus[0] == "RUNNING")) { - + this.devIcon = "../../assets/images/liveTrackIcons/ambulance_g.png"; - return this.devIcon; - } else if ((iconType == 'ambulance') && (devStatus[0] == "STOPPED")) { + return this.devIcon; + } else if ((iconType == 'ambulance') && (devStatus[0] == "STOPPED")) { this.devIcon = "../../assets/images/liveTrackIcons/ambulance_r.png"; return this.devIcon; - } else if ((iconType == 'ambulance') && (devStatus[0] == "IDLING")) { + } else if ((iconType == 'ambulance') && (devStatus[0] == "IDLING")) { this.devIcon = "../../assets/images/liveTrackIcons/ambulance_y.png"; - return this.devIcon; - } + return this.devIcon; + } else if ((iconType == 'tractor') && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; } - else if((!iconType)&&(devStatus[0] == "OUT")){ + else if ((!iconType) && (devStatus[0] == "OUT")) { this.devIcon = "../../assets/image/outOfReach_car.png"; return this.devIcon; - } else if((!iconType)&&(devStatus[0] == "RUNNING")){ + } else if ((!iconType) && (devStatus[0] == "RUNNING")) { this.devIcon = "../../assets/image/running_car.png"; return this.devIcon; - }else if((!iconType)&&(devStatus[0] == "STOPPED")){ + } else if ((!iconType) && (devStatus[0] == "STOPPED")) { this.devIcon = "../../assets/image/stopped_car.png"; return this.devIcon; - }else if((!iconType)&&(devStatus[0] == "IDLING")){ + } else if ((!iconType) && (devStatus[0] == "IDLING")) { this.devIcon = "../../assets/image/idle_car.png"; return this.devIcon; - }else if ((!iconType) && (devStatus[0] == "NO")) { + } else if ((!iconType) && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; - }else if ((iconType == 'user') && (devStatus[0] == "OUT")) { + } else if ((iconType == 'user') && (devStatus[0] == "OUT")) { this.devIcon = "../../assets/image/user_b.png"; return this.devIcon; } else if ((iconType == 'user') && (devStatus[0] == "RUNNING")) { @@ -7610,8 +7645,8 @@ var seconds = num % 60; } else if ((iconType == 'user') && (devStatus[0] == "IDLING")) { this.devIcon = "../../assets/image/user_y.png"; return this.devIcon; - - }else if ((iconType == 'user') && (devStatus[0] == "NO")) { + + } else if ((iconType == 'user') && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; } @@ -7627,27 +7662,27 @@ var seconds = num % 60; } else if ((iconType == 'jcb') && (devStatus[0] == "IDLING")) { this.devIcon = "../../assets/image/jcb_yellow.png"; return this.devIcon; - + } else if ((iconType == 'jcb') && (devStatus[0] == "NO")) { this.devIcon = "../../assets/image/no_data.png"; return this.devIcon; - }else{ + } else { this.devIcon = "../../assets/image/noIcon.png"; return this.devIcon } } - locationShare(device){ + locationShare(device) { let dialogRef = this.dialog.open(ShareLocComponent, { - width:'500px', + width: '500px', data: { deviceObject: device } }); dialogRef.afterClosed().subscribe(result => { if (result == "succ") { - this.data_descip = "Location Shared" ; + this.data_descip = "Location Shared"; // this.immobilizeDevice(device, this.engineCutStatus); } function launch_toast() { @@ -7661,187 +7696,188 @@ var seconds = num % 60; } - getAddress(lat,lng){ - + getAddress(lat, lng) { + var latlng_1 = { "lat": lat, - "long": lng + "long": lng } - this.contactService.getAddressByApi(latlng_1).subscribe(res=>{ - if(res.address != undefined){ - this.historyAdress = res.address ; - } - }) + + this.contactService.getAddressByApi(latlng_1).subscribe(res => { + if (res.address != undefined) { + this.historyAdress = res.address; + } + }) } -getSystemLogs(imeiObj){ - var tDate = new Date(); - tDate.setSeconds(0); - tDate.setMilliseconds(0); - var fDate = new Date().setHours(0,0,0,0); - var payLoad = { - "draw": 5, - "columns": [ - { - "data": "_id" - }, - { - "data": "imei" - }, - { - "data": "date" - }, - { - "data": "latDecimal" - }, - { - "data": "longDecimal" - }, - { - "data": "insertionTime" - }, - { - "data": "syncedAt" - }, - { - "data": "integrationResponse" - }, - { - "data": "speed" - }, - { - "data": "ac" - }, - { - "data": "currentFuel" - }, - { - "data": "raw" - }, - { - "data": "ignition" - }, - { - "data": "power" - }, - { - "data": "fuelVoltage" - }, - { - "data": "rawio" - }, - { - "data": "external_Battery" - }, - { - "data": "powerCutAlarm" - }, - { - "data": "satellites" - } - ], - "order": [ - { - "column": 4, - "dir": "asc" - } - ], - "start": 0, - "length": 100, - "search": { - "value": "", - "regex": false - }, - "op": {}, - "select": [], - "find": { - "imei": imeiObj.Device_ID, - "insertionTime": { - "$gte": { - "_eval": "date", - "value": new Date(fDate).toISOString() + getSystemLogs(imeiObj) { + var tDate = new Date(); + tDate.setSeconds(0); + tDate.setMilliseconds(0); + var fDate = new Date().setHours(0, 0, 0, 0); + var payLoad = { + "draw": 5, + "columns": [ + { + "data": "_id" }, - "$lte": { - "_eval": "date", - "value": tDate.toISOString() + { + "data": "imei" + }, + { + "data": "date" + }, + { + "data": "latDecimal" + }, + { + "data": "longDecimal" + }, + { + "data": "insertionTime" + }, + { + "data": "syncedAt" + }, + { + "data": "integrationResponse" + }, + { + "data": "speed" + }, + { + "data": "ac" + }, + { + "data": "currentFuel" + }, + { + "data": "raw" + }, + { + "data": "ignition" + }, + { + "data": "power" + }, + { + "data": "fuelVoltage" + }, + { + "data": "rawio" + }, + { + "data": "external_Battery" + }, + { + "data": "powerCutAlarm" + }, + { + "data": "satellites" + } + ], + "order": [ + { + "column": 4, + "dir": "asc" + } + ], + "start": 0, + "length": 100, + "search": { + "value": "", + "regex": false + }, + "op": {}, + "select": [], + "find": { + "imei": imeiObj.Device_ID, + "insertionTime": { + "$gte": { + "_eval": "date", + "value": new Date(fDate).toISOString() + }, + "$lte": { + "_eval": "date", + "value": tDate.toISOString() + } } } } - } - var suburl = '/gps/datatable'; - - this.contactService.post(suburl, payLoad).subscribe(resp => { + var suburl = '/gps/datatable'; + + this.contactService.post(suburl, payLoad).subscribe(resp => { // console.log(resp); var tempLog = resp; - this.gpsDataArr=[]; + this.gpsDataArr = []; this.gpsDataArr = resp['data']; - for(var i=0;i { - - }); + }, err => { -} -dcqData= []; -deviceCQ(imeiObj){ - var imei = imeiObj.Device_ID?imeiObj.Device_ID:imeiObj ; - this.dcqData =[]; - this.contactService.deviceCmdQueue(imei).subscribe(resp => { - var tempLog = resp; - this.dcqData = resp; - }, err => { - this.dcqData =[]; - }); + }); -} - - -historySeekbaar(){ - -} - - public Selectedspeed = 1; -changeSpeed(t){ - // console.log(t); - this.speed = t * 100; - this.Selectedspeed = t; - -} - - -nearByValue:number= 1000 ; -changeRangeNearby(){ - var rangeVal1 = document.getElementById("nearbySlider"); - this.nearByValue = rangeVal1['value'] ; -} - - -getNearByVehicles(devData){ - // console.log(devData); - var payLoad = { - uid : this.useridd, - distance : this.nearByValue, - coord: {lat : devData.latDecimal,long:devData.longDecimal} } - this.contactService.getNearByVehicles(payLoad).subscribe(res=>{ - // console.log(res); - this.deviceList=[]; - this.deviceList = res; - if(this.deviceList.length != 0){ - if (this.deviceList.length === 0) { - this.lastcall = false; - this.firstcall = true - } - this.foods=[]; - for (var k = 0; k < this.deviceList.length; k++) { - this.deviceList[k]['playPause'] = true; - this.deviceList[k]['checked'] = true; + dcqData = []; + deviceCQ(imeiObj) { + var imei = imeiObj.Device_ID ? imeiObj.Device_ID : imeiObj; + this.dcqData = []; + this.contactService.deviceCmdQueue(imei).subscribe(resp => { + var tempLog = resp; + this.dcqData = resp; + }, err => { + this.dcqData = []; + }); + + } + + + historySeekbaar() { + + } + + public Selectedspeed = 1; + changeSpeed(t) { + // console.log(t); + this.speed = t * 100; + this.Selectedspeed = t; + + } + + + nearByValue: number = 1000; + changeRangeNearby() { + var rangeVal1 = document.getElementById("nearbySlider"); + this.nearByValue = rangeVal1['value']; + } + + + getNearByVehicles(devData) { + // console.log(devData); + var payLoad = { + uid: this.useridd, + distance: this.nearByValue, + coord: { lat: devData.latDecimal, long: devData.longDecimal } + } + this.contactService.getNearByVehicles(payLoad).subscribe(res => { + // console.log(res); + this.deviceList = []; + this.deviceList = res; + if (this.deviceList.length != 0) { + if (this.deviceList.length === 0) { + this.lastcall = false; + this.firstcall = true + } + this.foods = []; + for (var k = 0; k < this.deviceList.length; k++) { + this.deviceList[k]['playPause'] = true; + this.deviceList[k]['checked'] = true; if (this.deviceList[k].type_of_device == "Tracker") { let a = { value: this.deviceList[k].Device_Name, @@ -7852,224 +7888,224 @@ getNearByVehicles(devData){ email: this.deviceList[k].Email_ID, deviceType: this.deviceList[k].type_of_device, iconType: this.deviceList[k].iconType, - // checked:true + // checked:true } this.foods.push(a); - if(k === (this.deviceList.length -1)){ + if (k === (this.deviceList.length - 1)) { // console.log("1111111121212"); this.livetrack(null); } - - } + + } + } + this.masterFoods = JSON.parse(JSON.stringify(this.foods)); + this.sortFoodDataByKey(); + // console.log('this.deviceList',this.deviceList); + } else { + this.data_descip = "No Nearby Devices Found !!!"; + launch_toast(); + } - this.masterFoods = JSON.parse(JSON.stringify(this.foods)); - this.sortFoodDataByKey(); - // console.log('this.deviceList',this.deviceList); - }else{ - this.data_descip = "No Nearby Devices Found !!!"; - launch_toast(); - } + function launch_toast() { + // console.log(divid); + var x = document.getElementById("toast") + // console.log(x); + x.className = "show"; + setTimeout(function () { x.className = x.className.replace("show", ""); }, 1500); + } + }) + } - function launch_toast() { - // console.log(divid); - var x = document.getElementById("toast") - // console.log(x); - x.className = "show"; - setTimeout(function () { x.className = x.className.replace("show", ""); }, 1500); - } - }) -} + directionShow(deviceObj) { + var lat = deviceObj.last_location.lat; + var long = deviceObj.last_location.long; - directionShow(deviceObj) { - var lat = deviceObj.last_location.lat; - var long = deviceObj.last_location.long; - - var url ="https://www.google.com/maps/dir/?api=1&destination="+lat+","+long+"&travelmode=driving"; - window.open(url, '_blank'); - } + var url = "https://www.google.com/maps/dir/?api=1&destination=" + lat + "," + long + "&travelmode=driving"; + window.open(url, '_blank'); + } - getStringifyio(rawio){ - console.log('askdjsahdiasjdasdlkasdjasdlkadjajldadadaa',rawio); - return JSON.stringify(rawio); + getStringifyio(rawio) { + console.log('askdjsahdiasjdasdlkasdjasdlkadjajldadadaa', rawio); + return JSON.stringify(rawio); - } + } - viewStreet(){ - console.log("Street View"); + viewStreet() { + console.log("Street View"); - } + } - triggerDeviceCmd(dev){ - console.log('device Object',dev); + triggerDeviceCmd(dev) { + console.log('device Object', dev); // CmdUIComponent - let dialogRef = this.dialog.open(CommandWindowComponent, { - width:'500px', + let dialogRef = this.dialog.open(CommandWindowComponent, { + width: '500px', data: { deviceObject: dev } }); dialogRef.afterClosed().subscribe(result => { if (result == "succ") { - this.data_descip = "Command Successfully Triggered" ; - launch_toast() - + this.data_descip = "Command Successfully Triggered"; + launch_toast() + } - if(result == "openOther"){ + if (result == "openOther") { let dialogRef_1 = this.dialog.open(CmdUIComponent, { - width:'500px', + width: '500px', data: { deviceObject: dev } }); dialogRef_1.afterClosed().subscribe(result => { - if(result === 'cancel'){ + if (result === 'cancel') { // console.log('Working Fine'); } - if(result === 'succ'){ + if (result === 'succ') { this.data_descip = 'Command Triggered Successfully'; launch_toast(); - + } }) } - function launch_toast() { + function launch_toast() { var x = document.getElementById("toast"); x.className = "show"; setTimeout(function () { x.className = x.className.replace("show", ""); }, 1500); } }); - } - parkingArr = []; + } + parkingArr = []; + + parkingData(fTime, tTime, uid, dev) { - parkingData(fTime, tTime,uid,dev){ - // console.log('fTime, tTime,uid,dev',fTime, tTime,uid,dev); var fd = new Date(fTime); - var td= new Date(tTime); - var userid=(dev.user._id != undefined)?dev.user._id:dev.user; - var device_imei=dev._id; - - this.contactService.stoppage_report(fd.toISOString(),td.toISOString(),userid,device_imei).subscribe(res=>{ - this.parkingArr =[] ; - this.parkingArr =res ; - + var td = new Date(tTime); + var userid = (dev.user._id != undefined) ? dev.user._id : dev.user; + var device_imei = dev._id; + + this.contactService.stoppage_report(fd.toISOString(), td.toISOString(), userid, device_imei).subscribe(res => { + this.parkingArr = []; + this.parkingArr = res; + // console.log('response=>',res); - },err=>{ - this.parkingArr =[] ; + }, err => { + this.parkingArr = []; }) } - notifArray=[]; - bulkVar:any; - notificationData(fTime, tTime,uid,dev){ + notifArray = []; + bulkVar: any; + notificationData(fTime, tTime, uid, dev) { // console.log('fTime, tTime,uid,dev',fTime, tTime,uid,dev); // console.log('Inside notification'); var fd = new Date(fTime); - var td= new Date(tTime); - var userid=(dev.user._id != undefined)?dev.user._id:dev.user; + var td = new Date(tTime); + var userid = (dev.user._id != undefined) ? dev.user._id : dev.user; // var userid:any; // console.log(dev); - var device_imei= dev.Device_ID; - - var skip = 1; - var limit = 200; - // console.log('what is skip here',skip); - - this.contactService.filteredNotifications(fd,td,this.bulkVar,device_imei,userid,skip,limit) - .subscribe(res=>{ - // console.log('res=>',res); - this.notifArray = []; - this.notifArray = res; - // console.log('this.notifArray',this.notifArray); + var device_imei = dev.Device_ID; - },err=>{ - this.notifArray = []; - }) + var skip = 1; + var limit = 200; + // console.log('what is skip here',skip); + + this.contactService.filteredNotifications(fd, td, this.bulkVar, device_imei, userid, skip, limit) + .subscribe(res => { + // console.log('res=>',res); + this.notifArray = []; + this.notifArray = res; + // console.log('this.notifArray',this.notifArray); + + }, err => { + this.notifArray = []; + }) } - getDuration(atime,dtime){ - let arrival_time = new Date(atime).toLocaleString(); + getDuration(atime, dtime) { + let arrival_time = new Date(atime).toLocaleString(); let departure_time = new Date(dtime).toLocaleString(); - var fd = new Date(arrival_time ).getTime(); + var fd = new Date(arrival_time).getTime(); var td = new Date(departure_time).getTime(); - var time_difference = td-fd; - var total_min = time_difference/60000; - var hours = total_min/60 + var time_difference = td - fd; + var total_min = time_difference / 60000; + var hours = total_min / 60 var rhours = Math.floor(hours); var minutes = (hours - rhours) * 60; - var rminutes = Math.round(minutes); - let Durations = rhours +" "+'hrs'+ " "+ rminutes + 'min'; + var rminutes = Math.round(minutes); + let Durations = rhours + " " + 'hrs' + " " + rminutes + 'min'; return Durations; } - getAlink(lat,lng){ + getAlink(lat, lng) { // lat +","+lng + // https://maps.google.com/?q= - var addressLink = "https://maps.google.com/?q=" +lat +',' +lng; - return addressLink; + var addressLink = "https://maps.google.com/?q=" + lat + ',' + lng; + return addressLink; } - liveEventsData:any=[]; - nType:any; - getRecentNotification(colObj){ - var fd= new Date(); - fd.setHours(0,0,0,0); - var fromD = new Date(fd); - var td = new Date(); - // var user = colObj.user; - var user=(colObj.user._id != undefined)?colObj.user._id:colObj.user; - var did= colObj.Device_ID + liveEventsData: any = []; + nType: any; + getRecentNotification(colObj) { + var fd = new Date(); + fd.setHours(0, 0, 0, 0); + var fromD = new Date(fd); + var td = new Date(); + // var user = colObj.user; + var user = (colObj.user._id != undefined) ? colObj.user._id : colObj.user; + var did = colObj.Device_ID // console.log('Inside get Notification Function',this.deviceSelect); - var skip=1; + var skip = 1; var limit = 200; // console.log('what is skip here',skip); - this.contactService.filteredNotifications(fromD,td,this.nType,did,user,skip,limit).subscribe(res=>{ + this.contactService.filteredNotifications(fromD, td, this.nType, did, user, skip, limit).subscribe(res => { // console.log('Inside get Notification Function',did); - this.liveEventsData=[]; - this.liveEventsData = res; - this.socket_Notify.on(this.useridd, this.accListener()); - },err=>{ - this.liveEventsData =[]; + this.liveEventsData = []; + this.liveEventsData = res; + this.socket_Notify.on(this.useridd, this.accListener()); + }, err => { + this.liveEventsData = []; }) } - accListener(){ + accListener() { // console.log('this is accListner'); var outerThis = this; - return function(msg){ - // console.log('message=>',msg); - // console.log('message=>',msg.device , this.deviceSelect); - if (this.deviceSelect){ + return function (msg) { + // console.log('message=>',msg); + // console.log('message=>',msg.device , this.deviceSelect); + if (this.deviceSelect) { - if(msg.device == this.deviceSelect[0].Device_ID){ + if (msg.device == this.deviceSelect[0].Device_ID) { // this.liveEventsData.push(msg); this.liveEventsData.splice(0, 0, msg); } } - // console.log('accListner=>',this.liveEventsData) - + // console.log('accListner=>',this.liveEventsData) + } } - addVehicle(){ - var that= this; + addVehicle() { + var that = this; let dialogRef = this.dialog.open(AddDeviceComponent, { width: '800px', }); @@ -8081,53 +8117,53 @@ getNearByVehicles(devData){ } }); } - checkBoxValue1(event){ + checkBoxValue1(event) { // console.log(event); - this.satelliteDisabled=event.checked + this.satelliteDisabled = event.checked } - checkBoxValue(ev,i){ + checkBoxValue(ev, i) { // console.log('event=>',ev); // console.log('index=>',i); // console.log('this.markerArray[i]',this.markerArray[i]); - var indexSwitch = (this.markerArray[i]===undefined)?0:i; + var indexSwitch = (this.markerArray[i] === undefined) ? 0 : i; // console.log(indexSwitch); // console.log(this.markerArray[indexSwitch].lat, this.markerArray[indexSwitch].lng); // console.log('this.markerArray',this.markerArray); - if(ev.checked === false){ + if (ev.checked === false) { this.markerArray[indexSwitch].marker.setMap(null); // this.markerArray[i] ={}; } - if(ev.checked === true){ + if (ev.checked === true) { this.markerArray[indexSwitch].marker.setMap(null); var m = new google.maps.Marker({ position: new google.maps.LatLng(this.markerArray[indexSwitch].lat, this.markerArray[indexSwitch].lng), map: this.mapNew, - icon: this.markerArray[indexSwitch].icon, + icon: this.markerArray[indexSwitch].icon, }); this.markerArray[indexSwitch].marker = m; this.mapNew.setCenter({ lat: this.markerArray[indexSwitch].lat, lng: this.markerArray[indexSwitch].lng }); - if(this.markerArray[indexSwitch].number_plate) - this.markerArray[indexSwitch].number_plate.open(this.mapNew, this.markerArray[indexSwitch].marker); + if (this.markerArray[indexSwitch].number_plate) + this.markerArray[indexSwitch].number_plate.open(this.mapNew, this.markerArray[indexSwitch].marker); var that = this; - this.markerArray[indexSwitch].marker.addListener('click',function(){ + this.markerArray[indexSwitch].marker.addListener('click', function () { // console.log('inside test function'); - + that.markerArray[i].infowindow.open(that.mapNew, that.markerArray[i].marker); - + }); // this.markerArray[indexSwitch].marker.addListener(this.markerArray[i].infowindow, 'click', function () { - // console.log('inside info click'); + // console.log('inside info click'); // that.markerArray[i].infowindow.open(that.mapNew, that.markerArray[i].marker); // }); } - - var that= this; - this.deviceList.filter((dl,index)=>{ + + var that = this; + this.deviceList.filter((dl, index) => { // console.log(dl,index); - if(dl.Device_ID == this.markerArray[indexSwitch].imei){ + if (dl.Device_ID == this.markerArray[indexSwitch].imei) { that.deviceList[index].checked = ev.checked } @@ -8136,106 +8172,106 @@ getNearByVehicles(devData){ } - selectGroup(event,item){ - var index=[] + selectGroup(event, item) { + var index = [] // console.log(item); - if(event.checked){ - this.deviceList.filter(x => x.vehicleGroup==undefined || x.vehicleGroup.name !== item.name).forEach(x => this.deviceList[this.deviceList.indexOf(x)].checked=false); - this.deviceList.filter(x =>{ - if(x.vehicleGroup){ - if(x.vehicleGroup.name === item.name){ - // console.log(x) - var ev={checked:true} - this.checkBoxValue(ev,this.deviceList.indexOf(x)); + if (event.checked) { + this.deviceList.filter(x => x.vehicleGroup == undefined || x.vehicleGroup.name !== item.name).forEach(x => this.deviceList[this.deviceList.indexOf(x)].checked = false); + this.deviceList.filter(x => { + if (x.vehicleGroup) { + if (x.vehicleGroup.name === item.name) { + // console.log(x) + var ev = { checked: true } + this.checkBoxValue(ev, this.deviceList.indexOf(x)); + } + } else { + var ev = { checked: false } + this.checkBoxValue(ev, this.deviceList.indexOf(x)); } - }else{ - var ev={checked:false} - this.checkBoxValue(ev,this.deviceList.indexOf(x)); - } - }) - }else{ - this.deviceList.forEach(x => { - x.checked=true; - var ev={checked:true} - this.checkBoxValue(ev,this.deviceList.indexOf(x)); - - }); - } - + }) + } else { + this.deviceList.forEach(x => { + x.checked = true; + var ev = { checked: true } + this.checkBoxValue(ev, this.deviceList.indexOf(x)); + + }); + } + // for(var i=0;i - // console.log(x) - // ); + + // }).forEach(x => + // console.log(x) + // ); } - getUserDetails(){ + getUserDetails() { // console.log("USERID--",this.useridd); - - this.contactService.getUserObj(this.useridd).subscribe((res:any)=>{ + + this.contactService.getUserObj(this.useridd).subscribe((res: any) => { // console.log("RESPONSE",res); - if(res.label_setting!==undefined){ - this.showLabels=res.label_setting - this.digitalInput=res.digital_input + if (res.label_setting !== undefined) { + this.showLabels = res.label_setting + this.digitalInput = res.digital_input } - if(res.user_settings){ - if(res.user_settings.sateliteValue) - this.satelite=res.user_settings.sateliteValue + if (res.user_settings) { + if (res.user_settings.sateliteValue) + this.satelite = res.user_settings.sateliteValue } - - + + }) } - + // @HostListener('click', ['$event']) // onClick(event) { // if (event.target.id === 'deletePoint'){ - // console.log(event.target.value); + // console.log(event.target.value); // this.latlongObjArr.splice(event.target.value,1); // this.maphistory(1) // } - + // } // CLICK(data){ - // console.log(data); - + // console.log(data); + // } // ------------new Method for calculate area------------------ - cordinates=[]; - showArea(){ + cordinates = []; + showArea() { // console.log(this.datefrom,this.date2,this.foods); - var imei=JSON.parse(localStorage.getItem('devDetail'))?JSON.parse(localStorage.getItem('devDetail')):this.temptrackingDev + var imei = JSON.parse(localStorage.getItem('devDetail')) ? JSON.parse(localStorage.getItem('devDetail')) : this.temptrackingDev // console.log(imei,"====>",imei,this.temptrackingDev); - if(!imei){ - imei=this.deviceSelect[0].did - }else{ - if(imei.vehicleId){ - imei=imei.vehicleId - }else{ - imei=imei + if (!imei) { + imei = this.deviceSelect[0].did + } else { + if (imei.vehicleId) { + imei = imei.vehicleId + } else { + imei = imei } } - - var data={ - f:new Date(this.datefrom).toISOString(), - t:new Date(this.date2).toISOString(), - imei:imei + + var data = { + f: new Date(this.datefrom).toISOString(), + t: new Date(this.date2).toISOString(), + imei: imei } // console.log( // data // ); - - this.contactService.calculateArea(data).subscribe((res:any)=>{ + + this.contactService.calculateArea(data).subscribe((res: any) => { // console.log("AREA RESPONSE",res); - if(res.area) - this.area=(res.area/1000000)*247; + if (res.area) + this.area = (res.area / 1000000) * 247; // let a = res.pts; @@ -8247,337 +8283,337 @@ getNearByVehicles(devData){ // this.cordinates.push(b); // } - // console.log(this.cordinates); + // console.log(this.cordinates); // // this.draw1(this.cordinates,'') - - + + }) } - -// draw1(zzz,yyy){ -// var map; -// var infoWindow; - // console.log(typeof zzz) -// var GeoFencCoords = zzz -// var GeoName = yyy - // console.log(zzz[0].lat) -// initMap(GeoFencCoords); -// function initMap(GeoFencCoords) { -// map = new google.maps.Map(document.getElementById('map2'), { -// zoom: 17, -// center: {lat: GeoFencCoords[0].lat, lng: GeoFencCoords[0].lng}, -// mapTypeId: 'terrain' -// }); - -// var bermudaTriangle = new google.maps.Polygon({ -// paths: GeoFencCoords, -// strokeColor: '#FF0000', -// strokeOpacity: 0.8, -// strokeWeight: 3, -// fillColor: '#FF0000', -// fillOpacity: 0.35 -// }); -// bermudaTriangle.setMap(map); + // draw1(zzz,yyy){ + // var map; + // var infoWindow; + // console.log(typeof zzz) + // var GeoFencCoords = zzz + // var GeoName = yyy + // console.log(zzz[0].lat) + // initMap(GeoFencCoords); + // function initMap(GeoFencCoords) { + // map = new google.maps.Map(document.getElementById('map2'), { + // zoom: 17, + // center: {lat: GeoFencCoords[0].lat, lng: GeoFencCoords[0].lng}, + // mapTypeId: 'terrain' + // }); -// // Add a listener for the click event. -// bermudaTriangle.addListener('click', showArrays); -// infoWindow = new google.maps.InfoWindow; -// } + // var bermudaTriangle = new google.maps.Polygon({ + // paths: GeoFencCoords, + // strokeColor: '#FF0000', + // strokeOpacity: 0.8, + // strokeWeight: 3, + // fillColor: '#FF0000', + // fillOpacity: 0.35 + // }); + // bermudaTriangle.setMap(map); -// /** @this {google.maps.Polygon} */ -// function showArrays(event) { -// // Since this polygon has only one path, we can call getPath() to return the -// // MVCArray of LatLngs. -// var vertices = this.getPath(); + // // Add a listener for the click event. + // bermudaTriangle.addListener('click', showArrays); -// var contentString = 'Geo Fence
' + -// 'Name: ' + GeoName; + // infoWindow = new google.maps.InfoWindow; + // } -// // Iterate over the vertices. -// /* for (var i =0; i < vertices.getLength(); i++) { -// var xy = vertices.getAt(i); -// contentString += '
' + 'Coordinate ' + i + ':
' + xy.lat() + ',' + -// xy.lng(); -// } -// */ -// // Replace the info window's content and position. -// infoWindow.setContent(contentString); -// infoWindow.setPosition(event.latLng); + // /** @this {google.maps.Polygon} */ + // function showArrays(event) { + // // Since this polygon has only one path, we can call getPath() to return the + // // MVCArray of LatLngs. + // var vertices = this.getPath(); -// infoWindow.open(map); -// } -// } + // var contentString = 'Geo Fence
' + + // 'Name: ' + GeoName; -change(device){ - // console.log(device); - this.deviceSelect[0]=device; - // console.log(this.deviceSelect); - -} -startAddress:any; -deviceNameForPDF -startTime -endTime -endAddress:any -pdfFunction(data){ - // console.log("IN PDF FUNCTION",data) - // this.startAddress=this.getAddressForPDF(data.today_start_location?data.today_start_location.lat:0,data.today_start_location?data.today_start_location.long:0,'start'); - // this.endAddress=this.getAddressForPDF(data.last_location?data.last_location.lat:0,data.last_location?data.last_location.long:0,'end') -} -getAddressForPDF(lat,lng,type){ - - var outerThis=this - - let geocoder = new google.maps.Geocoder(); - - let request = { - latLng: new google.maps.LatLng(lat,lng) - }; - geocoder.geocode(request, function (data, status) { - if (status == google.maps.GeocoderStatus.OK) { - if (data[0] != null) { - // var liveAdd = ; - // console.log(data[0].formatted_address); - if(type=="start"){ - outerThis.startAddress=data[0].formatted_address - }else{ - outerThis.endAddress=data[0].formatted_address - } - return data[0].formatted_address; - } - } - else { - // console.log(liveAdd); - return 'N/A'; - - - } - - }) -} + // // Iterate over the vertices. + // /* for (var i =0; i < vertices.getLength(); i++) { + // var xy = vertices.getAt(i); + // contentString += '
' + 'Coordinate ' + i + ':
' + xy.lat() + ',' + + // xy.lng(); + // } + // */ + // // Replace the info window's content and position. + // infoWindow.setContent(contentString); + // infoWindow.setPosition(event.latLng); + + // infoWindow.open(map); + // } + // } + + change(device) { + // console.log(device); + this.deviceSelect[0] = device; + // console.log(this.deviceSelect); + + } + startAddress: any; + deviceNameForPDF + startTime + endTime + endAddress: any + pdfFunction(data) { + // console.log("IN PDF FUNCTION",data) + // this.startAddress=this.getAddressForPDF(data.today_start_location?data.today_start_location.lat:0,data.today_start_location?data.today_start_location.long:0,'start'); + // this.endAddress=this.getAddressForPDF(data.last_location?data.last_location.lat:0,data.last_location?data.last_location.long:0,'end') + } + getAddressForPDF(lat, lng, type) { + + var outerThis = this + + let geocoder = new google.maps.Geocoder(); + + let request = { + latLng: new google.maps.LatLng(lat, lng) + }; + geocoder.geocode(request, function (data, status) { + if (status == google.maps.GeocoderStatus.OK) { + if (data[0] != null) { + // var liveAdd = ; + // console.log(data[0].formatted_address); + if (type == "start") { + outerThis.startAddress = data[0].formatted_address + } else { + outerThis.endAddress = data[0].formatted_address + } + return data[0].formatted_address; + } + } + else { + // console.log(liveAdd); + return 'N/A'; + + + } + + }) + } -image - pdf() { - var image="" - if(this.deviceList[0].supAdmin.imageDoc.length != 0){ - var str = this.deviceList[0].supAdmin.imageDoc[0] - var splitStr = str.split('/'); - var concatStr =''; - for(var i=1 ; i< splitStr.length ; i++){ - if(i > 0){ - var tt = splitStr[i]; - concatStr += '/'+tt ; - } - } - image='https://www.oneqlik.in' + concatStr + image + pdf() { + var image = "" + if (this.deviceList[0].supAdmin.imageDoc.length != 0) { + var str = this.deviceList[0].supAdmin.imageDoc[0] + var splitStr = str.split('/'); + var concatStr = ''; + for (var i = 1; i < splitStr.length; i++) { + if (i > 0) { + var tt = splitStr[i]; + concatStr += '/' + tt; + } + } + image = 'https://www.oneqlik.in' + concatStr // console.log("IMAGE==>",image); - + // this.contactService.imageUrlToBase64('https://www.oneqlik.in' + concatStr).subscribe(res=>{ - // console.log("Image=>",(res).toString()); + // console.log("Image=>",(res).toString()); // // this.image=res // }) - // this.getBase64ImageFromUrl('https://www.oneqlik.in' + concatStr).then(result => this.image= result) - } - this.deviceNameForPDF=this.tempMapHistory[0].device_name - this.startTime=this.tempMapHistory[0].fromTime - this.endTime=this.tempMapHistory[0].toTime; - var name=this.deviceNameForPDF+" track from "+this.startTime+" to "+this.endTime+'.pdf' - var outerThis=this; - this.startAddress = this.finalArr[0] ?this.finalArr[0].address : ''; - this.endAddress = this.finalArr[0] ?this.finalArr[this.finalArr.length-1].address :'' + // this.getBase64ImageFromUrl('https://www.oneqlik.in' + concatStr).then(result => this.image= result) + } + this.deviceNameForPDF = this.tempMapHistory[0].device_name + this.startTime = this.tempMapHistory[0].fromTime + this.endTime = this.tempMapHistory[0].toTime; + var name = this.deviceNameForPDF + " track from " + this.startTime + " to " + this.endTime + '.pdf' + var outerThis = this; + this.startAddress = this.finalArr[0] ? this.finalArr[0].address : ''; + this.endAddress = this.finalArr[0] ? this.finalArr[this.finalArr.length - 1].address : '' // console.log(this.startAddress,this.endAddress); - -// console.log(this.tempMapHistory,this.startAddress,this.endAddress, this.image); + + // console.log(this.tempMapHistory,this.startAddress,this.endAddress, this.image); - var element = $('#map2'); - var pdfOptions = { - orientation: "landscape", // One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") - unit: "mm", //Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" - format: "legal" //One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' - }; + var element = $('#map2'); + var pdfOptions = { + orientation: "landscape", // One of "portrait" or "landscape" (or shortcuts "p" (Default), "l") + unit: "mm", //Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in" + format: "legal" //One of 'a3', 'a4' (Default),'a5' ,'letter' ,'legal' + }; - var doc = new jsPDF(pdfOptions); - this.contactService.setFontInPdf(doc); - var pageWidth = doc.internal.pageSize.width-20; - var width = pageWidth; + var doc = new jsPDF(pdfOptions); + this.contactService.setFontInPdf(doc); + var pageWidth = doc.internal.pageSize.width - 20; + var width = pageWidth; - html2canvas(element, { - useCORS: true, // MUST - onrendered: function(canvas) { - var imgWidth = element.width(); - var imgHeight = element.height(); + html2canvas(element, { + useCORS: true, // MUST + onrendered: function (canvas) { + var imgWidth = element.width(); + var imgHeight = element.height(); - var height = (pageWidth * imgHeight)/ imgWidth - var imgData = canvas.toDataURL('image/png'); - doc.addImage(imgData, 'PNG', 5, 30 , width, height); - outerThis.toDataURL(image, function (dataUrl) { - if(image) - doc.addImage(dataUrl, 'JPEG', 2, 2, 27, 27); - let finalY = doc.previousAutoTable.finalY; - var header = function(data) { - doc.setFontSize(15); - doc.setTextColor(40); - doc.setFontStyle('normal'); - // console.log(dataUrl); - - // doc.addImage(dataUrl, 'JPEG', data.settings.margin.left, 20, 30, 30); - // doc.text("Testing Report", data.settings.margin.left, 50); - }; - doc.autoTable({html:"#headerTable",margin:{bottom:140,left:30,right:8,top:2},theme:'plain'}); - - // var options = { - // beforePageContent: header, - // // margin: { - // // top: 300 - // // }, - // // // startY:doc.lastAutoTable+ 300 - // // startY: 300 - // // startY: doc.autoTableEndPosY() + 300 - // }; - doc.autoTable({ - head: outerThis.headRows(), - // margin: { top: 80 }, - startY: doc.autoTable.previous.finalY + 200, - body: outerThis.bodyRows(outerThis.finalArr.length, outerThis.finalArr), - // beforePageContent: header, - }); - doc.save(name); - // // doc.addImage(dataUrl, 'JPG', 330, 4, 20, 20); - // // doc.addImage({ - // // imageData : dataUrl, - // // angle : 20, - // // x : 330, - // // y : 1, - // // w : 20, - // // h : 20 - // // }) - // console.log("URLLLL",dataUrl); - // // this.image=dataUrl - // }) - }); - - } + var height = (pageWidth * imgHeight) / imgWidth + var imgData = canvas.toDataURL('image/png'); + doc.addImage(imgData, 'PNG', 5, 30, width, height); + outerThis.toDataURL(image, function (dataUrl) { + if (image) + doc.addImage(dataUrl, 'JPEG', 2, 2, 27, 27); + let finalY = doc.previousAutoTable.finalY; + var header = function (data) { + doc.setFontSize(15); + doc.setTextColor(40); + doc.setFontStyle('normal'); + // console.log(dataUrl); + + // doc.addImage(dataUrl, 'JPEG', data.settings.margin.left, 20, 30, 30); + // doc.text("Testing Report", data.settings.margin.left, 50); + }; + doc.autoTable({ html: "#headerTable", margin: { bottom: 140, left: 30, right: 8, top: 2 }, theme: 'plain' }); + + // var options = { + // beforePageContent: header, + // // margin: { + // // top: 300 + // // }, + // // // startY:doc.lastAutoTable+ 300 + // // startY: 300 + // // startY: doc.autoTableEndPosY() + 300 + // }; + doc.autoTable({ + head: outerThis.headRows(), + // margin: { top: 80 }, + startY: doc.autoTable.previous.finalY + 200, + body: outerThis.bodyRows(outerThis.finalArr.length, outerThis.finalArr), + // beforePageContent: header, + }); + doc.save(name); + // // doc.addImage(dataUrl, 'JPG', 330, 4, 20, 20); + // // doc.addImage({ + // // imageData : dataUrl, + // // angle : 20, + // // x : 330, + // // y : 1, + // // w : 20, + // // h : 20 + // // }) + // console.log("URLLLL",dataUrl); + // // this.image=dataUrl + // }) }); + } + }); - } - toDataURL(url, callback) { - // console.log(url); - - var xhr = new XMLHttpRequest(); - xhr.onload = function () { - var reader = new FileReader(); - reader.onloadend = function () { - callback(reader.result); - } - reader.readAsDataURL(xhr.response); - }; - xhr.open('GET', url); - xhr.responseType = 'blob'; - xhr.send(); - } - - selectedGroup(event){ - // console.log(event,this.toppings); - this.getDeviceBYfilter('','') } - getGrp(){ - this.contactService.getGroup(this.useridd).subscribe( - res => { - // console.log(res); - this.groups = res["group_details"]; - // console.log(this.grpName); - }) -} + toDataURL(url, callback) { + // console.log(url); -selectAllVehicles(ev){ + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + var reader = new FileReader(); + reader.onloadend = function () { + callback(reader.result); + } + reader.readAsDataURL(xhr.response); + }; + xhr.open('GET', url); + xhr.responseType = 'blob'; + xhr.send(); + } + + selectedGroup(event) { + // console.log(event,this.toppings); + this.getDeviceBYfilter('', '') + } + + getGrp() { + this.contactService.getGroup(this.useridd).subscribe( + res => { + // console.log(res); + this.groups = res["group_details"]; + // console.log(this.grpName); + }) + } + + selectAllVehicles(ev) { // console.log(ev); - if(ev.checked){ - this.deviceObj = []; - var Alldevices = { - id: "all", - viewValue: "ALL Devices", - iconType: "", - deviceId: "" - } - if(this.deviceList.length==1){ - this.selectedDevice=this.deviceList[0]._id - this.parkingButtonShow=this.deviceList[0].theftAlert==null?'grey':this.deviceList[0].theftAlert==undefined?'grey':this.deviceList[0].theftAlert==true?'green':'red' - this.DriverName=this.deviceList[0].driver_name; - // console.log("DRIVER NAME",this.DriverName,this.deviceList[0].ac); - this.ac=this.deviceList[0].ac?this.deviceList[0].ac:'NA' - this.DriverNumber=this.deviceList[0].contact_number - } - // console.log("device obj =>",this.deviceList); - this.deviceObj.push(Alldevices); - for (var i = 0; i < this.deviceList.length; i++) { - Alldevices = { - id: this.deviceList[i]._id, - viewValue: this.deviceList[i].Device_Name ? this.deviceList[i].Device_Name : "", - iconType: this.deviceList[i].iconType, - deviceId: this.deviceList[i].Device_ID - } - this.deviceObj.push(Alldevices) - } - - this.final = this.deviceList; - this.foods = []; - this.masterFoods = []; - for (let i = 0; i < this.final.length; i++) { - this.final[i]['checked'] = true; - // this.deviceList = this.final; - - if (this.final[i].type_of_device == "Tracker") { - let a = { - value: this.final[i].Device_Name, - viewValue: this.final[i].Device_Name, - did: this.final[i].Device_ID, - id: this.final[i]._id, - user: this.final[i].user, - email: this.final[i].Email_ID, - deviceType: this.final[i].type_of_device, - iconType: this.final[i].iconType - - } - - this.foods.push(a); - - } - - } - - let that= this; - if((this.navId === undefined)||(this.navId != 'locationHistory')){ - this.livetrack(this.fin); - } - - for (let y = 0; y < this.foods.length; y++) { - if (this.foods[y].did == this.fin) { - this.new = this.foods[y]; - } + if (ev.checked) { + this.deviceObj = []; + var Alldevices = { + id: "all", + viewValue: "ALL Devices", + iconType: "", + deviceId: "" + } + if (this.deviceList.length == 1) { + this.selectedDevice = this.deviceList[0]._id + this.parkingButtonShow = this.deviceList[0].theftAlert == null ? 'grey' : this.deviceList[0].theftAlert == undefined ? 'grey' : this.deviceList[0].theftAlert == true ? 'green' : 'red' + this.DriverName = this.deviceList[0].driver_name; + // console.log("DRIVER NAME",this.DriverName,this.deviceList[0].ac); + this.ac = this.deviceList[0].ac ? this.deviceList[0].ac : 'NA' + this.DriverNumber = this.deviceList[0].contact_number + } + // console.log("device obj =>",this.deviceList); + this.deviceObj.push(Alldevices); + for (var i = 0; i < this.deviceList.length; i++) { + Alldevices = { + id: this.deviceList[i]._id, + viewValue: this.deviceList[i].Device_Name ? this.deviceList[i].Device_Name : "", + iconType: this.deviceList[i].iconType, + deviceId: this.deviceList[i].Device_ID + } + this.deviceObj.push(Alldevices) + } + + this.final = this.deviceList; + this.foods = []; + this.masterFoods = []; + for (let i = 0; i < this.final.length; i++) { + this.final[i]['checked'] = true; + // this.deviceList = this.final; + + if (this.final[i].type_of_device == "Tracker") { + let a = { + value: this.final[i].Device_Name, + viewValue: this.final[i].Device_Name, + did: this.final[i].Device_ID, + id: this.final[i]._id, + user: this.final[i].user, + email: this.final[i].Email_ID, + deviceType: this.final[i].type_of_device, + iconType: this.final[i].iconType + } + + this.foods.push(a); + + } + + } + + let that = this; + if ((this.navId === undefined) || (this.navId != 'locationHistory')) { + this.livetrack(this.fin); + } + + for (let y = 0; y < this.foods.length; y++) { + if (this.foods[y].did == this.fin) { + this.new = this.foods[y]; + } + } this.masterFoods = JSON.parse(JSON.stringify(this.foods)); this.sortFoodDataByKey(); - }else{ + } else { + - this.deviceList.forEach(element => { - element.checked=false; + element.checked = false; }); const myOptions = { - zoom:2, + zoom: 2, center: new google.maps.LatLng(18.602941, 73.777147), mapTypeId: google.maps.MapTypeId.ROADMAP }; - + var map = new google.maps.Map(document.getElementById('map'), myOptions); // console.log('mapmapmapmapmapmapmapmapmapmapmapmapmapmap',map); var trafficLayer = new google.maps.TrafficLayer(); @@ -8591,9 +8627,9 @@ selectAllVehicles(ev){ zoomBar = document.getElementById('myRange'); map.setZoom(map.getZoom()); - + zoomBar.value = map.getZoom(); - + zoomBar.oninput = function () { // console.log('zoomValue',map.getZoom()); map.setZoom(parseInt(this.value)); @@ -8604,114 +8640,133 @@ selectAllVehicles(ev){ if (zoomBar.value) zoomBar.value = map.getZoom(); }); - + } - -} -reportArr -finalArr=[] -reportArr1 -pathReport=[] -getTravelPathReport(device){ - var payload ={ - "to":new Date(this.date2).toISOString(), - "from" : new Date(this.datefrom).toISOString(), - "device": device.Device_ID ? device.Device_ID : device.did, - "interval" :10 + + } + reportArr + finalArr = [] + reportArr1 + pathReport = [] + getTravelPathReport(device) { + var payload = { + "to": new Date(this.date2).toISOString(), + "from": new Date(this.datefrom).toISOString(), + "device": device.Device_ID ? device.Device_ID : device.did, + "interval": 10 + } + + this.contactService.getTravel_path_report(payload).subscribe((resp: any) => { + + + this.reportArr = []; + if (resp && resp.length) { + this.reportArr = resp.filter(function (el) { + return el != null; + }); + } + + + let last = { speed: '' }; + let result = []; + + for (let i = 0; i < this.reportArr.length; i++) { + var cum_distance = parseFloat(this.reportArr[i].odo) - parseFloat(this.reportArr[0].odo); + this.reportArr[i].cum_distance = Math.abs(parseFloat(cum_distance.toFixed(2))) + + // let char = this.reportArr[i]; + // if(char.speed !== last.speed){ + // result.push(char); + // last = char; + // } + } + // console.log("RESSSS==>",this.reportArr); + this.reportArr1 = this.reportArr + let latLongArray :any[] = []; + this.reportArr1.forEach((deData)=>{ + latLongArray.push({ + "long":deData.longDecimal ? deData.longDecimal : 0, + "lat":deData.latDecimal ? deData.latDecimal : 0 + }) + + }) + + this.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + this.reportArr1.forEach((deData,index)=>{ + let latLng = { + lat: deData.latDecimal ? deData.latDecimal : 0, + long: deData.longDecimal ? deData.longDecimal : 0 } + this.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[index]; + }) - this.contactService.getTravel_path_report(payload).subscribe((resp:any)=>{ - - - this.reportArr = []; - if (resp && resp.length) { - this.reportArr= resp.filter(function (el) { - return el != null; + + + if (this.reportArr1.length != 0) { + var j = 0; + // console.log(this.reportArr1); + for (let i = 0; i < resp.length; i++) { + if (resp[i] != null) { + resp[i].Device_name = device.Device_Name; + this.pathReport.push(resp[i]); + } else { + } + } + + this.finalArr = []; + var that = this + // console.log(this.finalArr); + for (var i = 0; i < this.reportArr1.length; i++) { + this.clocation_1(this.reportArr1[i], function (err, succ) { + if (err) { + // console.log(err); + j++; + } else { + // console.log(succ); + succ['index'] = j + that.finalArr.push(succ); + // if(j==0){ + // that.startAddress=succ.address + // } + // console.log(that.finalArr,j); + j++; + if (j === that.reportArr1.length) { + // that.endAddress=succ.address + that.Load = false; + that.finalArr.sort(function (a: any, b: any) { + + return new Date(a.date).valueOf() - new Date(b.date).valueOf(); }); + // callback({ data: this.finalArr }); + } } - - - let last = {speed:''}; -let result = []; + }) -for(let i = 0; i < this.reportArr.length; i++){ - var cum_distance = parseFloat(this.reportArr[i].odo)-parseFloat(this.reportArr[0].odo); - this.reportArr[i].cum_distance=Math.abs(parseFloat(cum_distance.toFixed(2))) - // let char = this.reportArr[i]; - // if(char.speed !== last.speed){ - // result.push(char); - // last = char; - // } -} -// console.log("RESSSS==>",this.reportArr); -this.reportArr1=this.reportArr - - - if (this.reportArr1.length != 0) { - var j = 0; - // console.log(this.reportArr1); - for(let i = 0; i 0) ? false : true; - this.finalArr = []; - var that=this - // console.log(this.finalArr); - for (var i = 0; i < this.reportArr1.length; i++) { - this.clocation_1(this.reportArr1[i], function (err, succ) { - if (err) { - // console.log(err); - j++; - } else { - // console.log(succ); - succ['index']=j - that.finalArr.push(succ); - // if(j==0){ - // that.startAddress=succ.address - // } - // console.log(that.finalArr,j); - j++; - if (j === that.reportArr1.length) { - // that.endAddress=succ.address - that.Load = false; - that.finalArr.sort(function(a:any,b:any){ - - return new Date(a.date).valueOf() - new Date(b.date).valueOf(); - }); - // callback({ data: this.finalArr }); - } - } - }) - - - } - if(this.pathReport.length==0){ - this.Load = false; - } - } else { - this.Load = false; - this.firstcall=true; - this.lastcall=(this.skip>0)?false:true; - - - } - }, err => { - this.Load= false; - - // console.log("error",err) ; - }); -} + } + }) + }, err => { + this.Load = false; - clocation_1(latlngObj, cb) { - if(latlngObj==null){ - cb(null, latlngObj); - } + // console.log("error",err) ; + }); + + } + + clocation_1(latlngObj, cb) { + if (latlngObj == null) { + cb(null, latlngObj); + } var outerThis = this; var la = ''; @@ -8719,25 +8774,17 @@ this.reportArr1=this.reportArr lat: "0", long: "0" }; - - latLng = { - lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, - long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 - } - - - // if () { - // latLng = { - // lat: 0, - // long: 0 - // } - // } + latLng = { + lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, + long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 + } + outerThis.contactService.getAddressByApi(latLng).subscribe(res => { if (res.message == "Address not found in databse") { var adata = { - iden : 'noaddress', - latlng : latLng + iden: 'noaddress', + latlng: latLng } latlngObj['address'] = adata; // cb(null,latlngObj); @@ -8745,20 +8792,20 @@ this.reportArr1=this.reportArr lat: "0", long: "0" }; - - latLng_1 = { - lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, - long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 - } - + latLng_1 = { + lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, + long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 + } + + outerThis.contactService.getAddressByApi(latLng_1).subscribe(res => { if (res.message == "Address not found in databse") { var bdata = { - iden : 'noaddress', - latlng : latLng_1 + iden: 'noaddress', + latlng: latLng_1 } - + latlngObj['address'] = bdata; cb(null, latlngObj); @@ -8776,22 +8823,22 @@ this.reportArr1=this.reportArr lat: "0", long: "0" }; - - latLng_1 = { - lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, - long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 - } + + latLng_1 = { + lat: latlngObj.latDecimal ? latlngObj.latDecimal : 0, + long: latlngObj.longDecimal ? latlngObj.longDecimal : 0 + } + + + - - - outerThis.contactService.getAddressByApi(latLng_1).subscribe(res => { if (res.message == "Address not found in databse") { var cdata = { - iden : 'noaddress', - latlng : latLng_1 + iden: 'noaddress', + latlng: latLng_1 } - + latlngObj['address'] = cdata; cb(null, latlngObj); @@ -8809,24 +8856,24 @@ this.reportArr1=this.reportArr } - headRows() { + headRows() { return [ - // displayedColumns=['vehicleName','IMEI','totalDistance','fuel','ignOn','ignOff','idleTime','outOfReach','noGps','trips','maxSpeed','startLocation','endLocation','details']; + // displayedColumns=['vehicleName','IMEI','totalDistance','fuel','ignOn','ignOff','idleTime','outOfReach','noGps','trips','maxSpeed','startLocation','endLocation','details']; { - deviceName:'device Name', - imei:'IMEI', - date:'Date', - odo:'ODO', - distanceFromPrevious:'Distance', - speed:'Speed', - avgSpeed:'AVG Speed', - externalBattery:'Ext Battery', - temperature:'Temperature', - cumDistance:'Cum Distance', - location:'Location', - address:'Address', + deviceName: 'device Name', + imei: 'IMEI', + date: 'Date', + odo: 'ODO', + distanceFromPrevious: 'Distance', + speed: 'Speed', + avgSpeed: 'AVG Speed', + externalBattery: 'Ext Battery', + temperature: 'Temperature', + cumDistance: 'Cum Distance', + location: 'Location', + address: 'Address', } ]; } @@ -8834,87 +8881,87 @@ this.reportArr1=this.reportArr bodyRows(rowCount, pdfBody) { rowCount = rowCount || 10; let body = []; - - + + for (var j = 0; j < rowCount; j++) { - var str = (pdfBody[j] && pdfBody[j].latDecimal ? pdfBody[j].latDecimal : 0) + ' , ' + (pdfBody[j] &&pdfBody[j].longDecimal?pdfBody[j].longDecimal:0) + var str = (pdfBody[j] && pdfBody[j].latDecimal ? pdfBody[j].latDecimal : 0) + ' , ' + (pdfBody[j] && pdfBody[j].longDecimal ? pdfBody[j].longDecimal : 0) body.push({ - deviceName:pdfBody[j].Device_name, - imei:pdfBody[j].imei, - date:moment(pdfBody[j].date).format('lll'), - odo:pdfBody[j].odo?(pdfBody[j].odo).toFixed(2):0, - distanceFromPrevious:this.get_distance(pdfBody[j],pdfBody[j].index), - speed:pdfBody[j].speed, - avgSpeed:this.getavgSpeed(pdfBody[j],pdfBody[j].index), - externalBattery:pdfBody[j].external_Battery?pdfBody[j].external_Battery:'0', - temperature:pdfBody[j].temp?(parseFloat(pdfBody[j].temp)/10).toFixed(2):'0', - cumDistance:this.getcummulative_distance(pdfBody[j],pdfBody[j].index), - location:str, - address:pdfBody[j].address, + deviceName: pdfBody[j].Device_name, + imei: pdfBody[j].imei, + date: moment(pdfBody[j].date).format('lll'), + odo: pdfBody[j].odo ? (pdfBody[j].odo).toFixed(2) : 0, + distanceFromPrevious: this.get_distance(pdfBody[j], pdfBody[j].index), + speed: pdfBody[j].speed, + avgSpeed: this.getavgSpeed(pdfBody[j], pdfBody[j].index), + externalBattery: pdfBody[j].external_Battery ? pdfBody[j].external_Battery : '0', + temperature: pdfBody[j].temp ? (parseFloat(pdfBody[j].temp) / 10).toFixed(2) : '0', + cumDistance: this.getcummulative_distance(pdfBody[j], pdfBody[j].index), + location: str, + address: pdfBody[j].address, }); } return body; } -getcummulative_distance(gps_report,index){ - - if(index == 0){ - return 0.00; - }else{ - var cum_distance = parseFloat(this.reportArr1[index].odo)-parseFloat(this.reportArr1[0].odo); - return Math.abs(parseFloat(cum_distance.toFixed(2))) ; - } - -} + getcummulative_distance(gps_report, index) { -getavgSpeed(gps_report,index_1){ - if(index_1 == 0){ - return 0.00; - }else{ - var cum_distance = parseFloat(this.reportArr1[index_1].odo)-parseFloat(this.reportArr1[index_1-1].odo); - return Math.abs(parseFloat((cum_distance/0.166).toFixed(2))); - } -} - -get_distance(gps_report,index_1){ - if(index_1 == 0){ - return 0.00; - }else{ - var cum_distance = parseFloat(this.reportArr1[index_1].odo)-parseFloat(this.reportArr1[index_1-1].odo); - return Math.abs(parseFloat(cum_distance.toFixed(2))); - } - -} - -changeParking(){ - var theftAlert=this.parkingButtonShow=='grey'?true:this.parkingButtonShow=='green'?false:true - this.contactService.post('/devices/deviceupdate',{_id:this.selectedDevice,theftAlert:theftAlert}).subscribe(res=>{ - if(theftAlert){ - this.parkingButtonShow='green' - }else{ - this.parkingButtonShow='red' + if (index == 0) { + return 0.00; + } else { + var cum_distance = parseFloat(this.reportArr1[index].odo) - parseFloat(this.reportArr1[0].odo); + return Math.abs(parseFloat(cum_distance.toFixed(2))); } - }) -} + } - openRightMenu() { - document.getElementById("rightMenu").style.display = "block"; - document.getElementById('buttons').style.marginRight='325px' -} + getavgSpeed(gps_report, index_1) { + if (index_1 == 0) { + return 0.00; + } else { + var cum_distance = parseFloat(this.reportArr1[index_1].odo) - parseFloat(this.reportArr1[index_1 - 1].odo); + return Math.abs(parseFloat((cum_distance / 0.166).toFixed(2))); + } + } - closeRightMenu() { - document.getElementById("rightMenu").style.display = "none"; - document.getElementById('buttons').style.marginRight='-7px' -} + get_distance(gps_report, index_1) { + if (index_1 == 0) { + return 0.00; + } else { + var cum_distance = parseFloat(this.reportArr1[index_1].odo) - parseFloat(this.reportArr1[index_1 - 1].odo); + return Math.abs(parseFloat(cum_distance.toFixed(2))); + } -saveRoutePath(){ - let dialogRef = this.dialog.open(ShoRoutePlanComponent, { + } + + changeParking() { + var theftAlert = this.parkingButtonShow == 'grey' ? true : this.parkingButtonShow == 'green' ? false : true + this.contactService.post('/devices/deviceupdate', { _id: this.selectedDevice, theftAlert: theftAlert }).subscribe(res => { + if (theftAlert) { + this.parkingButtonShow = 'green' + } else { + this.parkingButtonShow = 'red' + } + }) + + } + + openRightMenu() { + document.getElementById("rightMenu").style.display = "block"; + document.getElementById('buttons').style.marginRight = '325px' + } + + closeRightMenu() { + document.getElementById("rightMenu").style.display = "none"; + document.getElementById('buttons').style.marginRight = '-7px' + } + + saveRoutePath() { + let dialogRef = this.dialog.open(ShoRoutePlanComponent, { width: '650px', height: '700px', - data: {data:this.latlongObjArr,device:this.tempMapHistory[0]} + data: { data: this.latlongObjArr, device: this.tempMapHistory[0] } }); dialogRef.afterClosed().subscribe(result => { @@ -8922,33 +8969,33 @@ saveRoutePath(){ // console.log(result); }) -} + } -workingHours=0 -workingHoursFunction1(device){ - // console.log(this.tempMapHistory[0]); - var date1=new Date(this.datefrom).toISOString(); - var date2=new Date(this.date2).toISOString(); - this.contactService.get('/notifs/ignitionReportForMobile?from_date='+date1+'&to_date='+date2+'&_u='+this.useridd+'&device='+device.Device_ID).subscribe((res:any)=>{ - // console.log(res); - if(res.length>0){ - this.workingHours=res[0].workingHours!="" && res[0].workingHours?res[0].workingHours:0 + workingHours = 0 + workingHoursFunction1(device) { + // console.log(this.tempMapHistory[0]); + var date1 = new Date(this.datefrom).toISOString(); + var date2 = new Date(this.date2).toISOString(); + this.contactService.get('/notifs/ignitionReportForMobile?from_date=' + date1 + '&to_date=' + date2 + '&_u=' + this.useridd + '&device=' + device.Device_ID).subscribe((res: any) => { + // console.log(res); + if (res.length > 0) { + this.workingHours = res[0].workingHours != "" && res[0].workingHours ? res[0].workingHours : 0 - } - - },err=>{ - // console.log(err); - }) -} + } -workingHoursFunction2(device){ -// console.log(this.tempMapHistory[0]); - this.contactService.get('/notifs/acReportForMobile?from_date='+this.datefrom+'&to_date='+this.date2+'&_u='+this.useridd+'&device='+device.Device_ID).subscribe((res:any)=>{ - // console.log(res); - this.workingHours=res.workingHours!="" && res.workingHours?res.workingHours:0 - },err=>{ - // console.log(err); - }) -} + }, err => { + // console.log(err); + }) + } + + workingHoursFunction2(device) { + // console.log(this.tempMapHistory[0]); + this.contactService.get('/notifs/acReportForMobile?from_date=' + this.datefrom + '&to_date=' + this.date2 + '&_u=' + this.useridd + '&device=' + device.Device_ID).subscribe((res: any) => { + // console.log(res); + this.workingHours = res.workingHours != "" && res.workingHours ? res.workingHours : 0 + }, err => { + // console.log(err); + }) + } } diff --git a/src/app/report/report component/current-position/current-position.component.ts b/src/app/report/report component/current-position/current-position.component.ts index 6994d7b..0cf7948 100644 --- a/src/app/report/report component/current-position/current-position.component.ts +++ b/src/app/report/report component/current-position/current-position.component.ts @@ -325,82 +325,115 @@ export class CurrentPositionReportComponent implements OnInit { if (that.reportArr.length != 0) { var j = 0; that.finalArr = []; - for (var i = 0; i < that.reportArr.length; i++) { - if (that.reportArr[i]) { - if (that.reportArr[i].status_updated_at == undefined) { - let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available"; - that.reportArr[i].status = dev_status_1; - // console.log("Not Available !!!"); - } else { - // this.arrival_time = new Date(that.reportArr[i].status_updated_at) - let dev_status = that.reportArr[i] ? that.reportArr[i].status : "NA"; - var curr_time: any = new Date(); - this.arrival_time = new Date(that.reportArr[i].status_updated_at); - var fd: any = new Date(this.arrival_time); - // console.log('curr_time',curr_time,this.arrival_time); - var diffInMilliSeconds = Math.abs(curr_time - fd) / 1000; + let latLongArray :any[] = []; + that.reportArr.forEach((deData)=>{ - // calculate days - const days = Math.floor(diffInMilliSeconds / 86400); - diffInMilliSeconds -= days * 86400; - // console.log('calculated days', days); - - // calculate hours - const hours = Math.floor(diffInMilliSeconds / 3600) % 24; - diffInMilliSeconds -= hours * 3600; - // console.log('calculated hours', hours); - - // calculate minutes - const minutes = Math.floor(diffInMilliSeconds / 60) % 60; - diffInMilliSeconds -= minutes * 60; - // console.log('minutes', minutes); - - let difference = ''; - if (days > 0) { - difference += (days === 1) ? `${days} day, ` : `${days} days, `; - } - - difference += (hours === 0 || hours === 1) ? `${hours} hour, ` : `${hours} hours, `; - - difference += (minutes === 0 || hours === 1) ? `${minutes} minutes` : `${minutes} minutes`; - - // new conversion logic - this.Durations = difference; - if (dev_status == undefined) { - - this.status_toShow = "NA"; - - } else { - this.status_toShow = dev_status + " " + "Since" + " " + this.Durations; - } - - that.reportArr[i].status = this.status_toShow; - } - - that.clocation_1(that.reportArr[i], function (err, succ) { - if (err) { - console.log(err); - j++; - } else { - console.log(succ); - that.finalArr.push(succ); - console.log(that.finalArr); - j++; - if (j === that.reportArr.length) { - that.Load = false; - callback({ data: that.finalArr }); - } - } - }) - } else { - that.Load = false; - callback({ data: [] }); + let latLng = { + lat: "0", + long: "0" + }; + + latLng = { + long: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[0] ? deData.last_loc.coordinates[0] : 0, + lat: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[1] ? deData.last_loc.coordinates[1]: 0 } + latLongArray.push(latLng) + + }) + + that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + + for (var i = 0; i < that.reportArr.length; i++) { + + if (that.reportArr[i]) { + let latLng = { + lat: "0", + long: "0" + }; + latLng = { + long: that.reportArr[i].last_loc && that.reportArr[i].last_loc.coordinates && that.reportArr[i].last_loc.coordinates.length && that.reportArr[i].last_loc.coordinates[0] ? that.reportArr[i].last_loc.coordinates[0] : 0, + lat: that.reportArr[i].last_loc && that.reportArr[i].last_loc.coordinates && that.reportArr[i].last_loc.coordinates.length && that.reportArr[i].last_loc.coordinates[1] ? that.reportArr[i].last_loc.coordinates[1]: 0 + } + that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[i]; + if (that.reportArr[i].status_updated_at == undefined) { + let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available"; + that.reportArr[i].status = dev_status_1; + // console.log("Not Available !!!"); + } else { + // this.arrival_time = new Date(that.reportArr[i].status_updated_at) + let dev_status = that.reportArr[i] ? that.reportArr[i].status : "NA"; + var curr_time: any = new Date(); + this.arrival_time = new Date(that.reportArr[i].status_updated_at); + var fd: any = new Date(this.arrival_time); + // console.log('curr_time',curr_time,this.arrival_time); + var diffInMilliSeconds = Math.abs(curr_time - fd) / 1000; + + // calculate days + const days = Math.floor(diffInMilliSeconds / 86400); + diffInMilliSeconds -= days * 86400; + // console.log('calculated days', days); + + // calculate hours + const hours = Math.floor(diffInMilliSeconds / 3600) % 24; + diffInMilliSeconds -= hours * 3600; + // console.log('calculated hours', hours); + + // calculate minutes + const minutes = Math.floor(diffInMilliSeconds / 60) % 60; + diffInMilliSeconds -= minutes * 60; + // console.log('minutes', minutes); + + let difference = ''; + if (days > 0) { + difference += (days === 1) ? `${days} day, ` : `${days} days, `; + } + + difference += (hours === 0 || hours === 1) ? `${hours} hour, ` : `${hours} hours, `; + + difference += (minutes === 0 || hours === 1) ? `${minutes} minutes` : `${minutes} minutes`; + + // new conversion logic + this.Durations = difference; + if (dev_status == undefined) { + + this.status_toShow = "NA"; + + } else { + this.status_toShow = dev_status + " " + "Since" + " " + this.Durations; + } + + that.reportArr[i].status = this.status_toShow; + } + + that.clocation_1(that.reportArr[i], function (err, succ) { + if (err) { + console.log(err); + j++; + } else { + console.log(succ); + that.finalArr.push(succ); + console.log(that.finalArr); + j++; + if (j === that.reportArr.length) { + that.Load = false; + callback({ data: that.finalArr }); + } + } + }) + } else { + that.Load = false; + callback({ data: [] }); + } + + + + } - } + }) + } else { that.Load = false; that.firstcall = true; diff --git a/src/app/report/report component/day-wise-report/day-wise-report.component.ts b/src/app/report/report component/day-wise-report/day-wise-report.component.ts index abf87b3..c49e19e 100644 --- a/src/app/report/report component/day-wise-report/day-wise-report.component.ts +++ b/src/app/report/report component/day-wise-report/day-wise-report.component.ts @@ -210,74 +210,93 @@ export class DayWiseReportComponent implements OnInit { that.reportArr = []; that.reportArr= resp ; if (that.reportArr.length != 0) { - console.log(that.reportArr); + var j = 0; that.finalArr = []; - for (var i = 0; i < that.reportArr.length; i++) { - // if(that.reportArr[i].distanceVariation){ - // console.log("IN"); - - // if(that.reportArr[i].distanceVariation[0]=="+"){ - // that.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']+(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1)) - // console.log("IN",(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1))); - // }else{ - - // that.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']-(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1)) - // console.log("IN-",that.reportArr[i]['Distance(Kms)']); - // } - // } - - console.log(that.reportArr[i]['Idle Time'],that.reportArr[i]['Moving Time'],that.reportArr[i]['Stoppage Time'],that.reportArr[i]['Idle Time']); + let latLongArray :any[] = []; + that.reportArr.forEach((deData)=>{ + let latLng = { + lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0, + long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0 + } + latLongArray.push(latLng) + let end_latLng = { + lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0, + long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0 + } + latLongArray.push(end_latLng) + }) - if((that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])<24){ - that.reportArr[i].outOfReach=(24-(that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])).toFixed(2) - }else{ - that.reportArr[i].outOfReach=0.0 + that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + let indexCounter = 0; + for (var i = 0; i < that.reportArr.length; i++) { + let latLng = { + lat: that.reportArr[i].start_location ? that.reportArr[i].start_location.lat ? that.reportArr[i].start_location.lat : 0:0, + long: that.reportArr[i].start_location ? that.reportArr[i].start_location.long ? that.reportArr[i].start_location.long : 0:0 + } + that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter]; + indexCounter++; + let end_latLng = { + lat: that.reportArr[i].end_location ? that.reportArr[i].end_location.lat ? that.reportArr[i].end_location.lat : 0:0, + long: that.reportArr[i].end_location ? that.reportArr[i].end_location.long ? that.reportArr[i].end_location.long : 0:0 + } + that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter]; + console.log('indexCounter++',indexCounter,i) + indexCounter++; - } - - that.clocation_1(that.reportArr[i], function (err, succ) { - if (err) { - console.log(err); - j++; - } else { - if(!(that.finalArr.includes(succ))){ - console.log(that.finalArr.includes(succ)); - for(var k=0;k{ + let latLng = { + lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0, + long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0 + } + latLongArray.push(latLng) + let end_latLng = { + lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0, + long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0 + } + latLongArray.push(end_latLng) + }) + + that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + let indexCounter = 0; + that.reportArr.forEach((deData,index)=>{ + let latLng = { + lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0, + long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0 } + that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter]; + indexCounter++; + let end_latLng = { + lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0, + long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0 + } + that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter]; + indexCounter++; + if(deData) { + + + that.clocation_1(deData, function (err, succ) { + if (err) { + console.log(err); + j++; + } else { + console.log(succ); + that.finalArr.push(succ); + console.log(that.finalArr); + j++; + if (j === that.reportArr.length) { + that.Load = false; + callback({ data: that.finalArr }); + } + } + }) + } else { + that.Load = false; + callback({ data: [] }); + + } }) - }else{ - that.Load = false; - callback({ data: [] }); - } + }) - - } + } else { that.Load = false; that.firstcall = true; diff --git a/src/app/report/report component/summary-report/summary-report.component.ts b/src/app/report/report component/summary-report/summary-report.component.ts index 81bebcb..91fc598 100644 --- a/src/app/report/report component/summary-report/summary-report.component.ts +++ b/src/app/report/report component/summary-report/summary-report.component.ts @@ -443,35 +443,98 @@ testTable() { if (that.summary.length != 0) { var j = 0; that.finalArr = []; - for (var i = 0; i < that.summary.length; i++) { - - that.clocation_1(that.summary[i], function (err, succ) { - if (err) { - console.log(err); - j++; - } else { - that.finalArr.push(succ); - console.log(that.finalArr); - j++; - if (j === that.summary.length) { - that.Load = false; - var x = []; - that.finalArr.sort(function(a,b){ - // Turn your strings into dates, and then subtract them - // to get a value that is either negative, positive, or zero. - var aDate:any = new Date(a.Date); - var bDate:any = new Date(b.Date); - return bDate - aDate; - }); - - - callback({ data: that.finalArr }); - } + + let latLongArray :any[] = []; + that.summary.forEach((deData)=>{ + let latLng = {lat:0, + long:0}; + let end_latLng = {lat:0, + long:0}; + if (deData.start_location) { + latLng = { + lat: deData.start_location.lat ? deData.start_location.lat : 0, + long: deData.start_location.long ? deData.start_location.long : 0 } - }) - + } + if (deData.today_start_location) { + latLng = { + lat: deData.today_start_location.lat ? deData.today_start_location.lat : 0, + long: deData.today_start_location.long ? deData.today_start_location.long : 0 + } + } else { + deData.today_start_location = deData.start_location; + } + latLongArray.push(latLng) + if (deData.last_location) { + end_latLng = { + lat: deData.last_location.lat ? deData.last_location.lat : 0, + long: deData.last_location.long ? deData.last_location.long : 0 + } + } + if (deData.end_location) { + end_latLng = { + lat: deData.end_location.lat ? deData.end_location.lat : 0, + long: deData.end_location.long ? deData.end_location.long : 0 + } + } else { + deData.end_location = deData.last_location; + } + latLongArray.push(end_latLng) + }) - } + that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => { + let indexCounter = 0; + that.summary.forEach((deData,index)=>{ + let latLng = { + lat: deData.today_start_location ? deData.today_start_location.lat ? deData.today_start_location.lat : 0:0, + long: deData.today_start_location ? deData.today_start_location.long ? deData.today_start_location.long : 0:0 + } + that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter]; + indexCounter++; + let end_latLng = { + lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0, + long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0 + } + that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter]; + indexCounter++; + if(deData) { + + //location code + that.clocation_1(deData, function (err, succ) { + if (err) { + console.log(err); + j++; + } else { + that.finalArr.push(succ); + console.log(that.finalArr); + j++; + if (j === that.summary.length) { + that.Load = false; + var x = []; + that.finalArr.sort(function(a,b){ + // Turn your strings into dates, and then subtract them + // to get a value that is either negative, positive, or zero. + var aDate:any = new Date(a.Date); + var bDate:any = new Date(b.Date); + return bDate - aDate; + }); + + + callback({ data: that.finalArr }); + } + } + }) + + } else { + that.Load = false; + callback({ data: [] }); + + } + }) + + }) + + } else { that.Load = false; callback({ data: [] });