@bpd-library/components 1.2.3-beta.4 → 1.2.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/dist/esm/atoms/button/button.js +33 -0
  2. package/dist/esm/atoms/button/button.js.map +1 -0
  3. package/dist/esm/atoms/col/col.js +22 -0
  4. package/dist/esm/atoms/col/col.js.map +1 -0
  5. package/dist/esm/atoms/container/container.js +6 -0
  6. package/dist/esm/atoms/container/container.js.map +1 -0
  7. package/dist/esm/atoms/form-elements/range-slider/range-slider.js +21 -0
  8. package/dist/esm/atoms/form-elements/range-slider/range-slider.js.map +1 -0
  9. package/dist/esm/atoms/form-elements/utilities/range-slider.js +100 -0
  10. package/dist/esm/atoms/form-elements/utilities/range-slider.js.map +1 -0
  11. package/dist/esm/atoms/image/image.js +18 -0
  12. package/dist/esm/atoms/image/image.js.map +1 -0
  13. package/dist/esm/atoms/image/utilities/create-image-url.js +15 -0
  14. package/dist/esm/atoms/image/utilities/create-image-url.js.map +1 -0
  15. package/dist/esm/atoms/row/row.js +6 -0
  16. package/dist/esm/atoms/row/row.js.map +1 -0
  17. package/dist/esm/atoms/svg/svg.js +25 -0
  18. package/dist/esm/atoms/svg/svg.js.map +1 -0
  19. package/dist/esm/index.js +14 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/molecules/infobox/infobox.js +20 -0
  22. package/dist/esm/molecules/infobox/infobox.js.map +1 -0
  23. package/dist/esm/molecules/map/map.js +256 -0
  24. package/dist/esm/molecules/map/map.js.map +1 -0
  25. package/dist/esm/molecules/map/store/map/store.js +150 -0
  26. package/dist/esm/molecules/map/store/map/store.js.map +1 -0
  27. package/dist/esm/molecules/map/utilities/fit-bounds.js +4 -0
  28. package/dist/esm/molecules/map/utilities/fit-bounds.js.map +1 -0
  29. package/dist/esm/molecules/map/utilities/mapbox/add-data.js +54 -0
  30. package/dist/esm/molecules/map/utilities/mapbox/add-data.js.map +1 -0
  31. package/dist/esm/molecules/map/utilities/mapbox/center.js +15 -0
  32. package/dist/esm/molecules/map/utilities/mapbox/center.js.map +1 -0
  33. package/dist/esm/molecules/map/utilities/mapbox/constants.js +5 -0
  34. package/dist/esm/molecules/map/utilities/mapbox/constants.js.map +1 -0
  35. package/dist/esm/molecules/map/utilities/mapbox/index.js +3 -0
  36. package/dist/esm/molecules/map/utilities/mapbox/index.js.map +1 -0
  37. package/dist/esm/molecules/map/utilities/mapbox/mapbox.js +27 -0
  38. package/dist/esm/molecules/map/utilities/mapbox/mapbox.js.map +1 -0
  39. package/dist/esm/molecules/map/utilities/mapbox/parse-feature-properties.js +18 -0
  40. package/dist/esm/molecules/map/utilities/mapbox/parse-feature-properties.js.map +1 -0
  41. package/dist/esm/molecules/map/utilities/mapbox/pointers/setup-pointers.js +151 -0
  42. package/dist/esm/molecules/map/utilities/mapbox/pointers/setup-pointers.js.map +1 -0
  43. package/dist/esm/molecules/map/utilities/mapbox/polygons/feature-state.js +11 -0
  44. package/dist/esm/molecules/map/utilities/mapbox/polygons/feature-state.js.map +1 -0
  45. package/dist/esm/molecules/map/utilities/mapbox/polygons/geojson.js +10 -0
  46. package/dist/esm/molecules/map/utilities/mapbox/polygons/geojson.js.map +1 -0
  47. package/dist/esm/molecules/map/utilities/mapbox/polygons/interaction.js +34 -0
  48. package/dist/esm/molecules/map/utilities/mapbox/polygons/interaction.js.map +1 -0
  49. package/dist/esm/molecules/map/utilities/mapbox/polygons/layer.js +110 -0
  50. package/dist/esm/molecules/map/utilities/mapbox/polygons/layer.js.map +1 -0
  51. package/dist/esm/molecules/map/utilities/mapbox/raster.js +43 -0
  52. package/dist/esm/molecules/map/utilities/mapbox/raster.js.map +1 -0
  53. package/dist/esm/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js +27 -0
  54. package/dist/esm/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js.map +1 -0
  55. package/dist/esm/molecules/map/utilities/mapbox/search/search.js +174 -0
  56. package/dist/esm/molecules/map/utilities/mapbox/search/search.js.map +1 -0
  57. package/dist/esm/molecules/map/utilities/mapbox/tooltip.js +26 -0
  58. package/dist/esm/molecules/map/utilities/mapbox/tooltip.js.map +1 -0
  59. package/dist/esm/molecules/tooltip/tooltip.js +14 -0
  60. package/dist/esm/molecules/tooltip/tooltip.js.map +1 -0
  61. package/dist/esm/node_modules/tslib/tslib.es6.js +24 -0
  62. package/dist/esm/node_modules/tslib/tslib.es6.js.map +1 -0
  63. package/dist/lib/atoms/button/button.js +31 -0
  64. package/dist/lib/atoms/button/button.js.map +1 -0
  65. package/dist/lib/atoms/button/index.js +2 -0
  66. package/dist/lib/atoms/button/index.js.map +1 -0
  67. package/dist/lib/atoms/col/col.js +19 -0
  68. package/dist/lib/atoms/col/col.js.map +1 -0
  69. package/dist/lib/atoms/container/container.js +3 -0
  70. package/dist/lib/atoms/container/container.js.map +1 -0
  71. package/dist/lib/atoms/form-elements/range-slider/range-slider.js +18 -0
  72. package/dist/lib/atoms/form-elements/range-slider/range-slider.js.map +1 -0
  73. package/dist/lib/atoms/form-elements/utilities/range-slider.js +97 -0
  74. package/dist/lib/atoms/form-elements/utilities/range-slider.js.map +1 -0
  75. package/dist/lib/atoms/image/image.js +15 -0
  76. package/dist/lib/atoms/image/image.js.map +1 -0
  77. package/dist/lib/atoms/image/index.js +2 -0
  78. package/dist/lib/atoms/image/index.js.map +1 -0
  79. package/dist/lib/atoms/image/utilities/create-image-url.js +14 -0
  80. package/dist/lib/atoms/image/utilities/create-image-url.js.map +1 -0
  81. package/dist/lib/atoms/image/utilities/detect-responsive-images.js +24 -0
  82. package/dist/lib/atoms/image/utilities/detect-responsive-images.js.map +1 -0
  83. package/dist/lib/atoms/image/utilities/image.js +86 -0
  84. package/dist/lib/atoms/image/utilities/image.js.map +1 -0
  85. package/dist/lib/atoms/image/utilities/object-fit.js +35 -0
  86. package/dist/lib/atoms/image/utilities/object-fit.js.map +1 -0
  87. package/dist/lib/atoms/row/row.js +3 -0
  88. package/dist/lib/atoms/row/row.js.map +1 -0
  89. package/dist/lib/atoms/svg/svg.js +23 -0
  90. package/dist/lib/atoms/svg/svg.js.map +1 -0
  91. package/dist/lib/index.js +12 -0
  92. package/dist/lib/index.js.map +1 -0
  93. package/dist/lib/molecules/infobox/index.js +2 -0
  94. package/dist/lib/molecules/infobox/index.js.map +1 -0
  95. package/dist/lib/molecules/infobox/infobox.js +17 -0
  96. package/dist/lib/molecules/infobox/infobox.js.map +1 -0
  97. package/dist/lib/molecules/map/hooks/use-style-loaded.js +14 -0
  98. package/dist/lib/molecules/map/hooks/use-style-loaded.js.map +1 -0
  99. package/dist/lib/molecules/map/index.js +4 -0
  100. package/dist/lib/molecules/map/index.js.map +1 -0
  101. package/dist/lib/molecules/map/map.js +256 -0
  102. package/dist/lib/molecules/map/map.js.map +1 -0
  103. package/dist/lib/molecules/map/store/map/index.js +2 -0
  104. package/dist/lib/molecules/map/store/map/index.js.map +1 -0
  105. package/dist/lib/molecules/map/store/map/store.js +147 -0
  106. package/dist/lib/molecules/map/store/map/store.js.map +1 -0
  107. package/dist/lib/molecules/map/storybook/themes.js +54 -0
  108. package/dist/lib/molecules/map/storybook/themes.js.map +1 -0
  109. package/dist/lib/molecules/map/utilities/fit-bounds.js +2 -0
  110. package/dist/lib/molecules/map/utilities/fit-bounds.js.map +1 -0
  111. package/dist/lib/molecules/map/utilities/mapbox/add-data.js +52 -0
  112. package/dist/lib/molecules/map/utilities/mapbox/add-data.js.map +1 -0
  113. package/dist/lib/molecules/map/utilities/mapbox/center.js +13 -0
  114. package/dist/lib/molecules/map/utilities/mapbox/center.js.map +1 -0
  115. package/dist/lib/molecules/map/utilities/mapbox/constants.js +3 -0
  116. package/dist/lib/molecules/map/utilities/mapbox/constants.js.map +1 -0
  117. package/dist/lib/molecules/map/utilities/mapbox/index.js +3 -0
  118. package/dist/lib/molecules/map/utilities/mapbox/index.js.map +1 -0
  119. package/dist/lib/molecules/map/utilities/mapbox/mapbox.js +25 -0
  120. package/dist/lib/molecules/map/utilities/mapbox/mapbox.js.map +1 -0
  121. package/dist/lib/molecules/map/utilities/mapbox/parse-feature-properties.js +16 -0
  122. package/dist/lib/molecules/map/utilities/mapbox/parse-feature-properties.js.map +1 -0
  123. package/dist/lib/molecules/map/utilities/mapbox/pointers/setup-pointers.js +151 -0
  124. package/dist/lib/molecules/map/utilities/mapbox/pointers/setup-pointers.js.map +1 -0
  125. package/dist/lib/molecules/map/utilities/mapbox/polygons/feature-state.js +10 -0
  126. package/dist/lib/molecules/map/utilities/mapbox/polygons/feature-state.js.map +1 -0
  127. package/dist/lib/molecules/map/utilities/mapbox/polygons/geojson.js +9 -0
  128. package/dist/lib/molecules/map/utilities/mapbox/polygons/geojson.js.map +1 -0
  129. package/dist/lib/molecules/map/utilities/mapbox/polygons/interaction.js +32 -0
  130. package/dist/lib/molecules/map/utilities/mapbox/polygons/interaction.js.map +1 -0
  131. package/dist/lib/molecules/map/utilities/mapbox/polygons/layer.js +109 -0
  132. package/dist/lib/molecules/map/utilities/mapbox/polygons/layer.js.map +1 -0
  133. package/dist/lib/molecules/map/utilities/mapbox/raster.js +42 -0
  134. package/dist/lib/molecules/map/utilities/mapbox/raster.js.map +1 -0
  135. package/dist/lib/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js +26 -0
  136. package/dist/lib/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js.map +1 -0
  137. package/dist/lib/molecules/map/utilities/mapbox/search/search.js +172 -0
  138. package/dist/lib/molecules/map/utilities/mapbox/search/search.js.map +1 -0
  139. package/dist/lib/molecules/map/utilities/mapbox/tooltip.js +24 -0
  140. package/dist/lib/molecules/map/utilities/mapbox/tooltip.js.map +1 -0
  141. package/dist/lib/molecules/tooltip/index.js +2 -0
  142. package/dist/lib/molecules/tooltip/index.js.map +1 -0
  143. package/dist/lib/molecules/tooltip/tooltip.js +11 -0
  144. package/dist/lib/molecules/tooltip/tooltip.js.map +1 -0
  145. package/dist/molecules/map/map.js +7 -3
  146. package/dist/molecules/map/map.js.map +1 -1
  147. package/dist/molecules/map/store/map/store.d.ts +1 -0
  148. package/dist/molecules/map/store/map/store.js +8 -0
  149. package/dist/molecules/map/store/map/store.js.map +1 -1
  150. package/dist/molecules/map/utilities/mapbox/add-data.d.ts +3 -2
  151. package/dist/molecules/map/utilities/mapbox/add-data.js +37 -5
  152. package/dist/molecules/map/utilities/mapbox/add-data.js.map +1 -1
  153. package/dist/molecules/map/utilities/mapbox/directions/directions.d.ts +5 -0
  154. package/dist/molecules/map/utilities/mapbox/directions/directions.js +78 -0
  155. package/dist/molecules/map/utilities/mapbox/directions/directions.js.map +1 -0
  156. package/dist/molecules/map/utilities/mapbox/isochrone.d.ts +3 -2
  157. package/dist/molecules/map/utilities/mapbox/isochrone.js +108 -40
  158. package/dist/molecules/map/utilities/mapbox/isochrone.js.map +1 -1
  159. package/dist/molecules/map/utilities/mapbox/mapbox.d.ts +2 -1
  160. package/dist/molecules/map/utilities/mapbox/mapbox.js +4 -3
  161. package/dist/molecules/map/utilities/mapbox/mapbox.js.map +1 -1
  162. package/dist/molecules/map/utilities/mapbox/search/search.d.ts +1 -1
  163. package/dist/molecules/map/utilities/mapbox/search/search.js +3 -2
  164. package/dist/molecules/map/utilities/mapbox/search/search.js.map +1 -1
  165. package/dist/types/atoms/button/button.d.ts +17 -0
  166. package/dist/types/atoms/button/index.d.ts +1 -0
  167. package/dist/types/atoms/col/col.d.ts +11 -0
  168. package/dist/types/atoms/container/container.d.ts +6 -0
  169. package/dist/types/atoms/form-elements/range-slider/range-slider.d.ts +11 -0
  170. package/dist/types/atoms/form-elements/utilities/range-slider.d.ts +7 -0
  171. package/dist/types/atoms/image/image.d.ts +14 -0
  172. package/dist/types/atoms/image/index.d.ts +1 -0
  173. package/dist/types/atoms/image/utilities/create-image-url.d.ts +6 -0
  174. package/dist/types/atoms/image/utilities/detect-responsive-images.d.ts +7 -0
  175. package/dist/types/atoms/image/utilities/image.d.ts +18 -0
  176. package/dist/types/atoms/image/utilities/object-fit.d.ts +7 -0
  177. package/dist/types/atoms/row/row.d.ts +6 -0
  178. package/dist/types/atoms/svg/svg.d.ts +4 -0
  179. package/dist/types/index.d.ts +11 -0
  180. package/dist/types/molecules/infobox/index.d.ts +1 -0
  181. package/dist/types/molecules/infobox/infobox.d.ts +7 -0
  182. package/dist/types/molecules/map/hooks/use-style-loaded.d.ts +2 -0
  183. package/dist/types/molecules/map/index.d.ts +3 -0
  184. package/dist/types/molecules/map/map.d.ts +2 -0
  185. package/dist/types/molecules/map/store/map/index.d.ts +1 -0
  186. package/dist/types/molecules/map/store/map/store.d.ts +60 -0
  187. package/dist/types/molecules/map/storybook/themes.d.ts +3 -0
  188. package/dist/types/molecules/map/utilities/fit-bounds.d.ts +3 -0
  189. package/dist/types/molecules/map/utilities/mapbox/add-data.d.ts +3 -0
  190. package/dist/types/molecules/map/utilities/mapbox/center.d.ts +3 -0
  191. package/dist/types/molecules/map/utilities/mapbox/constants.d.ts +2 -0
  192. package/dist/types/molecules/map/utilities/mapbox/index.d.ts +2 -0
  193. package/dist/types/molecules/map/utilities/mapbox/mapbox.d.ts +16 -0
  194. package/dist/types/molecules/map/utilities/mapbox/parse-feature-properties.d.ts +6 -0
  195. package/dist/types/molecules/map/utilities/mapbox/pointers/setup-pointers.d.ts +3 -0
  196. package/dist/types/molecules/map/utilities/mapbox/polygons/feature-state.d.ts +2 -0
  197. package/dist/types/molecules/map/utilities/mapbox/polygons/geojson.d.ts +3 -0
  198. package/dist/types/molecules/map/utilities/mapbox/polygons/interaction.d.ts +3 -0
  199. package/dist/types/molecules/map/utilities/mapbox/polygons/layer.d.ts +3 -0
  200. package/dist/types/molecules/map/utilities/mapbox/raster.d.ts +3 -0
  201. package/dist/types/molecules/map/utilities/mapbox/search/alternative-city-suggestions.d.ts +3 -0
  202. package/dist/types/molecules/map/utilities/mapbox/search/search.d.ts +4 -0
  203. package/dist/types/molecules/map/utilities/mapbox/tooltip.d.ts +4 -0
  204. package/dist/types/molecules/tooltip/index.d.ts +1 -0
  205. package/dist/types/molecules/tooltip/tooltip.d.ts +7 -0
  206. package/package.json +7 -4
  207. package/coverage/base.css +0 -224
  208. package/coverage/block-navigation.js +0 -79
  209. package/coverage/index.html +0 -95
  210. package/coverage/lcov.info +0 -0
  211. package/coverage/prettify.css +0 -1
  212. package/coverage/prettify.js +0 -2
  213. package/coverage/sort-arrow-sprite.png +0 -0
  214. package/coverage/sorter.js +0 -170
