script.blade.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <script>
  2. mapboxgl.accessToken = 'pk.eyJ1IjoiYXJtMDIiLCJhIjoiY2s4OTIxb2FpMDJoNjNlbnQzcmF1and1cyJ9.lVxm5Y1NFV96PL3u7bGu1A';
  3. var coordinates = document.getElementById('coordinates');
  4. var map = new mapboxgl.Map({
  5. container: 'qrCodeMap',
  6. style: 'mapbox://styles/mapbox/streets-v11',
  7. center: [113.347842, -0.050812],
  8. zoom: 4,
  9. });
  10. var dragMarker = new mapboxgl.Marker({
  11. draggable: true,
  12. color: 'red'
  13. })
  14. .setLngLat([117.35918201131932, -4.227448935594907])
  15. .addTo(map);
  16. function setCircleRadius(point)
  17. {
  18. var mapLayer = map.getLayer('circle');
  19. if(typeof mapLayer !== 'undefined') {
  20. map.removeLayer('circle').removeSource('circle');
  21. }
  22. map.addSource("circle", {
  23. "type": "geojson",
  24. "data": {
  25. "type": "FeatureCollection",
  26. "features": [{
  27. "type": "Feature",
  28. "geometry": {
  29. "type": "Point",
  30. "coordinates": [point[0], point[1]]
  31. }
  32. }]
  33. }
  34. });
  35. const metersToPixelsAtMaxZoom = (meters, latitude) =>
  36. meters / 0.075 / Math.cos(latitude * Math.PI / 180)
  37. console.log(metersToPixelsAtMaxZoom(50, point[1]));
  38. map.addLayer({
  39. "id": "circle",
  40. "type": "circle",
  41. "source": "circle",
  42. "paint": {
  43. "circle-radius": {
  44. stops: [
  45. [0, 0], [20, metersToPixelsAtMaxZoom(50, point[1])] ],
  46. base: 2
  47. },
  48. "circle-color": "lightblue",
  49. "circle-opacity": 0.6
  50. }
  51. });
  52. }
  53. map.on('load', function() {
  54. setCircleRadius([117.35918201131932, -4.227448935594907]);
  55. });
  56. function onDragEnd() {
  57. var lngLat = dragMarker.getLngLat();
  58. $.confirm({
  59. title: 'Location',
  60. content: '<b>Longitude : </b> ' + lngLat.lng + '<br /><b>Latitude : </b>' + lngLat.lat,
  61. type: 'blue',
  62. icon: 'fa fa-compass',
  63. typeAnimated: true,
  64. buttons: {
  65. close: function () {
  66. }
  67. }
  68. });
  69. }
  70. dragMarker.on('dragend', onDragEnd);
  71. var geocoder = new MapboxGeocoder({
  72. accessToken: mapboxgl.accessToken,
  73. mapboxgl: mapboxgl,
  74. marker: {
  75. color: 'red'
  76. },
  77. zoom: 16,
  78. placeholder: "Enter an address or place name",
  79. });
  80. map.addControl(geocoder, 'top-left');
  81. $(document).ready(function(){
  82. $("select#qrcode_select").on("change", function() {
  83. var val = $(this).text();
  84. console.log($(this).val());
  85. $.ajax({
  86. method: 'GET',
  87. url: '{{ url()->current() }}/longlat/' + $(this).val()
  88. }).done(function(data) {
  89. console.log(data.longitude);
  90. console.log(data.latitude);
  91. $("#addSiteBtn").hide();
  92. $("#editSiteBtn").hide();
  93. $("div.mapboxgl-marker.mapboxgl-marker-anchor-center").remove();
  94. var point = [data.longitude, data.latitude];
  95. console.log(point);
  96. var query = '{{URL::current()}}/radius/' + data.longitude + '/' + data.latitude;
  97. console.log(query);
  98. $.ajax({
  99. method: 'GET',
  100. url: query
  101. }).done(function(data) {
  102. console.log(data);
  103. var is_null = 0;
  104. data.forEach(function(result) {
  105. if (result.site_id != null) {
  106. is_null++;
  107. var site_id = result.site_id;
  108. }else{
  109. var site_id = 'BELUM TERDAFTAR';
  110. }
  111. var marker = new mapboxgl.Marker({
  112. draggable: false,
  113. color: 'orange'
  114. })
  115. .setLngLat([result.sid_long, result.sid_lat])
  116. .setPopup(new mapboxgl.Popup({ offset: 25 })
  117. .setHTML('<img style="width: 70px;height: 60px;" src="http://localhost/ISR/public/sdppi.png" alt=""><br><div style="text-align: left;"><table class="table"><tbody><tr><td style="font-weight: bold">SITE ID</td><td>:</td><td>'+ site_id +'</td></tr><tr><td style="font-weight: bold">CLIENT ID</td><td>:</td><td>'+ result.clnt_id +'</td></tr><tr><td style="font-weight: bold">CLIENT NAME</td><td>:</td><td>'+ result.clnt_name +'</td></tr><tr><td style="font-weight: bold">CITY</td><td>:</td><td>'+ result.city +'</td></tr></tbody></table></div>'))
  118. .addTo(map);
  119. });
  120. if (data.length >= 1) {
  121. if (is_null >= 1) {
  122. $("#printSiteBtn").show();
  123. $("#sitePayload").val(val);
  124. }
  125. }
  126. geocoder.clear();
  127. var styleSpec = data.result;
  128. dragMarker.setLngLat(point).addTo(map);
  129. setCircleRadius(point);
  130. map.flyTo({
  131. center: point,
  132. zoom: 16,
  133. bearing: 0,
  134. speed: 1,
  135. curve: 1,
  136. essential: true
  137. });
  138. });
  139. });
  140. });
  141. });
  142. map.on('load', function() {
  143. geocoder.on('result', function(data) {
  144. $("#addSiteBtn").hide();
  145. $("#editSiteBtn").hide();
  146. $("div.mapboxgl-marker.mapboxgl-marker-anchor-center").remove();
  147. var point = data.result.center;
  148. var query = '{{URL::current()}}/radius/' + point[0] + '/' + point[1];
  149. $.ajax({
  150. method: 'GET',
  151. url: query,
  152. data: {
  153. "app_no": $('select#app_select').val(),
  154. "sims_no": $('select#sims_select').val(),
  155. "qrcode_id": $('select#qrcode_select').val()
  156. }
  157. }).done(function(data) {
  158. var is_null = 0;
  159. data.forEach(function(result) {
  160. if (result.site_id != null) {
  161. is_null++;
  162. var site_id = result.site_id;
  163. }else{
  164. var site_id = 'BELUM TERDAFTAR';
  165. }
  166. var marker = new mapboxgl.Marker({
  167. draggable: false,
  168. color: 'orange'
  169. })
  170. .setLngLat([result.sid_long, result.sid_lat])
  171. .setPopup(new mapboxgl.Popup({ offset: 25 })
  172. .setHTML('<img style="width: 70px;height: 60px;" src="http://localhost/ISR/public/sdppi.png" alt=""><br><div style="text-align: left;"><table class="table"><tbody><tr><td style="font-weight: bold">SITE ID</td><td>:</td><td>'+ site_id +'</td></tr><tr><td style="font-weight: bold">CLIENT ID</td><td>:</td><td>'+ result.clnt_id +'</td></tr><tr><td style="font-weight: bold">CLIENT NAME</td><td>:</td><td>'+ result.clnt_name +'</td></tr><tr><td style="font-weight: bold">CITY</td><td>:</td><td>'+ result.city +'</td></tr></tbody></table></div>'))
  173. .addTo(map);
  174. });
  175. if (data.length >= 1) {
  176. if (is_null >= 1) {
  177. $("#printSiteBtn").show();
  178. $("#editPayload").val(JSON.stringify(data));
  179. }
  180. }
  181. geocoder.clear();
  182. var styleSpec = data.result;
  183. dragMarker.setLngLat(point).addTo(map);
  184. setCircleRadius(point);
  185. })
  186. });
  187. });
  188. $("select#app_select").select2({
  189. theme: 'bootstrap4',
  190. allowClear: true,
  191. ajax: {
  192. url: '{{ url()->full() }}',
  193. data: function (params) {
  194. var query = {
  195. search: params.term,
  196. client_id: true
  197. }
  198. return query;
  199. }
  200. }
  201. });
  202. $("select#sims_select").select2({
  203. theme: 'bootstrap4',
  204. allowClear: true,
  205. ajax: {
  206. url: '{{ url()->full() }}',
  207. data: function (params) {
  208. var query = {
  209. search: params.term,
  210. client_name: true
  211. }
  212. return query;
  213. }
  214. }
  215. });
  216. $("select#qrcode_select").select2({
  217. theme: 'bootstrap4',
  218. allowClear: true,
  219. ajax: {
  220. url: '{{ url()->full() }}',
  221. data: function (params) {
  222. var query = {
  223. search: params.term,
  224. site_id: true
  225. }
  226. return query;
  227. }
  228. }
  229. });
  230. </script>