@guardian/interactive-component-library 0.2.0-rc3 → 0.2.0

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 (276) hide show
  1. package/dist/interactive-component-library.js +8338 -0
  2. package/dist/interactive-component-library.js.map +1 -0
  3. package/dist/interactive-component-library.umd.cjs +8333 -0
  4. package/dist/interactive-component-library.umd.cjs.map +1 -0
  5. package/dist/style.css +157 -73
  6. package/package.json +10 -6
  7. package/dist/components/index.d.ts +0 -3
  8. package/dist/components/molecules/canvas-map/Map.d.ts +0 -17
  9. package/dist/components/molecules/canvas-map/Map.js +0 -89
  10. package/dist/components/molecules/canvas-map/context/MapContext.d.ts +0 -19
  11. package/dist/components/molecules/canvas-map/context/MapContext.js +0 -20
  12. package/dist/components/molecules/canvas-map/controls/ZoomControl.d.ts +0 -6
  13. package/dist/components/molecules/canvas-map/controls/ZoomControl.js +0 -40
  14. package/dist/components/molecules/canvas-map/controls/icons/index.d.ts +0 -3
  15. package/dist/components/molecules/canvas-map/controls/icons/minus.d.ts +0 -1
  16. package/dist/components/molecules/canvas-map/controls/icons/minus.js +0 -25
  17. package/dist/components/molecules/canvas-map/controls/icons/plus.d.ts +0 -1
  18. package/dist/components/molecules/canvas-map/controls/icons/plus.js +0 -25
  19. package/dist/components/molecules/canvas-map/controls/icons/reset.d.ts +0 -3
  20. package/dist/components/molecules/canvas-map/controls/icons/reset.js +0 -25
  21. package/dist/components/molecules/canvas-map/controls/index.d.ts +0 -1
  22. package/dist/components/molecules/canvas-map/controls/style.module.css.js +0 -11
  23. package/dist/components/molecules/canvas-map/index.d.ts +0 -12
  24. package/dist/components/molecules/canvas-map/lib/Feature.d.ts +0 -38
  25. package/dist/components/molecules/canvas-map/lib/Feature.js +0 -104
  26. package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +0 -20
  27. package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +0 -23
  28. package/dist/components/molecules/canvas-map/lib/Map.d.ts +0 -69
  29. package/dist/components/molecules/canvas-map/lib/Map.js +0 -254
  30. package/dist/components/molecules/canvas-map/lib/View.d.ts +0 -136
  31. package/dist/components/molecules/canvas-map/lib/View.js +0 -179
  32. package/dist/components/molecules/canvas-map/lib/events/Dispatcher.d.ts +0 -8
  33. package/dist/components/molecules/canvas-map/lib/events/Dispatcher.js +0 -35
  34. package/dist/components/molecules/canvas-map/lib/events/MapEvent.d.ts +0 -6
  35. package/dist/components/molecules/canvas-map/lib/events/MapEvent.js +0 -9
  36. package/dist/components/molecules/canvas-map/lib/events/index.d.ts +0 -2
  37. package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.d.ts +0 -10
  38. package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +0 -96
  39. package/dist/components/molecules/canvas-map/lib/geometry/Geometry.d.ts +0 -32
  40. package/dist/components/molecules/canvas-map/lib/geometry/Geometry.js +0 -41
  41. package/dist/components/molecules/canvas-map/lib/geometry/LineString.d.ts +0 -12
  42. package/dist/components/molecules/canvas-map/lib/geometry/LineString.js +0 -19
  43. package/dist/components/molecules/canvas-map/lib/geometry/Point.d.ts +0 -11
  44. package/dist/components/molecules/canvas-map/lib/geometry/Point.js +0 -16
  45. package/dist/components/molecules/canvas-map/lib/geometry/Polygon.d.ts +0 -16
  46. package/dist/components/molecules/canvas-map/lib/geometry/Polygon.js +0 -46
  47. package/dist/components/molecules/canvas-map/lib/geometry/index.d.ts +0 -4
  48. package/dist/components/molecules/canvas-map/lib/interpolators/index.d.ts +0 -2
  49. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.d.ts +0 -5
  50. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js +0 -95
  51. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.d.ts +0 -4
  52. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +0 -65
  53. package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +0 -52
  54. package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +0 -111
  55. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +0 -53
  56. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +0 -132
  57. package/dist/components/molecules/canvas-map/lib/layers/index.d.ts +0 -3
  58. package/dist/components/molecules/canvas-map/lib/projection/index.d.ts +0 -22
  59. package/dist/components/molecules/canvas-map/lib/projection/index.js +0 -12
  60. package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.d.ts +0 -6
  61. package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +0 -46
  62. package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +0 -6
  63. package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +0 -53
  64. package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +0 -17
  65. package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +0 -119
  66. package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +0 -10
  67. package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +0 -78
  68. package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +0 -15
  69. package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +0 -56
  70. package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +0 -7
  71. package/dist/components/molecules/canvas-map/lib/styles/Fill.js +0 -15
  72. package/dist/components/molecules/canvas-map/lib/styles/Stroke.d.ts +0 -8
  73. package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +0 -16
  74. package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +0 -24
  75. package/dist/components/molecules/canvas-map/lib/styles/Style.js +0 -17
  76. package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +0 -10
  77. package/dist/components/molecules/canvas-map/lib/styles/Text.js +0 -14
  78. package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +0 -4
  79. package/dist/components/molecules/canvas-map/lib/util/array.d.ts +0 -6
  80. package/dist/components/molecules/canvas-map/lib/util/array.js +0 -15
  81. package/dist/components/molecules/canvas-map/lib/util/bboxFeature.d.ts +0 -8
  82. package/dist/components/molecules/canvas-map/lib/util/bboxFeature.js +0 -26
  83. package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +0 -11
  84. package/dist/components/molecules/canvas-map/lib/util/debug.js +0 -27
  85. package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +0 -36
  86. package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +0 -1
  87. package/dist/components/molecules/canvas-map/lib/util/distance.js +0 -12
  88. package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +0 -9
  89. package/dist/components/molecules/canvas-map/lib/util/dom.js +0 -28
  90. package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +0 -21
  91. package/dist/components/molecules/canvas-map/lib/util/extent.js +0 -38
  92. package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +0 -10
  93. package/dist/components/molecules/canvas-map/lib/util/memoise.js +0 -20
  94. package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +0 -9
  95. package/dist/components/molecules/canvas-map/lib/util/resolution.js +0 -11
  96. package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +0 -114
  97. package/dist/components/molecules/canvas-map/lib/util/size.d.ts +0 -32
  98. package/dist/components/molecules/canvas-map/lib/util/size.js +0 -53
  99. package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +0 -1
  100. package/dist/components/molecules/canvas-map/lib/util/toRgba.js +0 -25
  101. package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +0 -5
  102. package/dist/components/molecules/canvas-map/lib/util/uid.js +0 -7
  103. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +0 -2
  104. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +0 -14
  105. package/dist/components/molecules/canvas-map/style.module.scss.js +0 -20
  106. package/dist/components/molecules/column-chart/column-chart-example.d.ts +0 -35
  107. package/dist/components/molecules/column-chart/column-chart-util.d.ts +0 -1
  108. package/dist/components/molecules/column-chart/index.d.ts +0 -11
  109. package/dist/components/molecules/column-chart/index.js +0 -63
  110. package/dist/components/molecules/column-chart/style.module.css.js +0 -14
  111. package/dist/components/molecules/control-change/index.d.ts +0 -6
  112. package/dist/components/molecules/control-change/index.js +0 -29
  113. package/dist/components/molecules/control-change/style.module.css.js +0 -11
  114. package/dist/components/molecules/dropdown/index.d.ts +0 -11
  115. package/dist/components/molecules/dropdown/index.js +0 -191
  116. package/dist/components/molecules/dropdown/style.module.css.js +0 -50
  117. package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +0 -5
  118. package/dist/components/molecules/first-past-the-post-waffle/index.js +0 -14
  119. package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +0 -14
  120. package/dist/components/molecules/index.d.ts +0 -17
  121. package/dist/components/molecules/modal/index.d.ts +0 -8
  122. package/dist/components/molecules/modal/index.js +0 -59
  123. package/dist/components/molecules/modal/style.module.css.js +0 -26
  124. package/dist/components/molecules/page-section/index.d.ts +0 -8
  125. package/dist/components/molecules/page-section/index.js +0 -52
  126. package/dist/components/molecules/page-section/style.module.scss.js +0 -20
  127. package/dist/components/molecules/party-profile/index.d.ts +0 -10
  128. package/dist/components/molecules/party-profile/index.js +0 -29
  129. package/dist/components/molecules/party-profile/style.module.css.js +0 -26
  130. package/dist/components/molecules/refresh-indicator/index.d.ts +0 -4
  131. package/dist/components/molecules/refresh-indicator/index.js +0 -18
  132. package/dist/components/molecules/refresh-indicator/style.module.scss.js +0 -17
  133. package/dist/components/molecules/responsive-grid/index.d.ts +0 -10
  134. package/dist/components/molecules/responsive-grid/index.js +0 -19
  135. package/dist/components/molecules/responsive-grid/style.module.scss.js +0 -8
  136. package/dist/components/molecules/result-summary/index.d.ts +0 -8
  137. package/dist/components/molecules/result-summary/index.js +0 -38
  138. package/dist/components/molecules/result-summary/style.module.css.js +0 -11
  139. package/dist/components/molecules/search-input/icons/search.d.ts +0 -1
  140. package/dist/components/molecules/search-input/icons/search.js +0 -24
  141. package/dist/components/molecules/search-input/icons/search.module.css.js +0 -11
  142. package/dist/components/molecules/search-input/index.d.ts +0 -11
  143. package/dist/components/molecules/search-input/index.js +0 -164
  144. package/dist/components/molecules/search-input/style.module.css.js +0 -32
  145. package/dist/components/molecules/slope-chart/index.d.ts +0 -16
  146. package/dist/components/molecules/slope-chart/index.js +0 -139
  147. package/dist/components/molecules/slope-chart/style.module.css.js +0 -35
  148. package/dist/components/molecules/svg-map/context/MapContext.d.ts +0 -1
  149. package/dist/components/molecules/svg-map/context/MapContext.js +0 -5
  150. package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +0 -10
  151. package/dist/components/molecules/svg-map/context/SVGMapProvider.js +0 -88
  152. package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +0 -8
  153. package/dist/components/molecules/svg-map/helpers/bboxFeature.js +0 -26
  154. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +0 -1
  155. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +0 -9
  156. package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +0 -4
  157. package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +0 -1
  158. package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
  159. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +0 -4
  160. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +0 -19
  161. package/dist/components/molecules/svg-map/index.d.ts +0 -38
  162. package/dist/components/molecules/svg-map/index.js +0 -121
  163. package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +0 -3
  164. package/dist/components/molecules/svg-map/layers/CompositionBorders.js +0 -14
  165. package/dist/components/molecules/svg-map/layers/Line.d.ts +0 -7
  166. package/dist/components/molecules/svg-map/layers/Line.js +0 -48
  167. package/dist/components/molecules/svg-map/layers/Point.d.ts +0 -10
  168. package/dist/components/molecules/svg-map/layers/Point.js +0 -59
  169. package/dist/components/molecules/svg-map/layers/Polygon.d.ts +0 -9
  170. package/dist/components/molecules/svg-map/layers/Polygon.js +0 -75
  171. package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +0 -3
  172. package/dist/components/molecules/svg-map/layers/Prerendered.js +0 -11
  173. package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +0 -8
  174. package/dist/components/molecules/svg-map/layers/index.d.ts +0 -5
  175. package/dist/components/molecules/svg-map/layers/index.js +0 -12
  176. package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +0 -3
  177. package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +0 -32
  178. package/dist/components/molecules/svg-map/style.module.css.js +0 -11
  179. package/dist/components/molecules/table/index.d.ts +0 -7
  180. package/dist/components/molecules/table/index.js +0 -90
  181. package/dist/components/molecules/table/style.module.scss.js +0 -29
  182. package/dist/components/molecules/table/useTable.d.ts +0 -8
  183. package/dist/components/molecules/table/useTable.js +0 -128
  184. package/dist/components/molecules/tooltip/index.d.ts +0 -82
  185. package/dist/components/molecules/tooltip/index.js +0 -117
  186. package/dist/components/molecules/tooltip/style.module.css.js +0 -8
  187. package/dist/components/molecules/topline-result/index.d.ts +0 -3
  188. package/dist/components/molecules/topline-result/index.js +0 -61
  189. package/dist/components/molecules/topline-result/style.module.scss.js +0 -38
  190. package/dist/components/organisms/coalitions-tracker/index.d.ts +0 -16
  191. package/dist/components/organisms/coalitions-tracker/index.js +0 -151
  192. package/dist/components/organisms/coalitions-tracker/style.module.scss.js +0 -32
  193. package/dist/components/organisms/index.d.ts +0 -2
  194. package/dist/components/organisms/ticker/gradient/index.d.ts +0 -1
  195. package/dist/components/organisms/ticker/gradient/index.js +0 -35
  196. package/dist/components/organisms/ticker/gradient/style.module.scss.js +0 -14
  197. package/dist/components/organisms/ticker/index.d.ts +0 -5
  198. package/dist/components/organisms/ticker/index.js +0 -102
  199. package/dist/components/organisms/ticker/style.module.scss.js +0 -32
  200. package/dist/components/particles/ad-slot/index.d.ts +0 -40
  201. package/dist/components/particles/ad-slot/index.js +0 -34
  202. package/dist/components/particles/ad-slot/style.module.css.js +0 -11
  203. package/dist/components/particles/arrow-button/index.d.ts +0 -6
  204. package/dist/components/particles/arrow-button/index.js +0 -32
  205. package/dist/components/particles/arrow-button/style.module.css.js +0 -11
  206. package/dist/components/particles/aspect-ratio-box/index.d.ts +0 -4
  207. package/dist/components/particles/aspect-ratio-box/index.js +0 -15
  208. package/dist/components/particles/aspect-ratio-box/style.module.css.js +0 -6
  209. package/dist/components/particles/button/index.d.ts +0 -6
  210. package/dist/components/particles/button/index.js +0 -10
  211. package/dist/components/particles/button/style.module.css.js +0 -11
  212. package/dist/components/particles/change-bar/index.d.ts +0 -8
  213. package/dist/components/particles/change-bar/index.js +0 -27
  214. package/dist/components/particles/change-bar/style.module.scss.js +0 -14
  215. package/dist/components/particles/chevron/index.d.ts +0 -6
  216. package/dist/components/particles/chevron/index.js +0 -78
  217. package/dist/components/particles/chevron/style.module.css.js +0 -20
  218. package/dist/components/particles/circle-icon/index.d.ts +0 -6
  219. package/dist/components/particles/circle-icon/index.js +0 -32
  220. package/dist/components/particles/circle-icon/style.module.css.js +0 -14
  221. package/dist/components/particles/close-button/index.d.ts +0 -5
  222. package/dist/components/particles/close-button/index.js +0 -35
  223. package/dist/components/particles/close-button/style.module.css.js +0 -17
  224. package/dist/components/particles/container/index.d.ts +0 -5
  225. package/dist/components/particles/container/index.js +0 -13
  226. package/dist/components/particles/container/style.module.scss.js +0 -11
  227. package/dist/components/particles/gradient-icon/index.d.ts +0 -1
  228. package/dist/components/particles/gradient-icon/index.js +0 -46
  229. package/dist/components/particles/gradient-icon/style.module.css.js +0 -14
  230. package/dist/components/particles/index.d.ts +0 -18
  231. package/dist/components/particles/info-button/index.d.ts +0 -3
  232. package/dist/components/particles/info-button/index.js +0 -19
  233. package/dist/components/particles/info-button/style.module.css.js +0 -11
  234. package/dist/components/particles/legend-item/index.d.ts +0 -6
  235. package/dist/components/particles/legend-item/index.js +0 -26
  236. package/dist/components/particles/legend-item/style.module.css.js +0 -17
  237. package/dist/components/particles/relative-time-sentence/index.d.ts +0 -4
  238. package/dist/components/particles/relative-time-sentence/index.js +0 -14
  239. package/dist/components/particles/relative-time-sentence/style.module.css.js +0 -8
  240. package/dist/components/particles/square-cut-corner-icon/index.d.ts +0 -6
  241. package/dist/components/particles/square-cut-corner-icon/index.js +0 -56
  242. package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +0 -17
  243. package/dist/components/particles/square-icon/index.d.ts +0 -5
  244. package/dist/components/particles/square-icon/index.js +0 -28
  245. package/dist/components/particles/square-icon/style.module.scss.js +0 -11
  246. package/dist/components/particles/stacked-bar/index.d.ts +0 -23
  247. package/dist/components/particles/stacked-bar/index.js +0 -140
  248. package/dist/components/particles/stacked-bar/style.module.css.js +0 -17
  249. package/dist/components/particles/stacked-grid/index.d.ts +0 -6
  250. package/dist/components/particles/stacked-grid/index.js +0 -35
  251. package/dist/components/particles/stacked-grid/style.module.css.js +0 -20
  252. package/dist/components/particles/waffle/index.d.ts +0 -14
  253. package/dist/components/particles/waffle/index.js +0 -76
  254. package/dist/components/particles/waffle/style.module.css.js +0 -11
  255. package/dist/index.d.ts +0 -2
  256. package/dist/index.js +0 -128
  257. package/dist/shared/colors/index.d.ts +0 -2
  258. package/dist/shared/helpers/createStore.d.ts +0 -1
  259. package/dist/shared/helpers/geometry.d.ts +0 -3
  260. package/dist/shared/helpers/geometry.js +0 -16
  261. package/dist/shared/helpers/geometry.test.d.ts +0 -1
  262. package/dist/shared/helpers/labelsUtil.d.ts +0 -54
  263. package/dist/shared/helpers/labelsUtil.js +0 -58
  264. package/dist/shared/helpers/labelsUtils.test.d.ts +0 -1
  265. package/dist/shared/helpers/shouldUpdate.d.ts +0 -7
  266. package/dist/shared/hooks/index.d.ts +0 -3
  267. package/dist/shared/hooks/useContainerSize.d.ts +0 -1
  268. package/dist/shared/hooks/useContainerSize.js +0 -24
  269. package/dist/shared/hooks/useTouchOrHover.d.ts +0 -6
  270. package/dist/shared/hooks/useTouchOrHover.js +0 -95
  271. package/dist/shared/hooks/useWindowSize.d.ts +0 -4
  272. package/dist/shared/hooks/useWindowSize.js +0 -27
  273. package/dist/styles/helpers/mergeStyles.d.ts +0 -1
  274. package/dist/styles/helpers/mergeStyles.js +0 -22
  275. package/dist/styles/helpers/mergeStyles.test.d.ts +0 -1
  276. package/dist/styles/theme.config.d.ts +0 -124