@@ -0,0 +1,78 @@
1
+ import { environment } from '@bpd-library/utilities';
2
+ import { Popup } from 'mapbox-gl';
3
+ const DIRECTIONS_SOURCE = 'directions';
4
+ let startPopup = null;
5
+ let endPopup = null;
6
+ let durationPopup = null;
7
+ const addDirections = async (map, directionsOptions) => {
8
+ if (!map.getSource(DIRECTIONS_SOURCE)) {
9
+ setupSource(map);
10
+ setupLayer(map);
11
+ }
12
+ const { profile, start, end } = directionsOptions;
13
+ const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;
14
+ try {
15
+ const url = `https://api.mapbox.com/directions/v5/mapbox/${profile}/${start[0]},${start[1]};${end[0]},${end[1]}?overview=full&geometries=geojson&access_token=${accessToken}`;
16
+ const { routes: [route], } = (await fetch(url).then((r) => r.json()));
17
+ if (route) {
18
+ const source = map.getSource(DIRECTIONS_SOURCE);
19
+ source === null || source === void 0 ? void 0 : source.setData({
20
+ type: 'FeatureCollection',
21
+ features: [
22
+ {
23
+ type: 'Feature',
24
+ geometry: route.geometry,
25
+ properties: null,
26
+ },
27
+ ],
28
+ });
29
+ const middlePoint = route.geometry.coordinates[route.geometry.coordinates.length / 2];
30
+ startPopup = addPopup(map, start, directionsOptions.startLabel());
31
+ endPopup = addPopup(map, end, directionsOptions.endLabel());
32
+ durationPopup = addPopup(map, middlePoint, directionsOptions.durationLabel(route.duration));
33
+ }
34
+ }
35
+ catch (e) {
36
+ if (environment.isLocal) {
37
+ console.error(e);
38
+ }
39
+ }
40
+ };
41
+ function removeDirections(map) {
42
+ const source = map.getSource(DIRECTIONS_SOURCE);
43
+ if (!source)
44
+ return;
45
+ source.setData({
46
+ type: 'FeatureCollection',
47
+ features: [],
48
+ });
49
+ startPopup && startPopup.remove();
50
+ endPopup && endPopup.remove();
51
+ durationPopup && durationPopup.remove();
52
+ }
53
+ function setupSource(map) {
54
+ map.addSource(DIRECTIONS_SOURCE, {
55
+ type: 'geojson',
56
+ data: {
57
+ type: 'FeatureCollection',
58
+ features: [],
59
+ },
60
+ });
61
+ }
62
+ function setupLayer(map, linePaintOptions) {
63
+ map.addLayer({
64
+ id: 'directionsStroke',
65
+ type: 'line',
66
+ source: DIRECTIONS_SOURCE,
67
+ layout: {},
68
+ paint: Object.assign({ 'line-color': '#32C1DE', 'line-width': 4 }, linePaintOptions),
69
+ });
70
+ }
71
+ function addPopup(map, location, labelNode, options) {
72
+ return new Popup(Object.assign({ closeButton: false, closeOnClick: false, offset: 5 }, options))
73
+ .setLngLat(location)
74
+ .setDOMContent(labelNode)
75
+ .addTo(map);
76
+ }
77
+ export { addDirections, removeDirections };
78
+ //# sourceMappingURL=directions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directions.js","sourceRoot":"","sources":["../../../../../../src/molecules/map/utilities/mapbox/directions/directions.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAiB,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAc5C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAEvC,IAAI,UAAU,GAAiB,IAAI,CAAC;AACpC,IAAI,QAAQ,GAAiB,IAAI,CAAC;AAClC,IAAI,aAAa,GAAiB,IAAI,CAAC;AAEvC,MAAM,aAAa,GAAG,KAAK,EAAE,GAAiB,EAAE,iBAAuC,EAAE,EAAE;IAIvF,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE;QACnC,WAAW,CAAC,GAAG,CAAC,CAAC;QACjB,UAAU,CAAC,GAAG,CAAC,CAAC;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E,KAAK,EACnB,MAAM,EAAE,CAAC,IACN,OAAO,EACZ;SACG,SAAS,CAAC,QAAQ,CAAC;SACnB,aAAa,CAAC,SAAS,CAAC;SACxB,KAAK,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// import { h } from '@atomify/jsx';\nimport { Coordinate, MapDirectionsSetting } from '@bpd-library/types';\nimport { environment } from '@bpd-library/utilities';\nimport mapboxgl, { Popup } from 'mapbox-gl';\n\n// import { fitBounds } from '../../fit-bounds';\n\ninterface DirectionsAPIResult {\n routes: DirectionsAPIRoute[];\n}\n\ninterface DirectionsAPIRoute {\n duration: number;\n distance: number;\n geometry: GeoJSON.LineString;\n}\n\nconst DIRECTIONS_SOURCE = 'directions';\n\nlet startPopup: Popup | null = null;\nlet endPopup: Popup | null = null;\nlet durationPopup: Popup | null = null;\n\nconst addDirections = async (map: mapboxgl.Map, directionsOptions: MapDirectionsSetting) => {\n // const bounds = getCountryBoundingBox(['nl']);\n\n // Setup source and layer, if not existing\n if (!map.getSource(DIRECTIONS_SOURCE)) {\n setupSource(map);\n setupLayer(map);\n }\n\n const { profile, start, end } = directionsOptions;\n\n const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;\n\n try {\n const url = `https://api.mapbox.com/directions/v5/mapbox/${profile}/${start[0]},${start[1]};${end[0]},${end[1]}?overview=full&geometries=geojson&access_token=${accessToken}`;\n const {\n routes: [route],\n } = (await fetch(url).then((r) => r.json())) as DirectionsAPIResult;\n\n if (route) {\n const source = map.getSource(DIRECTIONS_SOURCE) as mapboxgl.GeoJSONSource | undefined;\n source?.setData({\n type: 'FeatureCollection',\n features: [\n {\n type: 'Feature',\n geometry: route.geometry,\n properties: null,\n },\n ],\n });\n\n const middlePoint = route.geometry.coordinates[\n route.geometry.coordinates.length / 2\n ] as Coordinate;\n\n startPopup = addPopup(map, start, directionsOptions.startLabel());\n endPopup = addPopup(map, end, directionsOptions.endLabel());\n durationPopup = addPopup(\n map,\n middlePoint,\n directionsOptions.durationLabel(route.duration),\n );\n }\n } catch (e) {\n if (environment.isLocal) {\n console.error(e);\n }\n }\n // function handleFitBounds() {\n // return fitBounds(map, bounds);\n // }\n};\n\nfunction removeDirections(map: mapboxgl.Map) {\n const source = map.getSource(DIRECTIONS_SOURCE) as mapboxgl.GeoJSONSource | undefined;\n\n if (!source) return;\n\n source.setData({\n type: 'FeatureCollection',\n features: [],\n });\n\n startPopup && startPopup.remove();\n endPopup && endPopup.remove();\n durationPopup && durationPopup.remove();\n}\n\nfunction setupSource(map: mapboxgl.Map) {\n map.addSource(DIRECTIONS_SOURCE, {\n type: 'geojson',\n data: {\n type: 'FeatureCollection',\n features: [],\n },\n });\n}\n\nfunction setupLayer(map: mapboxgl.Map, linePaintOptions?: Partial<mapboxgl.LinePaint>) {\n map.addLayer({\n id: 'directionsStroke',\n type: 'line',\n source: DIRECTIONS_SOURCE,\n layout: {},\n paint: {\n 'line-color': '#32C1DE',\n 'line-width': 4,\n ...linePaintOptions,\n },\n });\n}\n\nfunction addPopup(\n map: mapboxgl.Map,\n location: Coordinate,\n labelNode: Node,\n options?: mapboxgl.PopupOptions,\n) {\n return new Popup({\n closeButton: false,\n closeOnClick: false,\n offset: 5,\n ...options,\n })\n .setLngLat(location)\n .setDOMContent(labelNode)\n .addTo(map);\n}\n\nexport { addDirections, removeDirections };\n"]}
@@ -1,4 +1,5 @@
1
1
  import { MapIsochroneSetting } from '@bpd-library/types';
