Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Logistic Fleet
  3. */
  4. ('use strict');
  5. (function () {
  6. // Mapbox Access Token
  7. //!YOUR_MAPBOX_ACCESS_TOKEN_HERE!
  8. mapboxgl.accessToken =
  9. '';
  10. const geojson = {
  11. type: 'FeatureCollection',
  12. features: [
  13. {
  14. type: 'Feature',
  15. properties: {
  16. iconSize: [20, 42],
  17. message: '1'
  18. },
  19. geometry: {
  20. type: 'Point',
  21. coordinates: [-73.999024, 40.75249842]
  22. }
  23. },
  24. {
  25. type: 'Feature',
  26. properties: {
  27. iconSize: [20, 42],
  28. message: '2'
  29. },
  30. geometry: {
  31. type: 'Point',
  32. coordinates: [-74.03, 40.75699842]
  33. }
  34. },
  35. {
  36. type: 'Feature',
  37. properties: {
  38. iconSize: [20, 42],
  39. message: '3'
  40. },
  41. geometry: {
  42. type: 'Point',
  43. coordinates: [-73.967524, 40.7599842]
  44. }
  45. },
  46. {
  47. type: 'Feature',
  48. properties: {
  49. iconSize: [20, 42],
  50. message: '4'
  51. },
  52. geometry: {
  53. type: 'Point',
  54. coordinates: [-74.0325, 40.742992]
  55. }
  56. }
  57. ]
  58. };
  59. const map = new mapboxgl.Map({
  60. container: 'map',
  61. // Choose from Mapbox's core styles, or make your own style with Mapbox Studio
  62. style: 'mapbox://styles/mapbox/light-v9',
  63. center: [-73.999024, 40.75249842],
  64. zoom: 12.25
  65. });
  66. // Add markers to the map and thier functionality
  67. for (const marker of geojson.features) {
  68. // Create a DOM element for each marker.
  69. const el = document.createElement('div');
  70. const width = marker.properties.iconSize[0];
  71. const height = marker.properties.iconSize[1];
  72. el.className = 'marker';
  73. el.insertAdjacentHTML(
  74. 'afterbegin',
  75. '<img src="' +
  76. assetsPath +
  77. 'img/illustrations/fleet-car.png" alt="Fleet Car" width="20" class="rounded-3" id="carFleet-' +
  78. marker.properties.message +
  79. '">'
  80. );
  81. el.style.width = `${width}px`;
  82. el.style.height = `${height}px`;
  83. el.style.cursor = 'pointer';
  84. // Add markers to the map.
  85. new mapboxgl.Marker(el).setLngLat(marker.geometry.coordinates).addTo(map);
  86. // Select Accordion for respective Marker
  87. const element = document.getElementById('fl-' + marker.properties.message);
  88. // Select Car for respective Marker
  89. const car = document.getElementById('carFleet-' + marker.properties.message);
  90. element.addEventListener('click', function () {
  91. const focusedElement = document.querySelector('.marker-focus');
  92. if (Helpers._hasClass('active', element)) {
  93. //fly to location
  94. map.flyTo({
  95. center: geojson.features[marker.properties.message - 1].geometry.coordinates,
  96. zoom: 16
  97. });
  98. // Remove marker-focus from other marked cars
  99. focusedElement && Helpers._removeClass('marker-focus', focusedElement);
  100. Helpers._addClass('marker-focus', car);
  101. } else {
  102. //remove marker-focus if not active
  103. Helpers._removeClass('marker-focus', car);
  104. }
  105. });
  106. }
  107. //For selecting default car location
  108. const defCar = document.getElementById('carFleet-1');
  109. Helpers._addClass('marker-focus', defCar);
  110. //hide mapbox controls
  111. document.querySelector('.mapboxgl-control-container').classList.add('d-none');
  112. //Selecting Sidebar Accordion for perfect scroll
  113. var sidebarAccordionBody = $('.logistics-fleet-sidebar-body');
  114. //Perfect Scrollbar for Sidebar Accordion
  115. if (sidebarAccordionBody.length) {
  116. new PerfectScrollbar(sidebarAccordionBody[0], {
  117. wheelPropagation: false,
  118. suppressScrollX: true
  119. });
  120. }
  121. })();