@@ -1,104 +0,0 @@
1
- import { createUid } from "./util/uid.js";
2
- import { combineExtents, containsCoordinate } from "./util/extent.js";
3
- import { geoContains } from "d3-geo";
4
- class Feature {
5
- /**
6
- * Represents a feature on the map
7
- * @constructor
8
- * @param {Object} props - The properties for the feature.
9
- * @property {string} id - The unique identifier of the feature
10
- * @property {Array} geometries - The geometries of the feature
11
- * @property {Object} properties - The properties of the feature
12
- * @property {import("./styles").Style | import("./styles").StyleFunction} style - The style of the feature
13
- */
14
- constructor({ id, geometries, properties, style }) {
15
- this.id = id;
16
- this.geometries = geometries;
17
- this.properties = properties;
18
- this.style = style;
19
- this.uid = createUid();
20
- }
21
- getExtent() {
22
- if (this._extent) return this._extent;
23
- const extent = this.geometries.reduce((combinedExtent, geometries) => {
24
- if (!combinedExtent) return geometries.extent;
25
- return combineExtents(geometries.extent, combinedExtent);
26
- }, null);
27
- this._extent = extent;
28
- return extent;
29
- }
30
- setgeometries(geometries) {
31
- this.geometries = geometries;
32
- this._extent = void 0;
33
- }
34
- getProjectedGeometries(projection) {
35
- return this.geometries.map(
36
- (d) => d.getProjected(projection, projection.revision)
37
- );
38
- }
39
- getStyleFunction() {
40
- const style = this.style;
41
- if (!style) return null;
42
- if (typeof style === "function") return style;
43
- return () => {
44
- return style;
45
- };
46
- }
47
- containsCoordinate(coordinate) {
48
- if (!containsCoordinate(this.getExtent(), coordinate)) {
49
- return false;
50
- }
51
- for (const geometries of this.geometries) {
52
- if (geoContains(geometries.getGeoJSON(), coordinate)) {
53
- return true;
54
- }
55
- }
56
- return false;
57
- }
58
- clone() {
59
- return new Feature({
60
- id: this.id,
61
- geometries: this.geometries.map((d) => d.clone()),
62
- properties: this.properties,
63
- style: this.style
64
- });
65
- }
66
- /**
67
- * Returns the geometries as a GeoJSON object
68
- * @returns {Object} The GeoJSON representation of the geometries
69
- */
70
- getGeoJSON() {
71
- const geometries = this.geometries.map((d) => d.getGeoJSON());
72
- if (geometries.length === 1) return geometries[0];
73
- return {
74
- type: "Feature",
75
- geometry: this._getGeometryGeoJSON(),
76
- properties: this.properties
77
- };
78
- }
79
- _getGeometryGeoJSON() {
80
- const geometries = this.geometries.map((d) => d.getGeoJSON());
81
- if (geometries.length === 0) throw new Error("Feature has no geometries");
82
- if (geometries.length === 1) return geometries[0];
83
- if (geometries[0].type === "Polygon") {
84
- return {
85
- type: "MultiPolygon",
86
- coordinates: geometries.map((d) => d.coordinates)
87
- };
88
- } else if (geometries[0].type === "LineString") {
89
- return {
90
- type: "MultiLineString",
91
- coordinates: geometries.map((d) => d.coordinates)
92
- };
93
- } else if (geometries[0].type === "Point") {
94
- return {
95
- type: "MultiPoint",
96
- coordinates: geometries.map((d) => d.coordinates)
97
- };
98
- }
99
- throw new Error("Could not determine geometry type");
100
- }
101
- }
102
- export {
103
- Feature
104
- };
@@ -1,20 +0,0 @@
1
- /**
2
- * Class representing a collection of map features.
3
- * @class
4
- * @property {import("./Feature").Feature[]} features - The features in the feature collection
5
- */
6
- export class FeatureCollection {
7
- /**
8
- * Create a feature collection from GeoJSON features.
9
- * @param {Object[]} geoJSON - The GeoJSON object
10
- * @returns {FeatureCollection} The feature collection
11
- */
12
- static fromGeoJSON(geoJSON: any[]): FeatureCollection;
13
- /**
14
- * Create a feature collection.
15
- * @constructor
16
- * @param {import("./Feature").Feature[]} features - The features to put in the collection
17
- */
18
- constructor(features: import('./Feature').Feature[]);
19
- features: import('./Feature').Feature[];
20
- }
@@ -1,23 +0,0 @@
1
- import { GeoJSON } from "./formats/GeoJSON.js";
2
- class FeatureCollection {
3
- /**
4
- * Create a feature collection from GeoJSON features.
5
- * @param {Object[]} geoJSON - The GeoJSON object
6
- * @returns {FeatureCollection} The feature collection
7
- */
8
- static fromGeoJSON(geoJSON) {
9
- const features = new GeoJSON().readFeaturesFromObject(geoJSON);
10
- return new FeatureCollection(features);
11
- }
12
- /**
13
- * Create a feature collection.
14
- * @constructor
15
- * @param {import("./Feature").Feature[]} features - The features to put in the collection
16
- */
17
- constructor(features) {
18
- this.features = features;
19
- }
20
- }
21
- export {
22
- FeatureCollection
23
- };
@@ -1,69 +0,0 @@
1
- import { View } from './View';
2
- import { Dispatcher } from './events';
3
- import { MapRenderer } from './renderers/MapRenderer';
4
- /**
5
- * Map component that renders into a canvas
6
- * It has built-in support for zooming and panning, as well as support for vector layers
7
- * @constructor
8
- * @param {Object} config - The configuration for the map.
9
- * @param {Object} config.view - The view configuration for the map.
10
- * @param {boolean} config.debug - Whether to enable debug mode or not.
11
- * @param {HTMLElement} config.target - The target element to render the map into.
12
- */
13
- export class Map {
14
- constructor(config: any);
15
- options: any;
16
- view: View;
17
- target: any;
18
- layers: any[];
19
- dispatcher: Dispatcher;
20
- _viewport: HTMLDivElement;
21
- _renderer: MapRenderer;
22
- _resizeObserver: ResizeObserver;
23
- destroy(): void;
24
- /** PUBLIC GETTERS */
25
- get size(): number[];
26
- get viewPort(): HTMLDivElement;
27
- get zoomScale(): any;
28
- get isTransitioning(): boolean;
29
- /** PUBLIC METHODS */
30
- collaborativeGesturesEnabled(enabled: any): any;
31
- _collaborativeGesturesEnabled: any;
32
- onFilterEvent(callback: any): void;
33
- _filterEventCallback: any;
34
- fitObject(geoJSON: any): void;
35
- addLayer(layer: any): void;
36
- addLayers(layers: any): void;
37
- setLayers(layers: any): void;
38
- removeLayer(layer: any): void;
39
- zoomIn(options: any): Promise<any>;
40
- zoomOut(options: any): Promise<any>;
41
- zoomTo(zoomScale: any, options?: {
42
- duration: number;
43
- }): Promise<any>;
44
- zoomToFeature(feature: any, focalPoint: any, padding?: {
45
- top: number;
46
- right: number;
47
- bottom: number;
48
- left: number;
49
- }): void;
50
- /** @param {import("./layers").Layer[]} layers */
51
- hasLayers(layers: import('./layers').Layer[]): boolean;
52
- resetZoom(options: any): Promise<any>;
53
- findFeatures(point: any): any[];
54
- changed(): void;
55
- transition(options: {
56
- duration: number;
57
- }, callback: any): Promise<any>;
58
- _isTransitioning: boolean;
59
- /** PRIVATE METHODS */
60
- _updateSize(): void;
61
- _size: number[];
62
- _updateViewportSize(size: any): void;
63
- _createZoomBehaviour(viewPortSize: any): void;
64
- _zoomBypassKey: string;
65
- _zoomBehaviour: any;
66
- _requestRender(): void;
67
- _animationFrameRequestID: number;
68
- _renderFrame(): void;
69
- }
@@ -1,254 +0,0 @@
1
- import { View } from "./View.js";
2
- import { sizeForElement } from "./util/size.js";
3
- import { arrayEquals } from "./util/array.js";
4
- import { containsCoordinate } from "./util/extent.js";
5
- import { MapRenderer } from "./renderers/MapRenderer.js";
6
- import { zoomIdentity, zoom } from "d3-zoom";
7
- import { select } from "d3-selection";
8
- import { timer } from "d3-timer";
9
- import { Dispatcher } from "./events/Dispatcher.js";
10
- import { MapEvent } from "./events/MapEvent.js";
11
- import "d3-transition";
12
- class Map {
13
- constructor(config) {
14
- if (config.debug) {
15
- console.log("Map config", config);
16
- }
17
- this.options = config;
18
- this.view = new View(config.view, config.debug);
19
- this.target = config.target;
20
- this.layers = [];
21
- this.dispatcher = new Dispatcher(this);
22
- this._viewport = document.createElement("div");
23
- this._viewport.className = "gv-map";
24
- this._viewport.style.position = "relative";
25
- this._viewport.style.overflow = "hidden";
26
- this._viewport.style.width = "100%";
27
- this._viewport.style.height = "100%";
28
- this.target.appendChild(this._viewport);
29
- this._renderer = new MapRenderer(this);
30
- this._resizeObserver = new ResizeObserver(() => {
31
- this._updateSize();
32
- });
33
- this._resizeObserver.observe(this.target);
34
- this._viewport.addEventListener("touchmove", (event) => {
35
- if (event.targetTouches.length < 2 && this._collaborativeGesturesEnabled) {
36
- this._filterEventCallback(true);
37
- }
38
- });
39
- }
40
- destroy() {
41
- this._resizeObserver.disconnect();
42
- this._viewport.remove();
43
- }
44
- /** PUBLIC GETTERS */
45
- get size() {
46
- return this._size;
47
- }
48
- get viewPort() {
49
- return this._viewport;
50
- }
51
- get zoomScale() {
52
- return this.view.transform.k;
53
- }
54
- get isTransitioning() {
55
- return this._isTransitioning;
56
- }
57
- /** PUBLIC METHODS */
58
- collaborativeGesturesEnabled(enabled) {
59
- if (enabled === void 0) return this._collaborativeGesturesEnabled;
60
- this._collaborativeGesturesEnabled = enabled;
61
- }
62
- onFilterEvent(callback) {
63
- this._filterEventCallback = callback;
64
- }
65
- fitObject(geoJSON) {
66
- this.view.fitObject(geoJSON);
67
- this._requestRender();
68
- }
69
- addLayer(layer) {
70
- this.addLayers([layer]);
71
- }
72
- addLayers(layers) {
73
- this.layers = this.layers.concat(layers);
74
- layers.forEach((layer) => {
75
- layer.on(MapEvent.CHANGE, () => {
76
- this._requestRender();
77
- });
78
- });
79
- this._requestRender();
80
- }
81
- setLayers(layers) {
82
- if (layers === this.layers) {
83
- return;
84
- }
85
- new Array(...this.layers).forEach((layer) => {
86
- if (!layers.includes(layer)) {
87
- this.removeLayer(layer);
88
- }
89
- });
90
- this.layers = [];
91
- this.addLayers(layers);
92
- }
93
- removeLayer(layer) {
94
- layer.tearDown();
95
- const layerIndex = this.layers.indexOf(layer);
96
- if (layerIndex < 0) return;
97
- this.layers.splice(layerIndex, 1);
98
- }
99
- async zoomIn(options) {
100
- return this.zoomTo(this.zoomScale * 2, options);
101
- }
102
- async zoomOut(options) {
103
- return this.zoomTo(this.zoomScale * 0.5, options);
104
- }
105
- async zoomTo(zoomScale, options = { duration: 500 }) {
106
- return select(this._viewport).transition().duration(options.duration).call(this._zoomBehaviour.scaleTo, zoomScale).end();
107
- }
108
- zoomToFeature(feature, focalPoint, padding = { top: 40, right: 40, bottom: 40, left: 40 }) {
109
- const extent = feature.getExtent();
110
- const [[featureX, featureY], [featureWidth, featureHeight]] = this.view.boundsForExtent(extent);
111
- const [viewPortWidth, viewPortHeight] = this.view.viewPortSize;
112
- const paddedViewPortWidth = viewPortWidth - padding.left - padding.right;
113
- const paddedViewPortHeight = viewPortHeight - padding.top - padding.bottom;
114
- const featureScale = Math.min(
115
- paddedViewPortWidth / featureWidth,
116
- paddedViewPortHeight / featureHeight
117
- );
118
- const zoomScale = Math.min(this.view.scaleExtent[1], featureScale);
119
- const scaledPadding = {
120
- top: padding.top / zoomScale,
121
- right: padding.right / zoomScale,
122
- bottom: padding.bottom / zoomScale,
123
- left: padding.left / zoomScale
124
- };
125
- const paddedFeatureBounds = {
126
- x: featureX - scaledPadding.left,
127
- y: featureY - scaledPadding.top,
128
- width: featureWidth + scaledPadding.left + scaledPadding.right,
129
- height: featureHeight + scaledPadding.top + scaledPadding.bottom
130
- };
131
- const newTransform = zoomIdentity.translate(viewPortWidth / 2, viewPortHeight / 2).scale(zoomScale).translate(
132
- -(paddedFeatureBounds.x + paddedFeatureBounds.width / 2),
133
- -(paddedFeatureBounds.y + paddedFeatureBounds.height / 2)
134
- );
135
- select(this._viewport).transition().duration(500).call(this._zoomBehaviour.transform, newTransform, focalPoint);
136
- }
137
- /** @param {import("./layers").Layer[]} layers */
138
- hasLayers(layers) {
139
- if (layers.length !== this.layers.length) {
140
- return false;
141
- }
142
- for (let i = 0; i < layers.length; i++) {
143
- if (layers[i] !== this.layers[i]) {
144
- return false;
145
- }
146
- }
147
- return true;
148
- }
149
- async resetZoom(options) {
150
- return this.zoomTo(1, options);
151
- }
152
- findFeatures(point) {
153
- const mapCoordinate = this.view.invert(point);
154
- const matchingFeatures = [];
155
- for (const layer of this.layers) {
156
- const layerExtent = layer.getExtent();
157
- if (layer.hitDetectionEnabled && containsCoordinate(layerExtent, mapCoordinate)) {
158
- const features = layer.findFeatures(mapCoordinate);
159
- if (features) {
160
- matchingFeatures.push(...features);
161
- }
162
- }
163
- }
164
- return matchingFeatures;
165
- }
166
- changed() {
167
- this._requestRender();
168
- }
169
- async transition(options = { duration: 500 }, callback) {
170
- const ease = options.ease || ((t) => t);
171
- return new Promise((resolve) => {
172
- this._isTransitioning = true;
173
- this.dispatcher.dispatch(MapEvent.TRANSITION_START);
174
- const _timer = timer((elapsed) => {
175
- const t = Math.min(elapsed / options.duration, 1);
176
- callback(ease(t));
177
- this._renderFrame();
178
- if (elapsed >= options.duration) {
179
- _timer.stop();
180
- this._isTransitioning = false;
181
- this.dispatcher.dispatch(MapEvent.TRANSITION_END);
182
- resolve();
183
- }
184
- });
185
- });
186
- }
187
- /** PRIVATE METHODS */
188
- _updateSize() {
189
- const targetElement = this.target;
190
- let newSize = sizeForElement(targetElement);
191
- const oldSize = this.size;
192
- if (newSize && (!oldSize || !arrayEquals(newSize, oldSize))) {
193
- this._size = newSize;
194
- this._updateViewportSize(newSize);
195
- }
196
- }
197
- _updateViewportSize(size) {
198
- const view = this.view;
199
- if (view) {
200
- view.viewPortSize = size;
201
- this._createZoomBehaviour(size);
202
- }
203
- this._requestRender();
204
- }
205
- _createZoomBehaviour(viewPortSize) {
206
- if (this._zoomBehaviour) {
207
- this._zoomBehaviour.on("zoom", null);
208
- }
209
- this._zoomBypassKey = navigator.userAgent.indexOf("Mac") !== -1 ? "metaKey" : "ctrlKey";
210
- this._zoomBehaviour = zoom().extent([[0, 0], viewPortSize]).translateExtent([[0, 0], viewPortSize]).scaleExtent(this.view.scaleExtent).filter((event) => {
211
- const filterEvent = (filter) => {
212
- this._filterEventCallback(filter);
213
- return !filter;
214
- };
215
- if (event.type === "wheel" && !event[this._zoomBypassKey]) {
216
- return filterEvent(true);
217
- }
218
- if ("targetTouches" in event && this.collaborativeGesturesEnabled) {
219
- if (event.targetTouches.length < 2) {
220
- return false;
221
- }
222
- event.preventDefault();
223
- return filterEvent(false);
224
- }
225
- return (!event.ctrlKey || event.type === "wheel") && !event.button;
226
- }).on("zoom", (event) => {
227
- this.view.transform = event.transform;
228
- this._requestRender();
229
- this.dispatcher.dispatch(MapEvent.ZOOM, {
230
- zoomScale: event.transform.k
231
- });
232
- });
233
- select(this._viewport).call(this._zoomBehaviour);
234
- }
235
- _requestRender() {
236
- if (!this._renderer || !!this._animationFrameRequestID || this._isTransitioning)
237
- return;
238
- this._animationFrameRequestID = requestAnimationFrame(
239
- this._renderFrame.bind(this)
240
- );
241
- }
242
- _renderFrame() {
243
- const frameState = {
244
- size: this.size,
245
- viewState: this.view.getState(),
246
- debug: this.options.debug || false
247
- };
248
- this._renderer.renderFrame(frameState);
249
- this._animationFrameRequestID = null;
250
- }
251
- }
252
- export {
253
- Map
254
- };
@@ -1,136 +0,0 @@
1
- import { ZoomTransform } from 'd3-zoom';
2
- /**
3
- * Represents how the map is viewed.
4
- * @constructor
5
- * @param {Object} options - The options for the view.
6
- * @param {Projection} options.projection - The projection to use for the view.
7
- * @param {Array} options.extent - The extent of the view in projection coordinates.
8
- * @param {number} options.minZoom - The minimum zoom level for the view.
9
- * @param {number} options.maxZoom - The maximum zoom level for the view.
10
- * @param {Object} options.padding - The padding for the view in pixels.
11
- * @param {boolean} debug - Whether to enable debug mode or not.
12
- */
13
- export class View {
14
- constructor({ projection, extent, minZoom, maxZoom, padding, }: {
15
- projection?: {
16
- (p: any): number[];
17
- invert(p: any): number[];
18
- stream(stream: any): any;
19
- postclip(_: any, ...args: any[]): any;
20
- clipExtent(_: any, ...args: any[]): any[][] | any;
21
- scale(_: any, ...args: any[]): number | any;
22
- translate(_: any, ...args: any[]): number[] | any;
23
- angle(_: any, ...args: any[]): number | any;
24
- reflectX(_: any, ...args: any[]): boolean | any;
25
- reflectY(_: any, ...args: any[]): boolean | any;
26
- fitExtent(extent: any, object: any): any;
27
- fitSize(size: any, object: any): any;
28
- fitWidth(width: any, object: any): any;
29
- fitHeight(height: any, object: any): any;
30
- };
31
- extent: any;
32
- minZoom?: number;
33
- maxZoom?: number;
34
- padding?: {
35
- top: number;
36
- right: number;
37
- bottom: number;
38
- left: number;
39
- };
40
- }, debug?: boolean);
41
- debug: boolean;
42
- projection: {
43
- (p: any): number[];
44
- invert(p: any): number[];
45
- stream(stream: any): any;
46
- postclip(_: any, ...args: any[]): any;
47
- clipExtent(_: any, ...args: any[]): any[][] | any;
48
- scale(_: any, ...args: any[]): number | any;
49
- translate(_: any, ...args: any[]): number[] | any;
50
- angle(_: any, ...args: any[]): number | any;
51
- reflectX(_: any, ...args: any[]): boolean | any;
52
- reflectY(_: any, ...args: any[]): boolean | any;
53
- fitExtent(extent: any, object: any): any;
54
- fitSize(size: any, object: any): any;
55
- fitWidth(width: any, object: any): any;
56
- fitHeight(height: any, object: any): any;
57
- };
58
- extent: any;
59
- minZoom: number;
60
- maxZoom: number;
61
- _transform: ZoomTransform;
62
- _padding: {
63
- top: number;
64
- right: number;
65
- bottom: number;
66
- left: number;
67
- };
68
- _viewPortSize: number[];
69
- pixelRatio: number;
70
- set viewPortSize(size: number[]);
71
- get viewPortSize(): number[];
72
- set transform(transform: ZoomTransform);
73
- get transform(): ZoomTransform;
74
- get mapSize(): any;
75
- get padding(): {
76
- top: number;
77
- right: number;
78
- bottom: number;
79
- left: number;
80
- };
81
- get scaledPadding(): {
82
- top: number;
83
- right: number;
84
- bottom: number;
85
- left: number;
86
- };
87
- get baseResolution(): number;
88
- get scaleExtent(): number[];
89
- setProjection(projection: any): void;
90
- setRawProjection(projection: any): void;
91
- fitExtent(extent: any): void;
92
- fitObject(geoJSON: any): void;
93
- boundsForExtent(extent: any): number[][];
94
- invert(point: any): number[];
95
- invertBounds(bounds: any): number[][];
96
- getResolution(): number;
97
- getZoomLevel(): number;
98
- /**
99
- * Function that returns the extent of the view in screen coordinates
100
- * The extent is defined as [[minX, minY], [maxX, maxY]]
101
- * @function getMapExtent
102
- * @returns {[[number, number], [number, number]]}
103
- */
104
- getMapExtent(): [[number, number], [number, number]];
105
- getVisibleExtent(transform: any, projection: any): any[];
106
- getState(): {
107
- transform: ZoomTransform;
108
- projection: {
109
- (p: any): number[];
110
- invert(p: any): number[];
111
- stream(stream: any): any;
112
- postclip(_: any, ...args: any[]): any;
113
- clipExtent(_: any, ...args: any[]): any[][] | any;
114
- scale(_: any, ...args: any[]): number | any;
115
- translate(_: any, ...args: any[]): number[] | any;
116
- angle(_: any, ...args: any[]): number | any;
117
- reflectX(_: any, ...args: any[]): boolean | any;
118
- reflectY(_: any, ...args: any[]): boolean | any;
119
- fitExtent(extent: any, object: any): any;
120
- fitSize(size: any, object: any): any;
121
- fitWidth(width: any, object: any): any;
122
- fitHeight(height: any, object: any): any;
123
- };
124
- zoomLevel: any;
125
- pixelRatio: number;
126
- padding: {
127
- top: number;
128
- right: number;
129
- bottom: number;
130
- left: number;
131
- };
132
- viewPortSize: number[];
133
- sizeInPixels: any;
134
- visibleExtent: any[];
135
- };
136
- }