2
2
  import mapboxgl from 'mapbox-gl';
3
- declare const isochrone: (map: mapboxgl.Map, isochroneSetting: MapIsochroneSetting) => Promise<void>;
4
- export default isochrone;
3
+ declare const addIsochrone: (map: mapboxgl.Map, isochroneSetting: MapIsochroneSetting) => Promise<void>;
4
+ declare const removeIsochrone: (map: mapboxgl.Map) => void;
5
+ export { addIsochrone, removeIsochrone };
@@ -1,46 +1,114 @@
1
- import { environment } from '@bpd-library/utilities';
2
- const isochrone = async (map, isochroneSetting) => {
3
- if (!map.getSource('isochrone')) {
4
- setupSource(map);
5
- setupLayer(map);
6
- }
7
- const { coordinate, minutes, profile } = isochroneSetting;
8
- const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;
9
- try {
10
- const url = `https://api.mapbox.com/isochrone/v1/mapbox/${profile}/${coordinate[0]},${coordinate[1]}?contours_minutes=${minutes}&polygons=true&access_token=${accessToken}`;
11
- const result = await fetch(url);
12
- const parsedResult = await result.json();
13
- if (parsedResult) {
14
- const source = map.getSource('isochrone');
15
- source === null || source === void 0 ? void 0 : source.setData(parsedResult);
1
+ import { calculateBoundingBox, environment } from '@bpd-library/utilities';
2
+ const OUTER_COORDINATES = [
3
+ [
4
+ [-42, 74],
5
+ [-42, 1],
6
+ [80, 1],
7
+ [80, 74],
8
+ [-42, 74],
9
+ ],
10
+ ];
11
+ const ISOCHRONE_SOURCE = 'isochrone';
12
+ const DEFAULT_FILL_COLOR = '#000000';
13
+ const DEFAULT_STROKE_COLOR = '#32C1DE';
14
+ let mask;
15
+ let polygon;
16
+ const addIsochrone = async (map, isochroneSetting) => {
17
+ await init();
18
+ async function init() {
19
+ if (!mask || !polygon) {
20
+ const maskPackage = await import('@turf/mask');
21
+ const helpersPackage = await import('@turf/helpers');
22
+ mask = await maskPackage.default;
23
+ polygon = await helpersPackage.polygon;
16
24
  }
17
- }
18
- catch (e) {
19
- if (environment.isLocal) {
20
- console.error(e);
25
+ if (!map.getSource(ISOCHRONE_SOURCE)) {
26
+ setupSource();
27
+ setupLayer();
28
+ }
29
+ const { coordinate, minutes, profile, fitBounds } = isochroneSetting;
30
+ const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;
31
+ try {
32
+ let url = `https://api.mapbox.com/isochrone/v1/mapbox/${profile}/${coordinate[0]},${coordinate[1]}?contours_minutes=${minutes}&polygons=true&access_token=${accessToken}`;
33
+ if (profile === 'driving') {
34
+ url += '&generalize=100';
35
+ }
36
+ const result = await fetch(url);
37
+ const parsedResult = await result.json();
38
+ if (parsedResult) {
39
+ const source = map.getSource(ISOCHRONE_SOURCE);
40
+ const invertedCoordinates = invertCoordinates(parsedResult);
41
+ if (fitBounds) {
42
+ fitApiResultBounds(parsedResult);
43
+ }
44
+ source === null || source === void 0 ? void 0 : source.setData(invertedCoordinates);
45
+ }
21
46
  }
47
+ catch (e) {
48
+ if (environment.isLocal) {
49
+ console.error(e);
50
+ }
51
+ }
52
+ }
53
+ function setupSource() {
54
+ map.addSource(ISOCHRONE_SOURCE, {
55
+ type: 'geojson',
56
+ data: {
57
+ type: 'FeatureCollection',
58
+ features: [],
59
+ },
60
+ });
61
+ }
62
+ function setupLayer() {
63
+ const { fill = DEFAULT_FILL_COLOR, stroke = DEFAULT_STROKE_COLOR } = isochroneSetting.color || {};
64
+ map.addLayer({
65
+ id: 'isochroneFill',
66
+ type: 'fill',
67
+ source: ISOCHRONE_SOURCE,
68
+ layout: {},
69
+ paint: {
70
+ 'fill-color': fill,
71
+ 'fill-opacity': 0.07,
72
+ },
73
+ });
74
+ map.addLayer({
75
+ id: 'isochroneStroke',
76
+ type: 'line',
77
+ source: ISOCHRONE_SOURCE,
78
+ layout: {},
79
+ paint: {
80
+ 'line-color': stroke,
81
+ 'line-width': 1,
82
+ },
83
+ });
84
+ }
85
+ function invertCoordinates(apiResult) {
86
+ var _a;
87
+ const apiCoordinates = (_a = apiResult.features[0]) === null || _a === void 0 ? void 0 : _a.geometry.coordinates;
88
+ const outerPolygon = polygon(apiCoordinates);
89
+ const innerPolygon = polygon([...OUTER_COORDINATES]);
90
+ const invertedPolygon = mask(outerPolygon, innerPolygon);
91
+ return invertedPolygon;
92
+ }
93
+ function fitApiResultBounds(apiResult) {
94
+ var _a;
95
+ const coordinates = (_a = apiResult.features[0]) === null || _a === void 0 ? void 0 : _a.geometry.coordinates;
96
+ const boundingBox = calculateBoundingBox(coordinates);
97
+ map.fitBounds(boundingBox, {
98
+ padding: 20,
99
+ animate: true,
100
+ duration: 1000,
101
+ });
22
102
  }
23
103
  };
24
- function setupSource(map) {
25
- map.addSource('isochrone', {
26
- type: 'geojson',
27
- data: {
28
- type: 'FeatureCollection',
29
- features: [],
30
- },
104
+ const removeIsochrone = (map) => {
105
+ const source = map.getSource(ISOCHRONE_SOURCE);
106
+ if (!source)
107
+ return;
108
+ source.setData({
109
+ type: 'FeatureCollection',
110
+ features: [],
31
111
  });
32
- }
33
- function setupLayer(map) {
34
- map.addLayer({
35
- id: 'isochroneLayer',
36
- type: 'fill',
37
- source: 'isochrone',
38
- layout: {},
39
- paint: {
40
- 'fill-color': '#5a3fc0',
41
- 'fill-opacity': 0.3,
42
- },
43
- });
44
- }
45
- export default isochrone;
112
+ };
113
+ export { addIsochrone, removeIsochrone };
46
114
  //# sourceMappingURL=isochrone.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isochrone.js","sourceRoot":"","sources":["../../../../../src/molecules/map/utilities/mapbox/isochrone.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,MAAM,SAAS,GAAG,KAAK,EAAE,GAAiB,EAAE,gBAAqC,EAAE,EAAE;IAEjF,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;QAC7B,WAAW,CAAC,GAAG,CAAC,CAAC;QACjB,UAAU,CAAC,GAAG,CAAC,CAAC;KACnB;IAED,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;IAE1D,MAAM,WAAW,GAAG,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,WAAW,CAAC;IAEtE,IAAI;QACA,MAAM,GAAG,GAAG,8CAA8C,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,qBAAqB,OAAO,+BAA+B,WAAW,EAAE,CAAC;QAC5K,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,YAAY,GAAQ,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAE9C,IAAI,YAAY,EAAE;YACd,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,WAAW,CAAuC,CAAC;YAChF,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,CAAC,YAAY,EAAE;SACjC;KACJ;IAAC,OAAO,CAAC,EAAE;QACR,IAAI,WAAW,CAAC,OAAO,EAAE;YACrB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACpB;KACJ;AACL,CAAC,CAAC;AAEF,SAAS,WAAW,CAAC,GAAiB;IAClC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE;QACvB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACF,IAAI,EAAE,mBAAmB;YACzB,QAAQ,EAAE,EAAE;SACf;KACJ,CAAC,CAAC;AACP,CAAC;AAED,SAAS,UAAU,CAAC,GAAiB;IACjC,GAAG,CAAC,QAAQ,CAAC;QACT,EAAE,EAAE,gBAAgB;QACpB,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,EAAE;QACV,KAAK,EAAE;YACH,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,GAAG;SACtB;KACJ,CAAC,CAAC;AACP,CAAC;AAED,eAAe,SAAS,CAAC","sourcesContent":["import { MapIsochroneSetting } from '@bpd-library/types';\nimport { environment } from '@bpd-library/utilities';\nimport mapboxgl from 'mapbox-gl';\n\nconst isochrone = async (map: mapboxgl.Map, isochroneSetting: MapIsochroneSetting) => {\n // Setup source and layer, if not existing\n if (!map.getSource('isochrone')) {\n setupSource(map);\n setupLayer(map);\n }\n\n const { coordinate, minutes, profile } = isochroneSetting;\n\n const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;\n\n try {\n const url = `https://api.mapbox.com/isochrone/v1/mapbox/${profile}/${coordinate[0]},${coordinate[1]}?contours_minutes=${minutes}&polygons=true&access_token=${accessToken}`;\n const result = await fetch(url);\n const parsedResult: any = await result.json();\n\n if (parsedResult) {\n const source = map.getSource('isochrone') as mapboxgl.GeoJSONSource | undefined;\n source?.setData(parsedResult);\n }\n } catch (e) {\n if (environment.isLocal) {\n console.error(e);\n }\n }\n};\n\nfunction setupSource(map: mapboxgl.Map) {\n map.addSource('isochrone', {\n type: 'geojson',\n data: {\n type: 'FeatureCollection',\n features: [],\n },\n });\n}\n\nfunction setupLayer(map: mapboxgl.Map) {\n map.addLayer({\n id: 'isochroneLayer',\n type: 'fill',\n source: 'isochrone',\n layout: {},\n paint: {\n 'fill-color': '#5a3fc0',\n 'fill-opacity': 0.3,\n },\n });\n}\n\nexport default isochrone;\n"]}
1
+ {"version":3,"file":"isochrone.js","sourceRoot":"","sources":["../../../../../src/molecules/map/utilities/mapbox/isochrone.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG3E,MAAM,iBAAiB,GAAgB;IACnC;QACI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;QACT,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACR,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;KACZ;CACJ,CAAC;AACF,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AACrC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAIvC,IAAI,IAAS,CAAC;AACd,IAAI,OAAY,CAAC;AAEjB,MAAM,YAAY,GAAG,KAAK,EAAE,GAAiB,EAAE,gBAAqC,EAAE,EAAE;IACpF,MAAM,IAAI,EAAE,CAAC;IAEb,KAAK,UAAU,IAAI;QAEf,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;YACnB,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,C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AC,CAAC,0CAAE,QAAQ,CAAC,WAA0B,CAAC;QAC/E,MAAM,WAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAEtD,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE;YACvB,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACjB,CAAC,CAAC;IACP,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,GAAiB,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,gBAAgB,CAAuC,CAAC;IAErF,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,CAAC,OAAO,CAAC;QACX,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,EAAE;KACf,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { Coordinates, MapIsochroneSetting } from '@bpd-library/types';\nimport { calculateBoundingBox, environment } from '@bpd-library/utilities';\nimport mapboxgl from 'mapbox-gl';\n\nconst OUTER_COORDINATES: Coordinates = [\n [\n [-42, 74],\n [-42, 1],\n [80, 1],\n [80, 74],\n [-42, 74],\n ],\n];\nconst ISOCHRONE_SOURCE = 'isochrone';\nconst DEFAULT_FILL_COLOR = '#000000';\nconst DEFAULT_STROKE_COLOR = '#32C1DE';\n\ntype IsochroneApiResult = GeoJSON.FeatureCollection<GeoJSON.Polygon>;\n\nlet mask: any;\nlet polygon: any;\n\nconst addIsochrone = async (map: mapboxgl.Map, isochroneSetting: MapIsochroneSetting) => {\n await init();\n\n async function init() {\n // Lazyload turf package\n if (!mask || !polygon) {\n const maskPackage = await import('@turf/mask');\n const helpersPackage = await import('@turf/helpers');\n\n mask = await maskPackage.default;\n polygon = await helpersPackage.polygon;\n }\n\n // Setup source and layer, if not existing\n if (!map.getSource(ISOCHRONE_SOURCE)) {\n setupSource();\n setupLayer();\n }\n\n const { coordinate, minutes, profile, fitBounds } = isochroneSetting;\n\n const accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;\n\n try {\n let url: string = `https://api.mapbox.com/isochrone/v1/mapbox/${profile}/${coordinate[0]},${coordinate[1]}?contours_minutes=${minutes}&polygons=true&access_token=${accessToken}`;\n\n // To simplify the polygon. Makes calculating boundingBoxes more performant\n if (profile === 'driving') {\n url += '&generalize=100';\n }\n\n const result = await fetch(url);\n const parsedResult: IsochroneApiResult = await result.json();\n\n if (parsedResult) {\n const source = map.getSource(ISOCHRONE_SOURCE) as\n | mapboxgl.GeoJSONSource\n | undefined;\n\n const invertedCoordinates = invertCoordinates(parsedResult);\n\n if (fitBounds) {\n fitApiResultBounds(parsedResult);\n }\n\n source?.setData(invertedCoordinates);\n }\n } catch (e) {\n if (environment.isLocal) {\n console.error(e);\n }\n }\n }\n\n function setupSource() {\n map.addSource(ISOCHRONE_SOURCE, {\n type: 'geojson',\n data: {\n type: 'FeatureCollection',\n features: [],\n },\n });\n }\n\n function setupLayer() {\n const {\n fill = DEFAULT_FILL_COLOR,\n stroke = DEFAULT_STROKE_COLOR\n } = isochroneSetting.color || {};\n\n map.addLayer({\n id: 'isochroneFill',\n type: 'fill',\n source: ISOCHRONE_SOURCE,\n layout: {},\n paint: {\n 'fill-color': fill,\n 'fill-opacity': 0.07,\n },\n });\n\n map.addLayer({\n id: 'isochroneStroke',\n type: 'line',\n source: ISOCHRONE_SOURCE,\n layout: {},\n paint: {\n 'line-color': stroke,\n 'line-width': 1,\n },\n });\n }\n\n function invertCoordinates(apiResult: IsochroneApiResult) {\n const apiCoordinates = apiResult.features[0]?.geometry.coordinates;\n\n const outerPolygon = polygon(apiCoordinates);\n const innerPolygon = polygon([...OUTER_COORDINATES]);\n\n const invertedPolygon = mask(outerPolygon, innerPolygon);\n\n return invertedPolygon;\n }\n\n function fitApiResultBounds(apiResult: IsochroneApiResult) {\n const coordinates = apiResult.features[0]?.geometry.coordinates as Coordinates;\n const boundingBox = calculateBoundingBox(coordinates);\n\n map.fitBounds(boundingBox, {\n padding: 20,\n animate: true,\n duration: 1000,\n });\n }\n};\n\nconst removeIsochrone = (map: mapboxgl.Map) => {\n const source = map.getSource(ISOCHRONE_SOURCE) as mapboxgl.GeoJSONSource | undefined;\n\n if (!source) return;\n\n source.setData({\n type: 'FeatureCollection',\n features: [],\n });\n};\n\nexport { addIsochrone, removeIsochrone };\n"]}
@@ -12,6 +12,7 @@ declare const mapbox: (map: mapboxgl.Map, options: MapOptions, theme: MapTheme)
12
12
  removeTooltip: () => void;
13
13
  setFeatureState: (variant: string, id: string, type: 'hover' | 'focus', hover: boolean) => void;
14
14
  search: (searchOptions: MapSearchOptions) => Promise<void>;
15
- isochrone: (isochroneSetting: MapIsochroneSetting) => Promise<void>;
15
+ addIsochrone: (isochroneSetting: MapIsochroneSetting) => Promise<void>;
16
+ removeIsochrone: () => void;
16
17
  };
17
18
  export default mapbox;
@@ -1,6 +1,6 @@
1
1
  import addData from './add-data';
2
2
  import center from './center';
3
- import isochrone from './isochrone';
3
+ import { addIsochrone, removeIsochrone } from './isochrone';
4
4
  import setupPointers from './pointers/setup-pointers';
5
5
  import setFeatureState from './polygons/feature-state';
6
6
  import geojson from './polygons/geojson';
@@ -16,12 +16,13 @@ const mapbox = (map, options, theme) => ({
16
16
  interaction: (setting) => interaction(map, setting),
17
17
  center: (coordinates) => center(map, coordinates),
18
18
  setupPointers: (element) => setupPointers(map, theme, element),
19
- addData: (data) => addData(map, data, theme),
19
+ addData: (data) => addData(map, data, theme, options),
20
20
  addTooltip: (coordinates, mapDataItem) => addTooltip(map, coordinates, mapDataItem, options.openInTab),
21
21
  removeTooltip,
22
22
  setFeatureState: (variant, id, type, hover) => setFeatureState(map, variant, id, type, hover),
23
23
  search: (searchOptions) => search(map, searchOptions, options),
24
- isochrone: (isochroneSetting) => isochrone(map, isochroneSetting),
24
+ addIsochrone: (isochroneSetting) => addIsochrone(map, isochroneSetting),
25
+ removeIsochrone: () => removeIsochrone(map),
25
26
  });
26
27
  export default mapbox;
27
28
  //# sourceMappingURL=mapbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mapbox.js","sourceRoot":"","sources":["../../../../../src/molecules/map/utilities/mapbox/mapbox.ts"],"names":[],"mappings":"AAYA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAO,eAAe,MAAM,0BAA0B,CAAC;AACvD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,MAAM,GAAG,CAAC,GAAiB,EAAE,OAAmB,EAAE,KAAe,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,EAAE,CAAC,QAAgC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC;IACnE,OAAO,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;IAChE,KAAK,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC;IAC5D,WAAW,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;IACxE,MAAM,EAAE,CAAC,WAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC;IAC9D,aAAa,EAAE,CAAC,OAAoB,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC;IAC3E,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;IACrD,UAAU,EAAE,CAAC,WAAwB,EAAE,WAAwB,EAAE,EAAE,CAC/D,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;IAChE,aAAa;IACb,eAAe,EAAE,CAAC,OAAe,EAAE,EAAU,EAAE,IAAuB,EAAE,KAAc,EAAE,EAAE,CACtF,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC;IAClD,MAAM,EAAE,CAAC,aAA+B,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC;IAChF,SAAS,EAAE,CAAC,gBAAqC,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,gBAAgB,CAAC;CACzF,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC","sourcesContent":["import {\n Coordinates,\n MapData,\n MapDataItem,\n MapIsochroneSetting,\n MapOptions,\n MapSearchOptions,\n MapTheme,\n PolygonThemeSetting,\n} from '@bpd-library/types';\n\nimport { MapLayerRasterSettings } from '../../store/map';\nimport addData from './add-data';\nimport center from './center';\nimport isochrone from './isochrone';\nimport setupPointers from './pointers/setup-pointers';\nimport setFeatureState from './polygons/feature-state';\nimport geojson from './polygons/geojson';\nimport interaction from './polygons/interaction';\nimport layer from './polygons/layer';\nimport raster from './raster';\nimport search from './search/search';\nimport { addTooltip, removeTooltip } from './tooltip';\n\nconst mapbox = (map: mapboxgl.Map, options: MapOptions, theme: MapTheme) => ({\n raster: (settings: MapLayerRasterSettings) => raster(map, settings),\n geojson: (setting: PolygonThemeSetting) => geojson(map, setting),\n layer: (setting: PolygonThemeSetting) => layer(map, setting),\n interaction: (setting: PolygonThemeSetting) => interaction(map, setting),\n center: (coordinates: Coordinates) => center(map, coordinates),\n setupPointers: (element: HTMLElement) => setupPointers(map, theme, element),\n addData: (data: MapData) => addData(map, data, theme),\n addTooltip: (coordinates: Coordinates, mapDataItem: MapDataItem) =>\n addTooltip(map, coordinates, mapDataItem, options.openInTab),\n removeTooltip,\n setFeatureState: (variant: string, id: string, type: 'hover' | 'focus', hover: boolean) =>\n setFeatureState(map, variant, id, type, hover),\n search: (searchOptions: MapSearchOptions) => search(map, searchOptions, options),\n isochrone: (isochroneSetting: MapIsochroneSetting) => isochrone(map, isochroneSetting),\n});\n\nexport default mapbox;\n"]}
1
+ {"version":3,"file":"mapbox.js","sourceRoot":"","sources":["../../../../../src/molecules/map/utilities/mapbox/mapbox.ts"],"names":[],"mappings":"AAYA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAO,eAAe,MAAM,0BAA0B,CAAC;AACvD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,MAAM,GAAG,CAAC,GAAiB,EAAE,OAAmB,EAAE,KAAe,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,EAAE,CAAC,QAAgC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC;IACnE,OAAO,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;IAChE,KAAK,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC;IAC5D,WAAW,EAAE,CAAC,OAA4B,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;IACxE,MAAM,EAAE,CAAC,WAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC;IAC9D,aAAa,EAAE,CAAC,OAAoB,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC;IAC3E,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;IAC9D,UAAU,EAAE,CAAC,WAAwB,EAAE,WAAwB,EAAE,EAAE,CAC/D,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;IAChE,aAAa;IACb,eAAe,EAAE,CAAC,OAAe,EAAE,EAAU,EAAE,IAAuB,EAAE,KAAc,EAAE,EAAE,CACtF,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC;IAClD,MAAM,EAAE,CAAC,aAA+B,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC;IAChF,YAAY,EAAE,CAAC,gBAAqC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC5F,eAAe,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC;CAC9C,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC","sourcesContent":["import {\n Coordinates,\n MapData,\n MapDataItem,\n MapIsochroneSetting,\n MapOptions,\n MapSearchOptions,\n MapTheme,\n PolygonThemeSetting,\n} from '@bpd-library/types';\n\nimport { MapLayerRasterSettings } from '../../store/map';\nimport addData from './add-data';\nimport center from './center';\nimport { addIsochrone, removeIsochrone } from './isochrone';\nimport setupPointers from './pointers/setup-pointers';\nimport setFeatureState from './polygons/feature-state';\nimport geojson from './polygons/geojson';\nimport interaction from './polygons/interaction';\nimport layer from './polygons/layer';\nimport raster from './raster';\nimport search from './search/search';\nimport { addTooltip, removeTooltip } from './tooltip';\n\nconst mapbox = (map: mapboxgl.Map, options: MapOptions, theme: MapTheme) => ({\n raster: (settings: MapLayerRasterSettings) => raster(map, settings),\n geojson: (setting: PolygonThemeSetting) => geojson(map, setting),\n layer: (setting: PolygonThemeSetting) => layer(map, setting),\n interaction: (setting: PolygonThemeSetting) => interaction(map, setting),\n center: (coordinates: Coordinates) => center(map, coordinates),\n setupPointers: (element: HTMLElement) => setupPointers(map, theme, element),\n addData: (data: MapData) => addData(map, data, theme, options),\n addTooltip: (coordinates: Coordinates, mapDataItem: MapDataItem) =>\n addTooltip(map, coordinates, mapDataItem, options.openInTab),\n removeTooltip,\n setFeatureState: (variant: string, id: string, type: 'hover' | 'focus', hover: boolean) =>\n setFeatureState(map, variant, id, type, hover),\n search: (searchOptions: MapSearchOptions) => search(map, searchOptions, options),\n addIsochrone: (isochroneSetting: MapIsochroneSetting) => addIsochrone(map, isochroneSetting),\n removeIsochrone: () => removeIsochrone(map),\n});\n\nexport default mapbox;\n"]}
@@ -1,4 +1,4 @@
1
1
  import { MapOptions, MapSearchOptions } from '@bpd-library/types';
2
2
  import mapboxgl from 'mapbox-gl';
3
- declare const search: (map: mapboxgl.Map, { hook, kmPadding, onSearchSuggestion, noZoomAfterSearch }: MapSearchOptions, { searchCountryIsoCodes, language }: MapOptions) => Promise<void>;
3
+ declare const search: (map: mapboxgl.Map, { hook, kmPadding, onSearchSuggestion, noZoomAfterSearch, types, }: MapSearchOptions, { searchCountryIsoCodes, language }: MapOptions) => Promise<void>;
4
4
  export default search;
@@ -5,7 +5,8 @@ import { clearSearchResult, getMapboxData, mapStore, updateSearchIsMoving, updat
5
5
  import { fitBounds } from '../../fit-bounds';
6
6
  import getCityAlternativeSuggestions from './alternative-city-suggestions';
7
7
  const MIN_KM_PADDING = 10;
8
- const search = async (map, { hook, kmPadding = MIN_KM_PADDING, onSearchSuggestion, noZoomAfterSearch }, { searchCountryIsoCodes = ['nl', 'de'], language = 'nl' }) => {
8
+ const DEFAULT_TYPES = 'region,district,place,neighborhood';
9
+ const search = async (map, { hook, kmPadding = MIN_KM_PADDING, onSearchSuggestion, noZoomAfterSearch, types = DEFAULT_TYPES, }, { searchCountryIsoCodes = ['nl', 'de'], language = 'nl' }) => {
9
10
  const element = document.querySelector(hook);
10
11
  const bounds = getCountryBoundingBox(searchCountryIsoCodes);
11
12
  if (!element) {
@@ -26,7 +27,7 @@ const search = async (map, { hook, kmPadding = MIN_KM_PADDING, onSearchSuggestio
26
27
  accessToken: mapboxgl.accessToken,
27
28
  mapboxgl,
28
29
  countries: searchCountryIsoCodes.join(',').toUpperCase(),
29
- types: 'region,district,place,neighborhood',
30
+ types,
30
31
  localGeocoder,
31
32
  language,
32
33
  enableEventLogging: false,
@@ -1 +1 @@
1
- {"version":3,"file":"search.js","sourceRoot":"","sources":["../../../../../../src/molecules/map/utilities/mapbox/search/search.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,OAAO,EACH,0BAA0B,EAC1B,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EACH,iBAAiB,EACjB,aAAa,EAEb,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,6BAA6B,MAAM,gCAAgC,CAAC;AAE3E,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,MAAM,MAAM,GAAG,KAAK,EAChB,GAAiB,EACjB,EAAE,IAAI,EAAE,SAAS,GAAG,cAAc,EAAE,kBAAkB,EAAE,i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,OAAO,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAChD,OAAO,CAAC,UAAU,CACd,CACR,CACR,CAAC,CACD,CACR,CAAC;IACN,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { h } from '@atomify/jsx';\nimport { BoundingBox, MapOptions, MapSearchOptions, MapSearchSuggestion } from '@bpd-library/types';\nimport {\n calculateBoundingBoxCenter,\n debounce,\n environment,\n expandBoundingBox,\n getCountryBoundingBox,\n useClickOutside,\n withinBoundingBox,\n} from '@bpd-library/utilities';\nimport mapboxgl from 'mapbox-gl';\n\nimport {\n clearSearchResult,\n getMapboxData,\n MapState,\n mapStore,\n updateSearchIsMoving,\n updateSearchResult,\n} from '../../../store/map';\nimport { fitBounds } from '../../fit-bounds';\nimport getCityAlternativeSuggestions from './alternative-city-suggestions';\n\nconst MIN_KM_PADDING = 10;\n\nconst search = async (\n map: mapboxgl.Map,\n { hook, kmPadding = MIN_KM_PADDING, onSearchSuggestion, noZoomAfterSearch }: MapSearchOptions,\n { searchCountryIsoCodes = ['nl', 'de'], language = 'nl' }: MapOptions,\n) => {\n const element = document.querySelector(hook);\n const bounds = getCountryBoundingBox(searchCountryIsoCodes);\n\n if (!element) {\n if (environment.isLocal) console.error(`Search element can't be found: ${hook}`);\n return;\n }\n\n const inputElement = element.querySelector('[js-hook-map-search-input]') as HTMLInputElement;\n const form = inputElement.closest<HTMLFormElement>('form');\n const suggestionsElement = element.querySelector(\n '[js-hook-map-search-suggestions]',\n ) as HTMLElement;\n const buttonElement = element.querySelector('[js-hook-map-search-button]') as HTMLButtonElement;\n\n let geocoder: any | undefined;\n let suggestions: any | undefined;\n\n init();\n\n async function init() {\n // Dynamically import geocoder library\n const { default: MapboxGeocoder } = await import('@mapbox/mapbox-gl-geocoder');\n\n geocoder = new MapboxGeocoder({\n accessToken: mapboxgl.accessToken,\n mapboxgl,\n countries: searchCountryIsoCodes.join(',').toUpperCase(),\n types: 'region,district,place,neighborhood',\n localGeocoder,\n language,\n enableEventLogging: false,\n marker: false,\n });\n\n map.addControl(geocoder);\n\n bindEvents();\n subscribe();\n }\n\n function bindEvents() {\n const debouncedOnKeyDown = debounce(onKeyDown, 300);\n\n inputElement.addEventListener('keydown', debouncedOnKeyDown);\n buttonElement.addEventListener('click', handleButtonClick);\n form?.addEventListener('submit', (e) => e.preventDefault());\n\n useClickOutside(inputElement!, handleClickOutside);\n\n geocoder.on('results', (results: any) => {\n suggestions = results;\n\n renderSuggestions(suggestions);\n });\n }\n\n function subscribe() {\n handleManualSearch(mapStore.getState());\n mapStore.subscribe(handleManualSearch, ['manualSearch']);\n }\n\n function handleManualSearch({ manualSearch }: MapState) {\n if (manualSearch) {\n geocoder.setInput(manualSearch).on('results', function handleResults(results: any) {\n suggestions = results;\n\n // First check if there's an exact match, in some cases bigger cities that are not an exact match are returned as first and most relevant result, while doing a manual search you always want an exact match.\n const firstExactMatch = results?.features?.find(\n ({ text }: { text?: string }) =>\n text?.toLowerCase() === manualSearch.toLowerCase(),\n );\n\n if (firstExactMatch) {\n submitSuggestion(firstExactMatch);\n } else {\n submitFirstSuggestion();\n }\n\n geocoder.off('results', handleResults);\n });\n }\n }\n\n function handleClickOutside() {\n clearSuggestionsContainer();\n }\n\n function handleFitBounds() {\n if (noZoomAfterSearch) return;\n\n fitBounds(map, bounds);\n }\n\n function onKeyDown(e: KeyboardEvent) {\n const { value } = inputElement!;\n\n if (e.key === 'Enter') {\n if (!value) {\n clearAll();\n return;\n } else {\n geocoder.on('results', function handleEnter() {\n submitFirstSuggestion();\n inputElement?.blur();\n\n geocoder.off('results', handleEnter);\n });\n }\n }\n\n if (value.length >= 3) {\n geocoder.setInput(value);\n } else {\n suggestions = undefined;\n handleFitBounds();\n clearSuggestionsContainer();\n clearSearchResult();\n }\n }\n\n function handleButtonClick() {\n const { value } = inputElement!;\n\n if (!value) {\n clearAll();\n } else {\n submitFirstSuggestion();\n }\n }\n\n function submitFirstSuggestion() {\n const firstSuggestion = suggestions?.features[0];\n\n submitSuggestion(firstSuggestion);\n }\n\n function submitSuggestion(feature: any) {\n updateStore(feature);\n clearSuggestionsContainer();\n }\n\n function clearSuggestionsContainer() {\n suggestionsElement.innerHTML = '';\n }\n\n function clearAll() {\n suggestions = undefined;\n handleFitBounds();\n clearSuggestionsContainer();\n clearSearchResult();\n inputElement?.blur();\n }\n\n function localGeocoder(query: string) {\n const createSuggestion = ({ title, bbox, type, id }: MapSearchSuggestion) => {\n const center = calculateBoundingBoxCenter(bbox);\n\n return {\n place_name: title,\n bbox,\n center,\n type,\n id,\n };\n };\n\n const customSuggestions = onSearchSuggestion\n ? onSearchSuggestion(query.toLowerCase()).map(createSuggestion)\n : [];\n const cityAlternatives = getCityAlternativeSuggestions(query.toLowerCase()).map(\n createSuggestion,\n );\n\n return [...customSuggestions, ...cityAlternatives].slice(0, 4);\n }\n\n function updateStore(result: any) {\n if (!result) {\n updateSearchResult({\n items: [],\n result: false,\n });\n\n handleFitBounds();\n\n return;\n }\n\n const expandedBoundingBox = expandBoundingBox(result.bbox as BoundingBox, kmPadding);\n const originalBoundingBox = result.bbox as BoundingBox;\n\n const mapData = getMapboxData();\n const filteredData = mapData.filter((item) =>\n withinBoundingBox(item.coordinates, expandedBoundingBox),\n );\n\n if (!noZoomAfterSearch) {\n map.fitBounds(expandedBoundingBox);\n\n // Update searchIsMoving boolean in store. Is used to block other focus interactions when searched.\n updateSearchIsMoving(true);\n\n map.once('moveend', () => {\n updateSearchIsMoving(false);\n });\n }\n\n updateSearchResult({\n items: filteredData,\n result,\n originalBoundingBox,\n expandedBoundingBox,\n });\n }\n\n function handleSuggestionClick(feature: any) {\n inputElement.value = feature.place_name;\n\n clearSuggestionsContainer();\n updateStore(feature);\n }\n\n function renderSuggestions(suggestions: any) {\n clearSuggestionsContainer();\n\n suggestionsElement.append(\n <ul class=\"map-search__suggestions\">\n {suggestions.features.map((feature: any) => (\n <li class=\"map-search__suggestion\">\n <button onClick={() => handleSuggestionClick(feature)}>\n {feature.place_name}\n </button>\n </li>\n ))}\n </ul>,\n );\n }\n};\n\nexport default search;\n"]}
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../../../../../src/molecules/map/utilities/mapbox/search/search.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,OAAO,EACH,0BAA0B,EAC1B,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EACH,iBAAiB,EACjB,aAAa,EAEb,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,6BAA6B,MAAM,gCAAgC,CAAC;AAE3E,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,aAAa,GAAG,oCAAoC,CAAC;AAE3D,MAAM,MAAM,GAAG,KAAK,EAChB,GAAiB,EACjB,EACI,IAAI,EACJ,SAAS,GAAG,cAAc,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,KAAK,GAAG,aAAa,GACN,EACnB,EAAE,qBAAqB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,EAAc,EACvE,EAAE;IACA,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IAE5D,IAAI,CAAC,OAAO,EAAE;QACV,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC;QACjF,OAAO;KACV;IAED,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,4BAA4B,C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CAAC,CAC3D,CAAC;QAEF,IAAI,CAAC,iBAAiB,EAAE;YACpB,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;YAGnC,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAE3B,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;gBACrB,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;SACN;QAED,kBAAkB,CAAC;YACf,KAAK,EAAE,YAAY;YACnB,MAAM;YACN,mBAAmB;YACnB,mBAAmB;SACtB,CAAC,CAAC;IACP,CAAC;IAED,SAAS,qBAAqB,CAAC,OAAY;QACvC,YAAY,CAAC,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC;QAExC,yBAAyB,EAAE,CAAC;QAC5B,WAAW,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,SAAS,iBAAiB,CAAC,WAAgB;QACvC,yBAAyB,EAAE,CAAC;QAE5B,kBAAkB,CAAC,MAAM,CACrB,UAAI,KAAK,EAAC,yBAAyB,IAC9B,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,CACxC,UAAI,KAAK,EAAC,wBAAwB;YAC9B,cAAQ,OAAO,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAChD,OAAO,CAAC,UAAU,CACd,CACR,CACR,CAAC,CACD,CACR,CAAC;IACN,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { h } from '@atomify/jsx';\nimport { BoundingBox, MapOptions, MapSearchOptions, MapSearchSuggestion } from '@bpd-library/types';\nimport {\n calculateBoundingBoxCenter,\n debounce,\n environment,\n expandBoundingBox,\n getCountryBoundingBox,\n useClickOutside,\n withinBoundingBox,\n} from '@bpd-library/utilities';\nimport mapboxgl from 'mapbox-gl';\n\nimport {\n clearSearchResult,\n getMapboxData,\n MapState,\n mapStore,\n updateSearchIsMoving,\n updateSearchResult,\n} from '../../../store/map';\nimport { fitBounds } from '../../fit-bounds';\nimport getCityAlternativeSuggestions from './alternative-city-suggestions';\n\nconst MIN_KM_PADDING = 10;\nconst DEFAULT_TYPES = 'region,district,place,neighborhood';\n\nconst search = async (\n map: mapboxgl.Map,\n {\n hook,\n kmPadding = MIN_KM_PADDING,\n onSearchSuggestion,\n noZoomAfterSearch,\n types = DEFAULT_TYPES,\n }: MapSearchOptions,\n { searchCountryIsoCodes = ['nl', 'de'], language = 'nl' }: MapOptions,\n) => {\n const element = document.querySelector(hook);\n const bounds = getCountryBoundingBox(searchCountryIsoCodes);\n\n if (!element) {\n if (environment.isLocal) console.error(`Search element can't be found: ${hook}`);\n return;\n }\n\n const inputElement = element.querySelector('[js-hook-map-search-input]') as HTMLInputElement;\n const form = inputElement.closest<HTMLFormElement>('form');\n const suggestionsElement = element.querySelector(\n '[js-hook-map-search-suggestions]',\n ) as HTMLElement;\n const buttonElement = element.querySelector('[js-hook-map-search-button]') as HTMLButtonElement;\n\n let geocoder: any | undefined;\n let suggestions: any | undefined;\n\n init();\n\n async function init() {\n // Dynamically import geocoder library\n const { default: MapboxGeocoder } = await import('@mapbox/mapbox-gl-geocoder');\n\n geocoder = new MapboxGeocoder({\n accessToken: mapboxgl.accessToken,\n mapboxgl,\n countries: searchCountryIsoCodes.join(',').toUpperCase(),\n types,\n localGeocoder,\n language,\n enableEventLogging: false,\n marker: false,\n });\n\n map.addControl(geocoder);\n\n bindEvents();\n subscribe();\n }\n\n function bindEvents() {\n const debouncedOnKeyDown = debounce(onKeyDown, 300);\n\n inputElement.addEventListener('keydown', debouncedOnKeyDown);\n buttonElement.addEventListener('click', handleButtonClick);\n form?.addEventListener('submit', (e) => e.preventDefault());\n\n useClickOutside(inputElement!, handleClickOutside);\n\n geocoder.on('results', (results: any) => {\n suggestions = results;\n\n renderSuggestions(suggestions);\n });\n }\n\n function subscribe() {\n handleManualSearch(mapStore.getState());\n mapStore.subscribe(handleManualSearch, ['manualSearch']);\n }\n\n function handleManualSearch({ manualSearch }: MapState) {\n if (manualSearch) {\n geocoder.setInput(manualSearch).on('results', function handleResults(results: any) {\n suggestions = results;\n\n // First check if there's an exact match, in some cases bigger cities that are not an exact match are returned as first and most relevant result, while doing a manual search you always want an exact match.\n const firstExactMatch = results?.features?.find(\n ({ text }: { text?: string }) =>\n text?.toLowerCase() === manualSearch.toLowerCase(),\n );\n\n if (firstExactMatch) {\n submitSuggestion(firstExactMatch);\n } else {\n submitFirstSuggestion();\n }\n\n geocoder.off('results', handleResults);\n });\n }\n }\n\n function handleClickOutside() {\n clearSuggestionsContainer();\n }\n\n function handleFitBounds() {\n if (noZoomAfterSearch) return;\n\n fitBounds(map, bounds);\n }\n\n function onKeyDown(e: KeyboardEvent) {\n const { value } = inputElement!;\n\n if (e.key === 'Enter') {\n if (!value) {\n clearAll();\n return;\n } else {\n geocoder.on('results', function handleEnter() {\n submitFirstSuggestion();\n inputElement?.blur();\n\n geocoder.off('results', handleEnter);\n });\n }\n }\n\n if (value.length >= 3) {\n geocoder.setInput(value);\n } else {\n suggestions = undefined;\n handleFitBounds();\n clearSuggestionsContainer();\n clearSearchResult();\n }\n }\n\n function handleButtonClick() {\n const { value } = inputElement!;\n\n if (!value) {\n clearAll();\n } else {\n submitFirstSuggestion();\n }\n }\n\n function submitFirstSuggestion() {\n const firstSuggestion = suggestions?.features[0];\n\n submitSuggestion(firstSuggestion);\n }\n\n function submitSuggestion(feature: any) {\n updateStore(feature);\n clearSuggestionsContainer();\n }\n\n function clearSuggestionsContainer() {\n suggestionsElement.innerHTML = '';\n }\n\n function clearAll() {\n suggestions = undefined;\n handleFitBounds();\n clearSuggestionsContainer();\n clearSearchResult();\n inputElement?.blur();\n }\n\n function localGeocoder(query: string) {\n const createSuggestion = ({ title, bbox, type, id }: MapSearchSuggestion) => {\n const center = calculateBoundingBoxCenter(bbox);\n\n return {\n place_name: title,\n bbox,\n center,\n type,\n id,\n };\n };\n\n const customSuggestions = onSearchSuggestion\n ? onSearchSuggestion(query.toLowerCase()).map(createSuggestion)\n : [];\n const cityAlternatives = getCityAlternativeSuggestions(query.toLowerCase()).map(\n createSuggestion,\n );\n\n return [...customSuggestions, ...cityAlternatives].slice(0, 4);\n }\n\n function updateStore(result: any) {\n if (!result) {\n updateSearchResult({\n items: [],\n result: false,\n });\n\n handleFitBounds();\n\n return;\n }\n\n const expandedBoundingBox = expandBoundingBox(result.bbox as BoundingBox, kmPadding);\n const originalBoundingBox = result.bbox as BoundingBox;\n\n const mapData = getMapboxData();\n const filteredData = mapData.filter((item) =>\n withinBoundingBox(item.coordinates, expandedBoundingBox),\n );\n\n if (!noZoomAfterSearch) {\n map.fitBounds(expandedBoundingBox);\n\n // Update searchIsMoving boolean in store. Is used to block other focus interactions when searched.\n updateSearchIsMoving(true);\n\n map.once('moveend', () => {\n updateSearchIsMoving(false);\n });\n }\n\n updateSearchResult({\n items: filteredData,\n result,\n originalBoundingBox,\n expandedBoundingBox,\n });\n }\n\n function handleSuggestionClick(feature: any) {\n inputElement.value = feature.place_name;\n\n clearSuggestionsContainer();\n updateStore(feature);\n }\n\n function renderSuggestions(suggestions: any) {\n clearSuggestionsContainer();\n\n suggestionsElement.append(\n <ul class=\"map-search__suggestions\">\n {suggestions.features.map((feature: any) => (\n <li class=\"map-search__suggestion\">\n <button onClick={() => handleSuggestionClick(feature)}>\n {feature.place_name}\n </button>\n </li>\n ))}\n </ul>,\n );\n }\n};\n\nexport default search;\n"]}
@@ -0,0 +1,17 @@
1
+ interface ButtonInterface {
2
+ label: string | Text;
3
+ variant?: string;
4
+ icon?: string;
5
+ size?: string;
6
+ classes?: string;
7
+ type?: string;
8
+ url?: string;
9
+ hook?: string;
10
+ controls?: string;
11
+ onClick?: Function;
12
+ target?: string;
13
+ attr?: {};
14
+ }
15
+ declare const Button: (data: ButtonInterface) => any;
16
+ declare const ButtonA: (data: ButtonInterface) => any;
17
+ export { Button, ButtonA };
@@ -0,0 +1 @@
1
+ export * from './button';
@@ -0,0 +1,11 @@
1
+ interface ColInterface {
2
+ extraClass?: string;
3
+ children?: NodeList;
4
+ cols?: (number | undefined)[];
5
+ push?: (number | undefined)[];
6
+ pull?: (number | undefined)[];
7
+ pre?: (number | undefined)[];
8
+ post?: (number | undefined)[];
9
+ }
10
+ export declare const Col: ({ extraClass, children, cols, push, pull, pre, post, }: ColInterface) => any;
11
+ export {};
@@ -0,0 +1,6 @@
1
+ interface ContainerInterface {
2
+ extraClass?: string;
3
+ children?: NodeList;
4
+ }
5
+ export declare const Container: ({ extraClass, children }: ContainerInterface) => any;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ export interface RangeSliderProps {
2
+ min: number;
3
+ max: number;
4
+ increment: number;
5
+ start: number[];
6
+ onChange: (e: CustomEvent) => void;
7
+ name: string;
8
+ classes?: string;
9
+ disabled?: boolean;
10
+ }
11
+ export declare const RangeSliderElement: ({ classes, disabled, min, max, increment, start, name, onChange, }: RangeSliderProps) => any;
@@ -0,0 +1,7 @@
1
+ import { Component, FC } from '@atomify/hooks';
2
+ export interface BPDRange extends Component {
3
+ bindValue: number[];
4
+ start: number[];
5
+ resetState: () => void;
6
+ }
7
+ export declare const RangeSlider: FC<BPDRange>;
@@ -0,0 +1,14 @@
1
+ import { Setting, Settings } from './utilities/image';
2
+ export interface ImageInterface {
3
+ image: string;
4
+ alt: string;
5
+ settings?: Settings;
6
+ preload?: Setting;
7
+ srcset?: string;
8
+ classes?: string;
9
+ caption?: string;
10
+ hidden?: boolean;
11
+ objectFit?: boolean | 'contain';
12
+ disableCrossFade?: boolean;
13
+ }
14
+ export declare const Image: (data: ImageInterface) => any;
@@ -0,0 +1 @@
1
+ export * from './image';
@@ -0,0 +1,6 @@
1
+ interface Setting {
2
+ width?: number;
3
+ height?: number;
4
+ }
5
+ declare const createImageUrl: (image: string, { width, height }: Setting) => string;
6
+ export default createImageUrl;
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ srcset: boolean;
3
+ currentSrc: boolean;
4
+ sizes: boolean;
5
+ picture: boolean;
6
+ };
7
+ export default _default;
@@ -0,0 +1,18 @@
1
+ export interface Setting {
2
+ width?: number;
3
+ height?: number;
4
+ src?: boolean | undefined;
5
+ }
6
+ export interface Settings {
7
+ [key: string]: Setting;
8
+ }
9
+ export declare class BPDImage extends HTMLElement {
10
+ img: HTMLImageElement;
11
+ componentDidLoad(): void;
12
+ disconnectedCallback(): void;
13
+ private parseSettings;
14
+ private generateSrc;
15
+ private generateSrcset;
16
+ private loadImage;
17
+ private renderImage;
18
+ }
@@ -0,0 +1,7 @@
1
+ declare type ImageElement = HTMLImageElement | HTMLImageElement[];
2
+ export default class ObjectFit {
3
+ static polyfillObjectFit(element: ImageElement): void;
4
+ static getObjectfitImages(element: ImageElement): HTMLImageElement[];
5
+ private static polyfillImage;
6
+ }
7
+ export {};
@@ -0,0 +1,6 @@
1
+ interface RowInterface {
2
+ extraClass?: string;
3
+ children?: NodeList;
4
+ }
5
+ export declare const Row: ({ extraClass, children }: RowInterface) => any;
6
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare class BPDSvg extends HTMLElement {
2
+ name: string;
3
+ render(): any;
4
+ }
@@ -0,0 +1,11 @@
1
+ export * from './atoms/button';
2
+ export * from './atoms/col/col';
3
+ export * from './atoms/container/container';
4
+ export * from './atoms/form-elements/range-slider/range-slider';
5
+ export * from './atoms/form-elements/utilities/range-slider';
6
+ export * from './atoms/image';
7
+ export * from './atoms/row/row';
8
+ export * from './atoms/svg/svg';
9
+ export * from './molecules/infobox';
10
+ export * from './molecules/map';
11
+ export * from './molecules/tooltip';
@@ -0,0 +1 @@
1
+ export * from './infobox';
@@ -0,0 +1,7 @@
1
+ import { MapInfobox } from '@bpd-library/types';
2
+ interface InfoboxInterface extends MapInfobox {
3
+ onClose: () => void;
4
+ openInTab?: boolean;
5
+ }
6
+ export declare const Infobox: ({ title, image, tags, description, link, onClose, openInTab, }: InfoboxInterface) => any;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const useStyleLoaded: (map: mapboxgl.Map, cb: Function) => void;
2
+ export default useStyleLoaded;
@@ -0,0 +1,3 @@
1
+ export * from './utilities/fit-bounds';
2
+ export * from './store/map';
3
+ export * from './map';
@@ -0,0 +1,2 @@
1
+ import { FC } from '@atomify/hooks';
2
+ export declare const Map: FC;