Advertisement
tungSfer

Untitled

Apr 16th, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var dataTemporary = [[21.0419, 105.821],
  2. [21.04188, 105.82111],
  3. [21.04186, 105.82137],
  4. [21.04183, 105.82157],
  5. [21.04182, 105.82168],
  6. [21.04179, 105.82188],
  7. [21.04173, 105.82209],
  8. [21.04165, 105.82235],
  9. [21.04158, 105.82258],
  10. [21.04156, 105.82263],
  11. [21.04155, 105.82265],
  12. [21.04147, 105.82285],
  13. [21.04143, 105.82296],
  14. [21.04141, 105.82301],
  15. [21.04129, 105.82333],
  16. [21.0412, 105.82351],
  17. [21.04114, 105.82361],
  18. [21.04113, 105.82365],
  19. [21.04105, 105.82384],
  20. [21.041, 105.82393],
  21. [21.0409, 105.82425],
  22. [21.04085, 105.82441],
  23. [21.04083, 105.82444],
  24. [21.04077, 105.82462],
  25. [21.04076, 105.82463],
  26. [21.0407, 105.8248],
  27. [21.04066, 105.82491],
  28. [21.04057, 105.82516],
  29. [21.04052, 105.82529],
  30. [21.04045, 105.82548],
  31. [21.0404, 105.82562],
  32. [21.04037, 105.82576],
  33. [21.04031, 105.82595],
  34. [21.04023, 105.82618],
  35. [21.04019, 105.8263],
  36. [21.04016, 105.82637],
  37. [21.04009, 105.82653],
  38. [21.04007, 105.82656],
  39. [21.04, 105.82671],
  40. [21.03995, 105.82683],
  41. [21.03986, 105.82702],
  42. [21.03983, 105.82708],
  43. [21.03977, 105.82731],
  44. [21.03972, 105.82748],
  45. [21.03965, 105.82769],
  46. [21.03959, 105.82802],
  47. [21.03952, 105.82841],
  48. [21.03952, 105.8285],
  49. [21.03953, 105.8286],
  50. [21.03957, 105.82871],
  51. [21.03957, 105.82871],
  52. [21.03946, 105.82874],
  53. [21.03921, 105.82882],
  54. [21.03918, 105.82883],
  55. [21.03881, 105.829],
  56. [21.03866, 105.82904],
  57. [21.03841, 105.82913],
  58. [21.03839, 105.8292],
  59. [21.03836, 105.82925],
  60. [21.03823, 105.82966],
  61. [21.03818, 105.82972],
  62. [21.03806, 105.82977],
  63. [21.03785, 105.82976],
  64. [21.03776, 105.8299],
  65. [21.03776, 105.83003],
  66. [21.03776, 105.8302],
  67. [21.03775, 105.83051],
  68. [21.03777, 105.83096],
  69. [21.03772, 105.83102],
  70. [21.03767, 105.83105],
  71. [21.03755, 105.83109],
  72. [21.03751, 105.83109],
  73. [21.03747, 105.83109],
  74. [21.0374, 105.83109],
  75. [21.03712, 105.8311],
  76. [21.03677, 105.8311],
  77. [21.03657, 105.8311],
  78. [21.0365, 105.83112],
  79. [21.03637, 105.83116],
  80. [21.03621, 105.83121],
  81. [21.03596, 105.83129],
  82. [21.03583, 105.83133],
  83. [21.03525, 105.83149],
  84. [21.03512, 105.83153],
  85. [21.03495, 105.83159],
  86. [21.03486, 105.83162],
  87. [21.03481, 105.83163],
  88. [21.0347, 105.83167],
  89. [21.03466, 105.83167],
  90. [21.03452, 105.8317],
  91. [21.03446, 105.83171],
  92. [21.03446, 105.83171],
  93. [21.03442, 105.83162],
  94. [21.03442, 105.83157],
  95. [21.03446, 105.83083],
  96. [21.03448, 105.83052],
  97. [21.03448, 105.83045],
  98. [21.03449, 105.83027],
  99. [21.03453, 105.82988],
  100. [21.03454, 105.82975],
  101. [21.03454, 105.82963],
  102. [21.03457, 105.82924],
  103. [21.03459, 105.82906],
  104. [21.03461, 105.82883],
  105. [21.03461, 105.82873],
  106. [21.03462, 105.8286],
  107. [21.03463, 105.8285],
  108. [21.03463, 105.82849],
  109. [21.03464, 105.82837],
  110. [21.03465, 105.82828],
  111. [21.03465, 105.82826],
  112. [21.03465, 105.82825],
  113. [21.03466, 105.82809],
  114. [21.03467, 105.82804],
  115. [21.03467, 105.828],
  116. [21.03467, 105.82795],
  117. [21.03468, 105.82789],
  118. [21.0347, 105.8276],
  119. [21.03471, 105.82746],
  120. [21.03472, 105.82733],
  121. [21.03472, 105.82717],
  122. [21.03475, 105.82697],
  123. [21.03476, 105.82678],
  124. [21.03478, 105.82662],
  125. [21.03483, 105.82607],
  126. [21.03484, 105.82599],
  127. [21.03485, 105.82574],
  128. [21.03486, 105.82566],
  129. [21.03487, 105.82559],
  130. [21.03488, 105.82536],
  131. [21.03489, 105.82532],
  132. [21.03489, 105.82526],
  133. [21.0349, 105.82513],
  134. [21.03491, 105.82497],
  135. [21.03491, 105.82493],
  136. [21.03491, 105.82488],
  137. [21.03493, 105.82467],
  138. [21.03494, 105.82457],
  139. [21.03494, 105.82451],
  140. [21.03495, 105.82441],
  141. [21.03497, 105.82411],
  142. [21.03499, 105.8239],
  143. [21.03506, 105.82336],
  144. [21.03506, 105.82329],
  145. [21.03507, 105.82319],
  146. [21.03508, 105.8231],
  147. [21.03509, 105.82297],
  148. [21.03509, 105.82293],
  149. [21.03509, 105.8229],
  150. [21.0351, 105.82279],
  151. [21.0351, 105.82271],
  152. [21.03511, 105.82261],
  153. [21.03513, 105.82235],
  154. [21.03514, 105.8223],
  155. [21.03514, 105.82224],
  156. [21.03514, 105.82222],
  157. [21.03515, 105.82213],
  158. [21.03516, 105.82199],
  159. [21.03516, 105.82196],
  160. [21.03517, 105.82181],
  161. [21.03518, 105.82169],
  162. [21.03519, 105.82156],
  163. [21.03519, 105.82148],
  164. [21.0352, 105.8214],
  165. [21.03523, 105.82101],
  166. [21.03524, 105.82082],
  167. [21.03527, 105.8203],
  168. [21.03527, 105.8203],
  169. [21.03541, 105.82032],
  170. [21.03559, 105.82034],
  171. [21.03613, 105.82038],
  172. [21.03635, 105.8204],
  173. [21.03659, 105.8204],
  174. [21.03685, 105.82043],
  175. [21.03705, 105.82045],
  176. [21.03723, 105.82048],
  177. [21.03856, 105.82064],
  178. [21.03874, 105.82066],
  179. [21.03879, 105.82071],
  180. [21.03882, 105.82076],
  181. [21.03884, 105.82082],
  182. [21.03884, 105.82088],
  183. [21.03884, 105.82095],
  184. [21.03883, 105.82102],
  185. [21.03882, 105.8211],
  186. [21.03881, 105.82119],
  187. [21.0388, 105.82131],
  188. [21.03874, 105.82193],
  189. [21.03873, 105.82211],
  190. [21.0387, 105.82263],
  191. [21.03864, 105.82287],
  192. [21.03844, 105.82336],
  193. [21.03836, 105.82362],
  194. [21.03831, 105.82387],
  195. [21.0383, 105.82391],
  196. [21.03828, 105.82404],
  197. [21.03827, 105.82422],
  198. [21.03827, 105.82436],
  199. [21.03827, 105.82449],
  200. [21.03826, 105.82461],
  201. [21.03825, 105.82471],
  202. [21.03823, 105.82481],
  203. [21.0382, 105.82494],
  204. [21.03818, 105.82501],
  205. [21.03818, 105.82501],
  206. [21.0382, 105.82501],
  207. [21.0382, 105.82501]
  208. ];
  209.  
  210. function updateService(dataTemporary) {
  211.     let id = "HN1234";
  212.     for (let i = 0; i < dataTemporary.length; i++) {
  213.         // console.log(dataTemporary[i][0], dataTemporary[i][1]);
  214.         setTimeout(function () {
  215.             $.getJSON("/majestic/Dashboard/php/api/post/update_service.php", {
  216.                 id:id,
  217.                 lat: dataTemporary[i][0],
  218.                 long: dataTemporary[i][1]
  219.             }, function (data) {
  220.                 // console.log(data);
  221.             });
  222.  
  223.         }, 500*i);
  224.  
  225.     }
  226. }
  227. updateService(dataTemporary);
  228.  
  229. // function loadname(){
  230. //     $.getJSON('/majestic/Dashboard/php/api/post/R_temporary.php',{},function (data) {
  231. //         // console.log(data);
  232. //         $("#display-username").text(data["username"]);
  233. //         // $("#display-fullname").text('Welcome back ' + data["fullname"]);
  234. //     });
  235. // }
  236. // window.onload=loadname;
  237. // Define map
  238.  
  239. var cities = L.layerGroup();
  240. var mLittleton = L.marker([21.1227, 105.7532], { icon: iconRed }).bindPopup('This is Littleton, CO.').addTo(cities);
  241. var mDenver = L.marker([21.0046, 105.8529], { icon: iconRed }).bindPopup('This is Denver, CO.').addTo(cities);
  242. var mAurora = L.marker([21.1108, 105.852], { icon: iconRed }).bindPopup('This is Aurora, CO.').addTo(cities);
  243. var mGolden = L.marker([21.05285, 105.852], { icon: iconRed }).bindPopup('This is Golden, CO.').addTo(cities);
  244.  
  245. var mbAttr = 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>';
  246. var mbUrl = 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
  247.  
  248. var grayscale = L.tileLayer(mbUrl, { id: 'mapbox/light-v9', tileSize: 512, zoomOffset: -1, attribution: mbAttr });
  249. var streets = L.tileLayer(mbUrl, { id: 'mapbox/streets-v11', tileSize: 512, zoomOffset: -1, attribution: mbAttr });
  250. var outdoors = L.tileLayer(mbUrl, { id: 'mapbox/outdoors-v11', tileSize: 512, zoomOffset: -1, attribution: mbAttr });
  251.  
  252. var mylayers = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  253.     attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  254. })
  255. var googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
  256.     maxZoom: 20,
  257.     subdomains:['mt0','mt1','mt2','mt3']
  258. });
  259. // Hybrid: s,h;
  260. // Satellite: s;
  261. // Streets: m;
  262. // Terrain: p;
  263. var map = L.map('map', {
  264.     center: [21.57201, 105.61388],
  265.     maxZoom: 20,
  266.     layers: [streets]
  267.     // layers: [googleStreets, cities]
  268. });
  269.  
  270. // var control = L.Routing.control({
  271. //     waypoints: [
  272. //         L.latLng(21.0419, 105.821),
  273. //         L.latLng(21.0382, 105.825)
  274. //     ],
  275. //     routeWhileDragging: true,
  276. //     // createMarker: function () {
  277. //     //     return null;
  278. //     // }
  279. // }).addTo(map);
  280.  
  281. var xxx = L.polyline(dataTemporary).addTo(map);
  282.  
  283. map.setView([21.037181, 105.833485], 15);
  284.  
  285. var baseLayers = {
  286.     'Grayscale': grayscale,
  287.     'Streets': streets,
  288.     'Outdoors': outdoors,
  289.     'MyLayers': mylayers,
  290.     'Google Streets': googleStreets
  291. };
  292.  
  293. var overlays = {
  294.     'Cities': cities
  295. };
  296.  
  297. // var layerControl = L.control.layers(baseLayers, overlays).addTo(map);
  298. var layerControl = L.control.layers(baseLayers).addTo(map);
  299.  
  300. var iconRed = L.icon({
  301.     iconUrl: './images/red-garbage.png',
  302.     iconSize: [25, 41],
  303. });
  304. var iconGreen = L.icon({
  305.     iconUrl: './images/green-garbage.png',
  306.     iconSize: [25, 41],
  307. });
  308. var iconYellow = L.icon({
  309.     iconUrl: './images/yellow-garbage.png',
  310.     iconSize: [25, 41],
  311. });
  312. var iconVehicleRed = L.icon({
  313.     iconUrl: './images/red-vehicle.png',
  314.     iconSize: [16, 35],
  315. });
  316. var iconVehicleGreen = L.icon({
  317.     iconUrl: './images/green-vehicle.png',
  318.     iconSize: [16, 35],
  319. });
  320.  
  321. (function() {
  322.     // save these original methods before they are overwritten
  323.     var proto_initIcon = L.Marker.prototype._initIcon;
  324.     var proto_setPos = L.Marker.prototype._setPos;
  325.  
  326.     var oldIE = (L.DomUtil.TRANSFORM === 'msTransform');
  327.  
  328.     L.Marker.addInitHook(function() {
  329.         var iconOptions = this.options.icon && this.options.icon.options;
  330.         var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
  331.         if (iconAnchor) {
  332.             iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
  333.         }
  334.         this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center center';
  335.         this.options.rotationAngle = this.options.rotationAngle || 0;
  336.  
  337.         // Ensure marker keeps rotated during dragging
  338.         this.on('drag', function(e) { e.target._applyRotation(); });
  339.     });
  340.  
  341.     L.Marker.include({
  342.         _initIcon: function() {
  343.             proto_initIcon.call(this);
  344.         },
  345.  
  346.         _setPos: function(pos) {
  347.             proto_setPos.call(this, pos);
  348.             this._applyRotation();
  349.         },
  350.  
  351.         _applyRotation: function() {
  352.             if (this.options.rotationAngle) {
  353.                 this._icon.style[L.DomUtil.TRANSFORM + 'Origin'] = this.options.rotationOrigin;
  354.  
  355.                 if (oldIE) {
  356.                     // for IE 9, use the 2D rotation
  357.                     this._icon.style[L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
  358.                     // this._icon.style[L.DomUtil.TRANSITION] = 'all 2s linear';
  359.                 } else {
  360.                     // for modern browsers, prefer the 3D accelerated version
  361.                     this._icon.style[L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
  362.                     // this._icon.style[L.DomUtil.TRANSITION] = 'all 2s linear';
  363.                 }
  364.             }
  365.         },
  366.  
  367.         setRotationAngle: function(angle) {
  368.             this.options.rotationAngle = angle;
  369.             this.update();
  370.             return this;
  371.         },
  372.  
  373.         setRotationOrigin: function(origin) {
  374.             this.options.rotationOrigin = origin;
  375.             this.update();
  376.             return this;
  377.         }
  378.     });
  379. })();
  380.  
  381.  
  382. function _getAngle(startx, starty, endx, endy) {
  383.     var tan = 0
  384.     if (endx == startx) {
  385.         tan = 90;
  386.     } else {
  387.         tan = Math.atan(Math.abs((endy - starty) / (endx - startx))) * 180 / Math.PI;
  388.         console.log(tan);
  389.     }
  390.  
  391.     if (endx >= startx && endy >= starty) //First quadrant
  392.     {
  393.         return -tan;
  394.     } else if (endx > startx && endy < starty) //Delta Quadrant
  395.     {
  396.         return tan;
  397.     } else if (endx < startx && endy > starty) //Beta Quadrant
  398.     {
  399.         return tan - 180;
  400.     } else {
  401.         return 180 - tan; //third quadrant
  402.     }
  403. }
  404.  
  405.  
  406. var statBin = {
  407.     "full": iconRed,
  408.     "empty": iconGreen,
  409.     "mid": iconYellow,
  410. };
  411. var statVehicle = {
  412.     "on": iconVehicleRed,
  413.     "On work": iconVehicleGreen,
  414. };
  415.  
  416. objLatlngs = [];
  417. $.getJSON('/majestic/Dashboard/php/api/post/R_vehicle.php', {}, (data) => {
  418.     let body = document.querySelector(".table tbody");
  419.     for (let i = 0; i < data.data.length; i++) {
  420.         let oV = {
  421.             lat: data.data[i].lat,
  422.             long: data.data[i].long,
  423.             angle: 0
  424.         }
  425.         objLatlngs.push(oV);
  426.     }
  427. });
  428. // console.log(objLatlngs);
  429.  
  430. var objBin = [];
  431. var objVehicle = [];
  432. var layerGrBin, layerGrVehicle;
  433. var oB = new Object();
  434. var oV = new Object();
  435. setInterval(function() {
  436.     objBin = [];
  437.     $.getJSON('/majestic/Dashboard/php/api/post/R_bin.php', {}, (data) => {
  438.        
  439.         for (let i = 0; i < data.data.length; i++) {
  440.             oB = {
  441.                 lat: data.data[i].lat,
  442.                 long: data.data[i].long,
  443.                 markerBin: L.marker([data.data[i].lat, data.data[i].long]).bindPopup(
  444.                 "ID: "+data.data[i].id +"<br>" +
  445.                 "addresses: "+data.data[i].addresses +"<br>" +
  446.                 "createddate: "+data.data[i].createddate +"<br>" +
  447.                 "lat: "+data.data[i].lat +"<br>" +
  448.                 "long: "+data.data[i].long +"<br>" +
  449.                 "statuses: "+data.data[i].statuses +"<br>"
  450.                 ).openPopup()
  451.             };
  452.             oB.markerBin.setIcon(statBin[data.data[i].statuses]);
  453.             objBin.push(oB.markerBin);
  454.         }
  455.     });
  456.     objVehicle = [];
  457.     $.getJSON('/majestic/Dashboard/php/api/post/R_vehicle.php', {}, (data) => {
  458.         // console.log(data);
  459.         let body = document.querySelector(".table tbody");
  460.         for (let i = 0; i < data.data.length; i++) {
  461.             oV = {
  462.                 lat: data.data[i].lat,
  463.                 long: data.data[i].long,
  464.                 markerVehicle: L.marker([data.data[i].lat, data.data[i].long]).bindPopup(
  465.                 "ID: "+data.data[i].id +"<br>" +
  466.                 // "typed: "+data.data[i].typed +"<br>" +
  467.                 "license: "+data.data[i].license +"<br>" +
  468.                 // "code: "+data.data[i].code +"<br>" +
  469.                 "lat: "+data.data[i].lat +"<br>" +
  470.                 "long: "+data.data[i].long +"<br>" +
  471.                 "addresses: "+data.data[i].addresses +"<br>" +
  472.                 "statuses: "+data.data[i].statuses +"<br>"
  473.                 ).openPopup()
  474.             }
  475.             oV.markerVehicle.setIcon(statVehicle[data.data[i].statuses]);
  476.             objVehicle.push(oV.markerVehicle);
  477.         }
  478.     });
  479.     setTimeout(function() {
  480.         for (let i = 0; i < objVehicle.length; i++) {
  481.             if (objVehicle[i]._latlng.lat !== objLatlngs[i].lat || objVehicle[i]._latlng.lng !== objLatlngs[i].long) {
  482.                 let angle = _getAngle(objLatlngs[i].long, objLatlngs[i].lat, objVehicle[i]._latlng.lng, objVehicle[i]._latlng.lat);
  483.                 // objVehicle[i].setRotationAngle(angle);
  484.                 // objVehicle[i].setRotationOrigin(16 + 'px ' + 35 + 'px');
  485.                 objLatlngs[i].angle = angle;
  486.                 objLatlngs[i].lat = objVehicle[i]._latlng.lat;
  487.                 objLatlngs[i].long = objVehicle[i]._latlng.lng;
  488.                 console.log("Update");
  489.             }
  490.             if (objVehicle[i].options.rotationAngle == 0) {
  491.                 objVehicle[i].setRotationAngle(objLatlngs[i].angle);
  492.                 objVehicle[i].setRotationOrigin(16 + 'px ' + 35 + 'px');
  493.             }
  494.             console.log(objVehicle[i].options.rotationAngle);
  495.         }
  496.         if (layerGrBin) {
  497.             map.removeLayer(layerGrBin);
  498.         }
  499.         if (layerGrVehicle) {
  500.             map.removeLayer(layerGrVehicle);
  501.         }
  502.         layerGrBin = L.layerGroup(objBin).addTo(map);
  503.         layerGrVehicle = L.layerGroup(objVehicle).addTo(map);
  504.        
  505.     }, 200);
  506. }, 500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement