Advertisement
tungSfer

map

Apr 8th, 2022
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. var iconRed = L.icon({
  2.     iconUrl: './images/red-garbage.png',
  3.     iconSize: [25, 41],
  4. });
  5. var iconGreen = L.icon({
  6.     iconUrl: './images/green-garbage.png',
  7.     iconSize: [25, 41],
  8. });
  9. var iconYellow = L.icon({
  10.     iconUrl: './images/yellow-garbage.png',
  11.     iconSize: [25, 41],
  12. });
  13. var iconVehicleRed = L.icon({
  14.     iconUrl: './images/red-vehicle.png',
  15.     iconSize: [16, 35],
  16. });
  17. var iconVehicleGreen = L.icon({
  18.     iconUrl: './images/green-vehicle.png',
  19.     iconSize: [16, 35],
  20. });
  21.  
  22. var map = L.map('map').setView([21.037181, 105.833485], 15);
  23.  
  24. L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  25.     attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
  26.     maxZoom: 20,
  27.     id: 'mapbox/streets-v11',
  28.     tileSize: 512,
  29.     zoomOffset: -1,
  30. }).addTo(map);
  31.  
  32. var statBin = {
  33.     "full": iconRed,
  34.     "empty": iconGreen,
  35.     "mid": iconYellow,
  36. };
  37. var statVehicle = {
  38.     "Free": iconVehicleRed,
  39.     "On work": iconVehicleGreen,
  40. };
  41. var objBin = [];
  42. var objVehicle = [];
  43. var layerGrBin, layerGrVehicle;
  44. var oB = new Object();
  45. var oV = new Object();
  46. setInterval(function() {
  47.     objBin = [];
  48.     $.getJSON('/majestic/Dashboard/php/api/post/R_bin.php', {}, (data) => {
  49.         for (let i = 0; i < data.data.length; i++) {
  50.             oB = {
  51.                 lat: data.data[i].lat,
  52.                 long: data.data[i].long,
  53.                 markerBin: L.marker([data.data[i].lat, data.data[i].long]),
  54.             };
  55.             oB.markerBin.setIcon(statBin[data.data[i].statuses]);
  56.             objBin.push(oB.markerBin);
  57.         }
  58.         console.log(objBin);
  59.     });
  60.     objVehicle = [];
  61.     $.getJSON('/majestic/Dashboard/php/api/post/R_vehicle.php', {}, (data) => {
  62.         let body = document.querySelector(".table tbody");
  63.         for (let i = 0; i < data.data.length; i++) {
  64.             oV = {
  65.                 lat: data.data[i].lat,
  66.                 long: data.data[i].long,
  67.                 markerVehicle: L.marker([data.data[i].lat, data.data[i].long]),
  68.             }
  69.             oV.markerVehicle.setIcon(statVehicle[data.data[i].statuses]);
  70.             objVehicle.push(oV.markerVehicle);
  71.         }
  72.     });
  73.     setTimeout(function() {
  74.         console.log(objBin);
  75.         console.log(objVehicle);
  76.         if (layerGrBin) {
  77.             map.removeLayer(layerGrBin);
  78.         }
  79.         if (layerGrVehicle) {
  80.             map.removeLayer(layerGrVehicle);
  81.         }
  82.         layerGrBin = L.layerGroup(objBin).addTo(map);
  83.         layerGrVehicle = L.layerGroup(objVehicle).addTo(map);
  84.     }, 1500);
  85. }, 2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement