src/component/busMap.js
// Logic to generate pair of recent path points for each vehicle.
Logic to generate pair of recent path points for each vehicle.
Logic to generate pair of recent path points for each vehicle .
generatePathJSON(vehicleData) {
        let locationCache = pathHistory,
            filteredJSON = {}
        if(Object.keys(locationCache).length === 0){
            vehicleData.map((vehicleObj) => {
                let x = mapProjection([vehicleObj.lon,vehicleObj.lat])[0],
                    y = mapProjection([vehicleObj.lon,vehicleObj.lat])[1],
                    tempArr = []
                tempArr.push([x,y])
                locationCache[vehicleObj.id] = tempArr
                return null
            })
        } else {
            vehicleData.forEach((vehicleObj) => {
                let x = mapProjection([vehicleObj.lon,vehicleObj.lat])[0],
                    y = mapProjection([vehicleObj.lon,vehicleObj.lat])[1]
                if(locationCache[vehicleObj.id]) {
                    if(locationCache[vehicleObj.id].length > 1) {
                        locationCache[vehicleObj.id].shift()
                    }
                    locationCache[vehicleObj.id].push([x,y])
                } else {
                    let tempArr = []
                    tempArr.push([x,y])
                    locationCache[vehicleObj.id] = tempArr
                }
            })
        }
        if(Object.keys(locationCache).length !== vehicleData.length) {
            vehicleData.map((vehicle)=> {
                filteredJSON[vehicle.id] = locationCache[vehicle.id]
                return null
            })
            pathHistory = {...filteredJSON}
        } else {
            pathHistory = {...locationCache}
        }
        return pathHistory
    }
generatePathJSON ( vehicleData ) { let locationCache = pathHistory , filteredJSON = { } if ( Object . keys ( locationCache ) . length === 0 ) { vehicleData . map ( ( vehicleObj ) => { let x = mapProjection ( [ vehicleObj . lon , vehicleObj . lat ] ) [ 0 ] , y = mapProjection ( [ vehicleObj . lon , vehicleObj . lat ] ) [ 1 ] , tempArr = [ ] tempArr . push ( [ x , y ] ) locationCache [ vehicleObj . id ] = tempArr return null } ) } else { vehicleData . forEach ( ( vehicleObj ) => { let x = mapProjection ( [ vehicleObj . lon , vehicleObj . lat ] ) [ 0 ] , y = mapProjection ( [ vehicleObj . lon , vehicleObj . lat ] ) [ 1 ] if ( locationCache [ vehicleObj . id ] ) { if ( locationCache [ vehicleObj . id ] . length > 1 ) { locationCache [ vehicleObj . id ] . shift ( ) } locationCache [ vehicleObj . id ] . push ( [ x , y ] ) } else { let tempArr = [ ] tempArr . push ( [ x , y ] ) locationCache [ vehicleObj . id ] = tempArr } } ) } if ( Object . keys ( locationCache ) . length !== vehicleData . length ) { vehicleData . map ( ( vehicle ) => { filteredJSON [ vehicle . id ] = locationCache [ vehicle . id ] return null } ) pathHistory = { ... filteredJSON } } else { pathHistory = { ... locationCache } } return pathHistory }
Logic to generate pair of recent path points for each vehicle.
Logic to generate pair of recent path points for each vehicle .