Support rider status changes in dashboard map #362

This commit is contained in:
Kendrick Chan 2020-03-05 07:15:26 +08:00
parent 7124a7d2c8
commit 2e3c879fd5
4 changed files with 68 additions and 2 deletions

View file

@ -51,6 +51,32 @@ class DashboardMap {
return this.map;
}
switchRiderStatus(rider_id, rider_status) {
console.log('switching rider ' + rider_id + ' to ' + rider_status);
// find the marker
console.log(this.rider_markers);
if (this.rider_markers.hasOwnProperty(rider_id)) {
var marker = this.rider_markers[rider_id];
} else {
// TODO: call ajax to get location and create marker
console.log('marker not found for rider');
return true;
}
// add it to proper layer group
console.log(rider_status);
if (rider_status == 'available') {
this.layer_groups.rider_active_jo.removeLayer(marker);
this.layer_groups.rider_available.addLayer(marker);
marker.setIcon(this.options.icons.rider_available);
} else if (rider_status == 'jo') {
this.layer_groups.rider_available.removeLayer(marker);
this.layer_groups.rider_active_jo.addLayer(marker);
marker.setIcon(this.options.icons.rider_active_jo);
}
}
putMarker(id, lat, lng, markers, icon, layer_group, popup_url) {
var my = this;
// existing marker
@ -131,6 +157,19 @@ class DashboardMap {
);
}
removeRiderMarker(id) {
console.log('removing rider marker for ' + id);
var markers = this.rider_markers;
if (!markers.hasOwnProperty(id)) {
console.log('no such marker to remove');
return;
}
this.layer_groups.rider_active_jo.removeLayer(markers[id]);
this.layer_groups.rider_available.removeLayer(markers[id]);
}
loadLocations(location_url) {
console.log(this.rider_markers);
var my = this;

View file

@ -27,18 +27,26 @@ class MapEventHandler {
console.log('mqtt connected!');
var my = icontext.invocationContext;
// subscribe to rider locations
if (my.options.track_rider) {
// subscribe to rider locations
console.log('subscribing to ' + my.options.channels.rider_location);
my.mqtt.subscribe(my.options.channels.rider_location);
// subscribe to rider status
console.log('subscribing to ' + my.options.channels.rider_status);
my.mqtt.subscribe(my.options.channels.rider_status);
}
// subscribe to jo locations
if (my.options.track_jo) {
// subscribe to jo locations
console.log('subscribing to ' + my.options.channels.jo_location);
my.mqtt.subscribe(my.options.channels.jo_location);
// subscribe to jo status
console.log('subscribing to ' + my.options.channels.jo_status);
my.mqtt.subscribe(my.options.channels.jo_status);
}
}
onMessage(msg) {
@ -75,8 +83,24 @@ class MapEventHandler {
var lat = parseFloat(pl_split[0]);
var lng = parseFloat(pl_split[1]);
// TODO: check if available or not
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
break;
case "status":
console.log("got status for rider " + chan_split[1] + " - " + payload);
switch (payload) {
case 'available':
this.dashmap.switchRiderStatus(chan_split[1], 'available');
break;
case 'jo':
console.log('jo status');
this.dashmap.switchRiderStatus(chan_split[1], 'jo');
break;
case 'logout':
this.dashmap.removeRiderMarker(chan_split[1]);
break;
}
break;
}
}
@ -102,6 +126,7 @@ class MapEventHandler {
this.dashmap.putCustomerMarker(id, lat, lng);
break;
case "status":
console.log("got status for jo " + payload);
switch (payload) {
case 'cancel':
case 'fulfill':

View file

@ -92,6 +92,7 @@ class JobOrderActiveCacheListener
protected function processInactiveJO($jo, $status = 'cancel')
{
error_log('got inactive jo, sending mqtt message for ' . $jo->getID());
// remove from redis cache
$this->jo_cache->removeActiveJobOrder($jo);

View file

@ -51,6 +51,7 @@ function initEventHandler(dashmap) {
'track_rider': true,
'channels': {
'rider_location': 'rider/+/location',
'rider_status': 'rider/+/status',
'jo_location': 'jo/+/location',
'jo_status': 'jo/+/status'
},