map.blade.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
  2. <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
  3. <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
  4. <script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
  5. <script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
  6. @if(count($ordersMapRecords) !== count($orders))
  7. <div class="alert alert-danger mb-1">
  8. <i class="fa-solid fa-triangle-exclamation fa-fw me-1" style="font-size: 25px;"></i> There are <b>{{ count($orders) }}</b> but only <b>{{ count($ordersMapRecords) }}</b> have coordinates!
  9. </div>
  10. @endif
  11. <style>
  12. #map {
  13. width: 100%;
  14. height: 90vh;
  15. }
  16. </style>
  17. <div class="border mb-3">
  18. <div id="map"></div>
  19. </div>
  20. <script>
  21. (function($) {
  22. var mapViewComponent = {
  23. orders:<?= json_encode($ordersMapRecords) ?>,
  24. defaultLocation: [51.505, -0.09],
  25. defaultLocationZoom: 8,
  26. getRandom: function(min, max) {
  27. return Math.random() * (max - min) + min;
  28. },
  29. initMap: function() {
  30. var map = L.map('map');
  31. L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  32. attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  33. }).addTo(map);
  34. var markers = new L.MarkerClusterGroup();
  35. for (let i = 0; i < this.orders.length; i++) {
  36. let order = this.orders[i];
  37. // var lat = this.getRandom(37, 39);
  38. // var lng = this.getRandom(-9.5, -6.5);
  39. var lat = order.latitude;
  40. var lng = order.longitude;
  41. if(i == 0){
  42. this.defaultLocation = [lat, lng];
  43. }
  44. const marker = L.marker([
  45. lat,
  46. lng
  47. ])
  48. marker.bindPopup(`
  49. <b><a href="/admin/users/view/${order.clientUid}/dashboard">${order.clientName}</a><b><br>
  50. <a href="/admin/orders/view/${order.uid}/dashboard">Order #:${order.orderNumber}</a><br>
  51. <span>${order.shippingAddress}</span>
  52. `).openPopup();
  53. markers.addLayer(marker);
  54. }
  55. map.addLayer(markers);
  56. map.setView(this.defaultLocation, this.defaultLocationZoom)
  57. },
  58. init: function() {
  59. this.initMap();
  60. }
  61. };
  62. mapViewComponent.init();
  63. })(jQuery);
  64. </script>