diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 99b4da36..d678c95d 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -39,12 +39,44 @@ class HomeController extends Controller $rider_id = $rider->getID(); $coordinates = $rider_tracker->getRiderLocation($rider_id); - $long = $coordinates->getLongitude(); $lat = $coordinates->getLatitude(); + $long = $coordinates->getLongitude(); + + $jo = $rider->getActiveJobOrder(); + if ($jo == null) + { + $has_jo = false; + $clat = 0; + $clong = 0; + $jo_data = []; + } + else + { + $has_jo = true; + $cust_loc = $jo->getCoordinates(); + $clat = $cust_loc->getLatitude(); + $clong = $cust_loc->getLongitude(); + $jo_id = $jo->getID(); + $jo_data = [ + 'id' => $jo_id, + 'status' => $jo->getStatusText(), + 'stype' => $jo->getServiceTypeName(), + 'url' => $this->generateUrl('jo_all_form', ['id' => $jo_id]), + 'plate' => $jo->getCustomerVehicle()->getPlateNumber(), + 'cname' => $jo->getCustomer()->getNameDisplay(), + ]; + } + // use rider map label as key $rider_map_label = $rider->getMapLabel(); - $locations[$rider_map_label] = array($lat, $long); + $locations[$rider_id] = [ + 'label' => $rider->getMapLabel(), + 'loc' => [$lat, $long], + 'has_jo' => $has_jo, + 'cust_loc' => [$clat, $clong], + 'jo' => $jo_data, + ]; } diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 69fd5b3e..5ae565a5 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -234,6 +234,11 @@ class Customer return $this->last_name; } + public function getNameDisplay() + { + return $this->first_name . ' ' . $this->last_name; + } + public function setCustomerClassification($customer_classification) { $this->customer_classification = $customer_classification; diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index fbe9fee5..f9331c03 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -322,7 +322,7 @@ class Rider public function getMapLabel() { - $map_label = $this->id . '-' . $this->first_name .' ' . $this->last_name; + $map_label = $this->first_name .' ' . $this->last_name; return $map_label; } } diff --git a/templates/home.html.twig b/templates/home.html.twig index c5a4b8d9..1b4a41c1 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -1,5 +1,46 @@ {% extends 'base.html.twig' %} +{% block stylesheets %} + + +{% endblock %} + {% block body %}
diff --git a/templates/map/initOpenStreetMap.js b/templates/map/initOpenStreetMap.js index f14c2cef..2198c61b 100644 --- a/templates/map/initOpenStreetMap.js +++ b/templates/map/initOpenStreetMap.js @@ -20,33 +20,86 @@ function mapCreate(div_id, center_lat, center_lng, map_type, zoom) { accessToken: 'pk.eyJ1Ijoia2NvcmRlcm8iLCJhIjoiY2szbzA3ZHdsMDZxdTNsbGl4ZGNnN2VxaSJ9.LRzAe3RlV8sIP1N1x0chdw' }).addTo(map); - // rider marker layer group + // layer groups // .addTo(map) --> this will display your riders by default - var ridersLayerGroup = L.layerGroup().addTo(map); + var lg_avail_rider = L.layerGroup().addTo(map); + var lg_jo_rider = L.layerGroup().addTo(map); + var lg_cust = L.layerGroup().addTo(map); // this little snippet will not display your riders by default. // Instead, a toggle button will display in the map, with a checkbox with text Riders. // Check that to display the riders //var ridersLayerGroup = L.layerGroup(); + // create icons + var icon_rider_active_jo = L.divIcon({ + className: 'custom-div-icon', + html: "", + iconSize: [39, 42], + iconAnchor: [15, 42] + }); + var icon_rider_available = L.divIcon({ + className: 'custom-div-icon', + html: "", + iconSize: [39, 42], + iconAnchor: [15, 42] + }); + var icon_customer = L.divIcon({ + className: 'custom-div-icon', + html: "", + iconSize: [39, 42], + iconAnchor: [15, 42] + }); + $.ajax({ url: '{{ path('rider_locations') }}', }).done(function(response) { // clear all markers - ridersLayerGroup.clearLayers(); + lg_avail_rider.clearLayers(); + lg_jo_rider.clearLayers(); + lg_cust.clearLayers(); // get riders and mark var riders = response.riders; - $.each(riders, function(rider_id, point) { + $.each(riders, function(rider_id, rider_data) { + // rider location + var point = rider_data['loc']; var lat = point[0]; var long = point[1]; - // create markers - var marker = L.marker([lat, long]).bindPopup(rider_id); + // customer location + var cloc = rider_data['cust_loc']; + var clat = cloc[0]; + var clong = cloc[1]; - // add marker/layer to layergroup - ridersLayerGroup.addLayer(marker); + // rider popup content + rider_popup = '' + rider_data['label'] + ''; + + // create rider markers + if (rider_data['has_jo']) { + var jo_data = rider_data['jo']; + rider_popup += '