app.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. let currentPage = 2;
  3. const tabs = document.getElementsByClassName('page');
  4. const conditions = {
  5. agreement: [
  6. () => {
  7. const agreementCheckbox = document.getElementById('agreement');
  8. if (agreementCheckbox.checked) {
  9. return true;
  10. } else {
  11. const form = document.getElementById('terms-and-conditions-form');
  12. form.classList.add('was-validated');
  13. return false;
  14. }
  15. }
  16. ]
  17. }
  18. const showCustomInput = (customElementId, element) => {
  19. if (element.value === 'other') {
  20. const customInput = document.getElementById(customElementId);
  21. customInput.style.display = 'block'
  22. }
  23. }
  24. const showPage = (page) => {
  25. tabs[page].style.display = 'block';
  26. }
  27. const isValid = condition => condition();
  28. const changePage = (page, condition) => {
  29. if (condition && !conditions[condition].every(isValid)) {
  30. console.log("not all conditions passed");
  31. return;
  32. }
  33. tabs[currentPage].style.display = 'none';
  34. showPage(page);
  35. currentPage = page;
  36. }
  37. showPage(2);
  38. mapboxgl.accessToken = 'pk.eyJ1IjoidGluYW1hIiwiYSI6ImNpbWV2dDJudjAxM2Z0c2traGthOTJyZjYifQ.s_lP9rp2Iro7Urb4IZAzTQ';
  39. const bounds = [
  40. [-2.460270, 53.370427],
  41. [-2.062598, 53.552900]
  42. ]
  43. const map = new mapboxgl.Map({
  44. container: 'map',
  45. style: 'mapbox://styles/tinama/ck7avipta06nj1jmomolvvrbr',
  46. center: [-2.884808, 53.495743],
  47. zoom: 9.5,
  48. });
  49. const Draw = new MapboxDraw({
  50. displayControlsDefault: false,
  51. controls: {
  52. polygon: true,
  53. trash: true
  54. }
  55. });
  56. console.log("turf", turf);
  57. const AddPopup = (map) => (area) => {
  58. let polygon = turf.polygon(area);
  59. let center = turf.centroid(polygon);
  60. console.log(center, polygon)
  61. return new mapboxgl.Popup({closeOnClick: false})
  62. .setLngLat(center.geometry.coordinates)
  63. .setHTML(`
  64. <h3>form</h3>
  65. <label for="data">some data</label>
  66. <input type="text" class="form-control" id="data" placeholder="" required>
  67. <button type="button">save</button>
  68. `)
  69. .addTo(map)
  70. }
  71. map.addControl(Draw, 'top-right');
  72. map.on('load', function() {
  73. let drawnData = {};
  74. map.on('draw.create', createArea);
  75. map.on('draw.delete', deleteArea);
  76. map.on('draw.update', updateArea);
  77. function createArea(polygon) {
  78. let area = polygon.features[0].geometry;
  79. drawnData = {
  80. ...drawnData,
  81. [polygon.features[0].id]: area
  82. };
  83. console.log("create", area);
  84. const popup = AddPopup(map)(area.coordinates);
  85. }
  86. function deleteArea(polygon) {
  87. console.log('delete', polygon);
  88. }
  89. function updateArea(polygon) {
  90. console.log('update', polygon)
  91. }
  92. });