script.blade.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 onDragEnd() {
  17. var lngLat = dragMarker.getLngLat();
  18. $.confirm({
  19. title: 'Location',
  20. content: '<b>Longitude : </b> ' + lngLat.lng + '<br /><b>Latitude : </b>' + lngLat.lat,
  21. type: 'blue',
  22. icon: 'fa fa-compass',
  23. typeAnimated: true,
  24. buttons: {
  25. close: function () {
  26. }
  27. }
  28. });
  29. }
  30. dragMarker.on('dragend', onDragEnd);
  31. var geocoder = new MapboxGeocoder({
  32. accessToken: mapboxgl.accessToken,
  33. mapboxgl: mapboxgl,
  34. marker: {
  35. color: 'red'
  36. },
  37. zoom: 16,
  38. placeholder: "Enter an address or place name",
  39. });
  40. map.addControl(geocoder, 'top-left');
  41. var userLocation = new mapboxgl.GeolocateControl({
  42. positionOptions: {
  43. enableHighAccuracy: true,
  44. },
  45. fitBoundsOptions: {
  46. zoom: 18,
  47. },
  48. showAccuracyCircle: false,
  49. trackUserLocation: false,
  50. showUserLocation: true
  51. });
  52. map.addControl(userLocation);
  53. function setCircleRadius(point)
  54. {
  55. var mapLayer = map.getLayer('circle');
  56. if(typeof mapLayer !== 'undefined') {
  57. map.removeLayer('circle').removeSource('circle');
  58. }
  59. map.addSource("circle", {
  60. "type": "geojson",
  61. "data": {
  62. "type": "FeatureCollection",
  63. "features": [{
  64. "type": "Feature",
  65. "geometry": {
  66. "type": "Point",
  67. "coordinates": [point[0], point[1]]
  68. }
  69. }]
  70. }
  71. });
  72. const metersToPixelsAtMaxZoom = (meters, latitude) =>
  73. meters / 0.075 / Math.cos(latitude * Math.PI / 180)
  74. map.addLayer({
  75. "id": "circle",
  76. "type": "circle",
  77. "source": "circle",
  78. "paint": {
  79. "circle-radius": {
  80. stops: [
  81. [0, 0], [20, metersToPixelsAtMaxZoom(50, point[1])] ],
  82. base: 2
  83. },
  84. "circle-color": "lightblue",
  85. "circle-opacity": 0.6
  86. }
  87. });
  88. }
  89. function getDataSite(){
  90. var longtitude = $("#longtitudeInput").val();
  91. var latitude = $("#latitudeInput").val();
  92. if (longtitude && latitude) {
  93. var point = [longtitude, latitude];
  94. setCircleRadius(point);
  95. var query = '{{URL::current()}}/radius/' + longtitude + '/' + latitude;
  96. $.ajax({
  97. method: 'GET',
  98. url: query,
  99. }).done(function(data) {
  100. var is_null = 0;
  101. data.forEach(function(result) {
  102. if (result.site_id != null) {
  103. is_null++;
  104. var site_id = result.site_id;
  105. }else{
  106. var site_id = 'BELUM TERDAFTAR';
  107. }
  108. var markerSite = new mapboxgl.Marker({
  109. draggable: false,
  110. color: 'orange'
  111. })
  112. .setLngLat([result.sid_long, result.sid_lat])
  113. .setPopup(new mapboxgl.Popup({ offset: 25 })
  114. .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>'))
  115. .addTo(map);
  116. });
  117. });
  118. }else{
  119. $.confirm({
  120. title: 'Location',
  121. content: 'Empty Longitude & Latitude Input',
  122. type: 'red',
  123. icon: 'fa fa-compass',
  124. typeAnimated: true,
  125. buttons: {
  126. close: function () {
  127. }
  128. }
  129. });
  130. }
  131. }
  132. map.on('load', function() {
  133. userLocation.on('geolocate', function(geolocate) {
  134. $("#longtitudeInput").val(geolocate.coords.longitude);
  135. $("#latitudeInput").val(geolocate.coords.latitude);
  136. var point = [geolocate.coords.longitude, geolocate.coords.latitude];
  137. setCircleRadius(point);
  138. var markerLocation = new mapboxgl.Marker({
  139. draggable: true,
  140. color: 'green'
  141. })
  142. .setLngLat([$("#longtitudeInput").val(), $("#latitudeInput").val()])
  143. .addTo(map);
  144. function onDragEndLocation() {
  145. var location = markerLocation.getLngLat();
  146. $("#longtitudeInput").val(location.lng);
  147. $("#latitudeInput").val(location.lat);
  148. }
  149. markerLocation.on('drag', onDragEndLocation);
  150. });
  151. geocoder.on('result', function(data) {
  152. $("#addSiteBtn").hide();
  153. $("#editSiteBtn").hide();
  154. $("div.mapboxgl-marker.mapboxgl-marker-anchor-center").remove();
  155. var point = data.result.center;
  156. var query = '{{URL::current()}}/radius/' + point[0] + '/' + point[1];
  157. $.ajax({
  158. method: 'GET',
  159. url: query,
  160. }).done(function(data) {
  161. var is_null = 0;
  162. data.forEach(function(result) {
  163. if (result.site_id != null) {
  164. is_null++;
  165. var site_id = result.site_id;
  166. }else{
  167. var site_id = 'BELUM TERDAFTAR';
  168. }
  169. var marker = new mapboxgl.Marker({
  170. draggable: false,
  171. color: 'orange'
  172. })
  173. .setLngLat([result.sid_long, result.sid_lat])
  174. .setPopup(new mapboxgl.Popup({ offset: 25 })
  175. .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>'))
  176. .addTo(map);
  177. });
  178. if (data.length >= 1) {
  179. if (is_null >= 1) {
  180. $("#editSiteBtn").show();
  181. $("#editPayload").val(JSON.stringify(data));
  182. }
  183. else {
  184. $("#addSiteBtn").show();
  185. $("#createPayload").val(JSON.stringify(data));
  186. }
  187. }
  188. geocoder.clear();
  189. var styleSpec = data.result;
  190. dragMarker.setLngLat(point).addTo(map);
  191. })
  192. });
  193. });
  194. $("select").select2({
  195. theme: 'bootstrap4',
  196. });
  197. </script>