Fix issue of icon not displaying when rider goes online. #436
This commit is contained in:
parent
326bbeaed2
commit
0c845b456e
3 changed files with 29 additions and 4 deletions
|
|
@ -211,6 +211,8 @@ class DashboardMap {
|
|||
|
||||
this.layer_groups.customer.removeLayer(markers[id]);
|
||||
this.layer_groups.mobile_customer.removeLayer(markers[id]);
|
||||
|
||||
delete markers[id];
|
||||
}
|
||||
|
||||
putMobileCustomerMarker(id, lat, lng) {
|
||||
|
|
@ -260,6 +262,8 @@ class DashboardMap {
|
|||
|
||||
this.layer_groups.rider_active_jo.removeLayer(markers[id]);
|
||||
this.layer_groups.rider_available.removeLayer(markers[id]);
|
||||
|
||||
delete markers[id];
|
||||
}
|
||||
|
||||
loadLocations(location_url) {
|
||||
|
|
|
|||
|
|
@ -82,11 +82,16 @@ class MapEventHandler {
|
|||
switch (chan_split[2]) {
|
||||
case "availability":
|
||||
console.log("got availability for rider " + chan_split[1] + " - " + payload);
|
||||
switch (payload) {
|
||||
var obj = JSON.parse(payload);
|
||||
var status = obj.status;
|
||||
console.log("status " + status);
|
||||
switch (status) {
|
||||
case 'rider_offline':
|
||||
this.dashmap.removeRiderMarker(chan_split[1]);
|
||||
break;
|
||||
case 'rider_online':
|
||||
var lat = parseFloat(obj.latitude);
|
||||
var lng = parseFloat(obj.longitude);
|
||||
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use App\Service\MQTTClient;
|
|||
use App\Service\WarrantyHandler;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\RiderTracker;
|
||||
|
||||
use App\Entity\RiderSession;
|
||||
use App\Entity\Rider;
|
||||
|
|
@ -57,7 +58,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
EncoderFactoryInterface $ef, RiderCache $rcache,
|
||||
string $country_code, MQTTClient $mclient,
|
||||
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
|
||||
InvoiceGeneratorInterface $ic, string $upload_dir)
|
||||
InvoiceGeneratorInterface $ic, string $upload_dir,
|
||||
RiderTracker $rider_tracker)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->redis = $redis;
|
||||
|
|
@ -69,6 +71,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$this->jo_handler = $jo_handler;
|
||||
$this->ic = $ic;
|
||||
$this->upload_dir = $upload_dir;
|
||||
$this->rider_tracker = $rider_tracker;
|
||||
|
||||
// one device = one session, since we have control over the devices
|
||||
// when a rider logs in, we just change the rider assigned to the device
|
||||
|
|
@ -282,8 +285,18 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$this->em->flush();
|
||||
|
||||
// send mqtt event to put rider on map
|
||||
// get rider coordinates from redis
|
||||
$coord = $this->rider_tracker->getRiderLocation($rider->getID());
|
||||
|
||||
$lng = $coord->getLongitude();
|
||||
$lat = $coord->getLatitude();;
|
||||
$channel = 'rider/' . $rider->getID() . '/availability';
|
||||
$this->mclient->publish($channel, 'rider_online');
|
||||
$payload = [
|
||||
'status' => 'rider_online',
|
||||
'longitude' => $lng,
|
||||
'latitude' => $lat,
|
||||
];
|
||||
$this->mclient->publish($channel, json_encode($payload));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -307,7 +320,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
|
||||
// send mqtt event to remove rider from map
|
||||
$channel = 'rider/' . $rider->getID() . '/availability';
|
||||
$this->mclient->publish($channel, 'rider_offline');
|
||||
$payload = [
|
||||
'status' => 'rider_offline'
|
||||
];
|
||||
$this->mclient->publish($channel, json_encode($payload));
|
||||
|
||||
return $data;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue