diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 51e43b4c..29d42731 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -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) { diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 65736b4c..73138723 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -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; } diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 066b76d4..fc2b1272 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -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;