react-spatial 1.5.3 → 1.5.4

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 (294) hide show
  1. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +231 -0
  2. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -0
  3. package/components/BaseLayerSwitcher/index.js +1 -0
  4. package/components/BaseLayerSwitcher/index.js.map +7 -0
  5. package/components/BasicMap/BasicMap.js +278 -0
  6. package/components/BasicMap/BasicMap.js.map +7 -0
  7. package/components/BasicMap/index.js +1 -0
  8. package/components/BasicMap/index.js.map +7 -0
  9. package/{src/components → components}/CanvasSaveButton/CanvasSaveButton.js +93 -320
  10. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -0
  11. package/components/CanvasSaveButton/index.js +1 -0
  12. package/components/CanvasSaveButton/index.js.map +7 -0
  13. package/components/Copyright/Copyright.js +55 -0
  14. package/components/Copyright/Copyright.js.map +7 -0
  15. package/components/Copyright/index.js +1 -0
  16. package/components/Copyright/index.js.map +7 -0
  17. package/components/FeatureExportButton/FeatureExportButton.js +62 -0
  18. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -0
  19. package/components/FeatureExportButton/index.js +1 -0
  20. package/components/FeatureExportButton/index.js.map +7 -0
  21. package/components/FitExtent/FitExtent.js +32 -0
  22. package/components/FitExtent/FitExtent.js.map +7 -0
  23. package/components/FitExtent/index.js +1 -0
  24. package/components/FitExtent/index.js.map +7 -0
  25. package/{src/components → components}/Geolocation/Geolocation.js +61 -144
  26. package/components/Geolocation/Geolocation.js.map +7 -0
  27. package/components/Geolocation/index.js +1 -0
  28. package/components/Geolocation/index.js.map +7 -0
  29. package/components/LayerTree/LayerTree.js +278 -0
  30. package/components/LayerTree/LayerTree.js.map +7 -0
  31. package/components/LayerTree/index.js +1 -0
  32. package/components/LayerTree/index.js.map +7 -0
  33. package/components/MousePosition/MousePosition.js +110 -0
  34. package/components/MousePosition/MousePosition.js.map +7 -0
  35. package/components/MousePosition/index.js +1 -0
  36. package/components/MousePosition/index.js.map +7 -0
  37. package/components/NorthArrow/NorthArrow.js +43 -0
  38. package/components/NorthArrow/NorthArrow.js.map +7 -0
  39. package/components/NorthArrow/index.js +1 -0
  40. package/components/NorthArrow/index.js.map +7 -0
  41. package/components/Overlay/Overlay.js +122 -0
  42. package/components/Overlay/Overlay.js.map +7 -0
  43. package/components/Overlay/index.js +1 -0
  44. package/components/Overlay/index.js.map +7 -0
  45. package/components/Permalink/Permalink.js +206 -0
  46. package/components/Permalink/Permalink.js.map +7 -0
  47. package/components/Permalink/index.js +1 -0
  48. package/components/Permalink/index.js.map +7 -0
  49. package/{src/components → components}/Popup/Popup.js +55 -165
  50. package/components/Popup/Popup.js.map +7 -0
  51. package/components/Popup/index.js +1 -0
  52. package/components/Popup/index.js.map +7 -0
  53. package/{src/components → components}/ResizeHandler/ResizeHandler.js +15 -50
  54. package/components/ResizeHandler/ResizeHandler.js.map +7 -0
  55. package/components/ResizeHandler/index.js +1 -0
  56. package/components/ResizeHandler/index.js.map +7 -0
  57. package/components/RouteSchedule/RouteSchedule.js +223 -0
  58. package/components/RouteSchedule/RouteSchedule.js.map +7 -0
  59. package/components/RouteSchedule/index.js +1 -0
  60. package/components/RouteSchedule/index.js.map +7 -0
  61. package/components/ScaleLine/ScaleLine.js +32 -0
  62. package/components/ScaleLine/ScaleLine.js.map +7 -0
  63. package/components/ScaleLine/index.js +1 -0
  64. package/components/ScaleLine/index.js.map +7 -0
  65. package/components/StopsFinder/StopsFinder.js +210 -0
  66. package/components/StopsFinder/StopsFinder.js.map +7 -0
  67. package/components/StopsFinder/StopsFinderOption.js +51 -0
  68. package/components/StopsFinder/StopsFinderOption.js.map +7 -0
  69. package/components/StopsFinder/index.js +1 -0
  70. package/components/StopsFinder/index.js.map +7 -0
  71. package/components/Zoom/Zoom.js +130 -0
  72. package/components/Zoom/Zoom.js.map +7 -0
  73. package/components/Zoom/index.js +1 -0
  74. package/components/Zoom/index.js.map +7 -0
  75. package/package.json +1 -1
  76. package/{src/propTypes.js → propTypes.js} +12 -16
  77. package/propTypes.js.map +7 -0
  78. package/{src/setupTests.js → setupTests.js} +1 -1
  79. package/setupTests.js.map +7 -0
  80. package/utils/GlobalsForOle.js +94 -0
  81. package/utils/GlobalsForOle.js.map +7 -0
  82. package/utils/KML.js +412 -0
  83. package/utils/KML.js.map +7 -0
  84. package/utils/KMLFormat.js +69 -0
  85. package/utils/KMLFormat.js.map +7 -0
  86. package/{src/utils → utils}/Styles.js +14 -20
  87. package/utils/Styles.js.map +7 -0
  88. package/{src/utils → utils}/getPolygonPattern.js +6 -34
  89. package/utils/getPolygonPattern.js.map +7 -0
  90. package/{src/utils → utils}/timeUtils.js +5 -22
  91. package/utils/timeUtils.js.map +7 -0
  92. package/.github/workflows/conventional-pr-title.yml +0 -21
  93. package/.github/workflows/main.yml +0 -28
  94. package/.husky/commit-msg +0 -4
  95. package/.husky/post-checkout +0 -4
  96. package/.husky/post-merge +0 -4
  97. package/.husky/post-rebase +0 -4
  98. package/.husky/pre-commit +0 -4
  99. package/.nvmrc +0 -1
  100. package/.whitesource +0 -8
  101. package/CHANGELOG.md +0 -65
  102. package/DEVELOP.md +0 -113
  103. package/__mocks__/mapbox-gl.js +0 -11
  104. package/__mocks__/resize-observer-polyfill.js +0 -9
  105. package/babel.config.js +0 -3
  106. package/commitlint.config.js +0 -1
  107. package/data/topic1.js +0 -119
  108. package/data/topic2.js +0 -28
  109. package/doc/README.md +0 -21
  110. package/doc/doc-config.json +0 -4
  111. package/pull_request_template.md +0 -16
  112. package/renovate.json +0 -4
  113. package/scripts/read-pkg-json.js +0 -17
  114. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -322
  115. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -69
  116. package/src/components/BaseLayerSwitcher/README.md +0 -61
  117. package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +0 -88
  118. package/src/components/BaseLayerSwitcher/index.js +0 -1
  119. package/src/components/BasicMap/BasicMap.js +0 -413
  120. package/src/components/BasicMap/BasicMap.test.js +0 -281
  121. package/src/components/BasicMap/README.md +0 -18
  122. package/src/components/BasicMap/index.js +0 -1
  123. package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -148
  124. package/src/components/CanvasSaveButton/README.md +0 -76
  125. package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +0 -76
  126. package/src/components/CanvasSaveButton/index.js +0 -1
  127. package/src/components/Copyright/Copyright.js +0 -89
  128. package/src/components/Copyright/Copyright.test.js +0 -134
  129. package/src/components/Copyright/README.md +0 -36
  130. package/src/components/Copyright/index.js +0 -1
  131. package/src/components/FeatureExportButton/FeatureExportButton.js +0 -118
  132. package/src/components/FeatureExportButton/FeatureExportButton.test.js +0 -417
  133. package/src/components/FeatureExportButton/README.md +0 -76
  134. package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +0 -67
  135. package/src/components/FeatureExportButton/index.js +0 -1
  136. package/src/components/FitExtent/FitExtent.js +0 -62
  137. package/src/components/FitExtent/FitExtent.test.js +0 -48
  138. package/src/components/FitExtent/README.md +0 -34
  139. package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +0 -13
  140. package/src/components/FitExtent/index.js +0 -1
  141. package/src/components/Geolocation/Geolocation.test.js +0 -267
  142. package/src/components/Geolocation/README.md +0 -25
  143. package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +0 -92
  144. package/src/components/Geolocation/index.js +0 -1
  145. package/src/components/LayerTree/LayerTree.js +0 -487
  146. package/src/components/LayerTree/LayerTree.test.js +0 -337
  147. package/src/components/LayerTree/README.md +0 -92
  148. package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +0 -1746
  149. package/src/components/LayerTree/index.js +0 -1
  150. package/src/components/MousePosition/MousePosition.js +0 -175
  151. package/src/components/MousePosition/MousePosition.test.js +0 -132
  152. package/src/components/MousePosition/README.md +0 -50
  153. package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +0 -76
  154. package/src/components/MousePosition/index.js +0 -1
  155. package/src/components/NorthArrow/NorthArrow.js +0 -75
  156. package/src/components/NorthArrow/NorthArrow.test.js +0 -104
  157. package/src/components/NorthArrow/README.md +0 -59
  158. package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +0 -117
  159. package/src/components/NorthArrow/index.js +0 -1
  160. package/src/components/Overlay/Overlay.js +0 -176
  161. package/src/components/Overlay/Overlay.test.js +0 -149
  162. package/src/components/Overlay/README.md +0 -59
  163. package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +0 -9
  164. package/src/components/Overlay/index.js +0 -1
  165. package/src/components/Permalink/Permalink.js +0 -326
  166. package/src/components/Permalink/Permalink.test.js +0 -285
  167. package/src/components/Permalink/README.md +0 -105
  168. package/src/components/Permalink/index.js +0 -1
  169. package/src/components/Popup/Popup.test.js +0 -307
  170. package/src/components/Popup/README.md +0 -93
  171. package/src/components/Popup/__snapshots__/Popup.test.js.snap +0 -180
  172. package/src/components/Popup/index.js +0 -1
  173. package/src/components/README.md +0 -41
  174. package/src/components/ResizeHandler/ResizeHandler.test.js +0 -344
  175. package/src/components/ResizeHandler/index.js +0 -1
  176. package/src/components/RouteSchedule/README.md +0 -118
  177. package/src/components/RouteSchedule/RouteSchedule.js +0 -370
  178. package/src/components/RouteSchedule/RouteSchedule.test.js +0 -113
  179. package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +0 -248
  180. package/src/components/RouteSchedule/index.js +0 -1
  181. package/src/components/ScaleLine/README.md +0 -29
  182. package/src/components/ScaleLine/ScaleLine.js +0 -50
  183. package/src/components/ScaleLine/ScaleLine.test.js +0 -30
  184. package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +0 -7
  185. package/src/components/ScaleLine/index.js +0 -1
  186. package/src/components/StopsFinder/README.md +0 -50
  187. package/src/components/StopsFinder/StopsFinder.js +0 -284
  188. package/src/components/StopsFinder/StopsFinder.test.js +0 -17
  189. package/src/components/StopsFinder/StopsFinderOption.js +0 -61
  190. package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +0 -133
  191. package/src/components/StopsFinder/index.js +0 -1
  192. package/src/components/Zoom/README.md +0 -25
  193. package/src/components/Zoom/Zoom.js +0 -180
  194. package/src/components/Zoom/Zoom.test.js +0 -141
  195. package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +0 -201
  196. package/src/components/Zoom/index.js +0 -1
  197. package/src/styleguidist/ComponentsList.js +0 -52
  198. package/src/styleguidist/StyleGuide.js +0 -277
  199. package/src/styleguidist/styleguidist.css +0 -38
  200. package/src/utils/GlobalsForOle.js +0 -99
  201. package/src/utils/KML.js +0 -594
  202. package/src/utils/KML.test.js +0 -337
  203. package/src/utils/KMLFormat.js +0 -100
  204. package/src/utils/KMLFormat.test.js +0 -50
  205. package/src/utils/__snapshots__/KML.test.js.snap.KML-readFeatures()-and-writeFeatures()-should-read-and-write-lineDash-and-fillPattern-style-for-polygon.canvas-image.png +0 -0
  206. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
  207. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-3-(diagonal-line-from-bottom-left-tot-top-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  208. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-4-(diagonal-line-from-top-left-to-bottom-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  209. package/src/utils/getPolygonPattern.test.js +0 -61
  210. package/src/utils/timeUtils.test.js +0 -30
  211. package/styleguide.config.js +0 -251
  212. /package/{src/components → components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
  213. /package/{src/components → components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
  214. /package/{src/components → components}/BasicMap/BasicMap.md.scss +0 -0
  215. /package/{src/components → components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
  216. /package/{src/components → components}/Copyright/Copyright.md.scss +0 -0
  217. /package/{src/components → components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
  218. /package/{src/components → components}/FitExtent/FitExtent.md.scss +0 -0
  219. /package/{src/components → components}/Geolocation/Geolocation.md.scss +0 -0
  220. /package/{src/components → components}/Geolocation/Geolocation.scss +0 -0
  221. /package/{src/components → components}/LayerTree/LayerTree.md.scss +0 -0
  222. /package/{src/components → components}/LayerTree/LayerTree.scss +0 -0
  223. /package/{src/components → components}/MousePosition/MousePosition.md.scss +0 -0
  224. /package/{src/components → components}/NorthArrow/NorthArrow.scss +0 -0
  225. /package/{src/components → components}/Overlay/Overlay.md.scss +0 -0
  226. /package/{src/components → components}/Overlay/Overlay.scss +0 -0
  227. /package/{src/components → components}/Permalink/Permalink.md.scss +0 -0
  228. /package/{src/components → components}/Popup/Popup.md.scss +0 -0
  229. /package/{src/components → components}/Popup/Popup.scss +0 -0
  230. /package/{src/components → components}/RouteSchedule/RouteSchedule.md.scss +0 -0
  231. /package/{src/components → components}/RouteSchedule/RouteSchedule.scss +0 -0
  232. /package/{src/components → components}/ScaleLine/ScaleLine.scss +0 -0
  233. /package/{src/components → components}/Zoom/Zoom.md.scss +0 -0
  234. /package/{src/components → components}/Zoom/Zoom.scss +0 -0
  235. /package/{src/images → images}/RouteSchedule/firstStation.png +0 -0
  236. /package/{src/images → images}/RouteSchedule/lastStation.png +0 -0
  237. /package/{src/images → images}/RouteSchedule/line.png +0 -0
  238. /package/{src/images → images}/RouteSchedule/station.png +0 -0
  239. /package/{src/images → images}/baselayer/baselayer.basebright.png +0 -0
  240. /package/{src/images → images}/baselayer/baselayer.osm.png +0 -0
  241. /package/{src/images → images}/baselayer/baselayer.travic.png +0 -0
  242. /package/{src/images → images}/baselayer/open.topo.map.png +0 -0
  243. /package/{src/images → images}/baselayer/osm.baselayer.hot.png +0 -0
  244. /package/{src/images → images}/baselayer/osm.baselayer.png +0 -0
  245. /package/{src/images → images}/favicon.png +0 -0
  246. /package/{src/images → images}/geops_logo.png +0 -0
  247. /package/{src/images → images}/geops_logo.svg +0 -0
  248. /package/{src/images → images}/geops_qr.png +0 -0
  249. /package/{src/images → images}/mots/bus_poi-blue-01.svg +0 -0
  250. /package/{src/images → images}/mots/bus_poi-grey-01.svg +0 -0
  251. /package/{src/images → images}/mots/bus_round-blue-01.svg +0 -0
  252. /package/{src/images → images}/mots/bus_round-grey-01.svg +0 -0
  253. /package/{src/images → images}/mots/bus_square-blue-01.svg +0 -0
  254. /package/{src/images → images}/mots/bus_square-grey-01.svg +0 -0
  255. /package/{src/images → images}/mots/cable_car_poi-blue-01.svg +0 -0
  256. /package/{src/images → images}/mots/cable_car_poi-grey-01.svg +0 -0
  257. /package/{src/images → images}/mots/cable_car_round-blue-01.svg +0 -0
  258. /package/{src/images → images}/mots/cable_car_round-grey-01.svg +0 -0
  259. /package/{src/images → images}/mots/cable_car_square-blue-01.svg +0 -0
  260. /package/{src/images → images}/mots/cable_car_square-grey-01.svg +0 -0
  261. /package/{src/images → images}/mots/ferry_poi-blue-01.svg +0 -0
  262. /package/{src/images → images}/mots/ferry_poi-grey-01.svg +0 -0
  263. /package/{src/images → images}/mots/ferry_round-blue-01.svg +0 -0
  264. /package/{src/images → images}/mots/ferry_round-grey-01.svg +0 -0
  265. /package/{src/images → images}/mots/ferry_square-blue-01.svg +0 -0
  266. /package/{src/images → images}/mots/ferry_square-grey-01.svg +0 -0
  267. /package/{src/images → images}/mots/funicular_round-blue-01.svg +0 -0
  268. /package/{src/images → images}/mots/funicular_round-grey-01.svg +0 -0
  269. /package/{src/images → images}/mots/funicular_square-blue-01.svg +0 -0
  270. /package/{src/images → images}/mots/gondola_round-blue-01.svg +0 -0
  271. /package/{src/images → images}/mots/rail_poi-blue-01.svg +0 -0
  272. /package/{src/images → images}/mots/rail_poi-grey-01.svg +0 -0
  273. /package/{src/images → images}/mots/rail_round-blue-01.svg +0 -0
  274. /package/{src/images → images}/mots/rail_round-grey-01.svg +0 -0
  275. /package/{src/images → images}/mots/rail_square-blue-01.svg +0 -0
  276. /package/{src/images → images}/mots/rail_square-grey-01.svg +0 -0
  277. /package/{src/images → images}/mots/subway_round blue-01.svg +0 -0
  278. /package/{src/images → images}/mots/subway_round-blue-01.svg +0 -0
  279. /package/{src/images → images}/mots/tram_poi-blue-01.svg +0 -0
  280. /package/{src/images → images}/mots/tram_poi-grey-01.svg +0 -0
  281. /package/{src/images → images}/mots/tram_round-blue-01.svg +0 -0
  282. /package/{src/images → images}/mots/tram_round-grey-01.svg +0 -0
  283. /package/{src/images → images}/mots/tram_square-blue-01.svg +0 -0
  284. /package/{src/images → images}/mots/tram_square-grey-01.svg +0 -0
  285. /package/{src/images → images}/northArrow.svg +0 -0
  286. /package/{src/images → images}/northArrow.url.svg +0 -0
  287. /package/{src/images → images}/northArrowCircle.svg +0 -0
  288. /package/{src/images → images}/northArrowCircle.url.svg +0 -0
  289. /package/{src/themes → themes}/README.md +0 -0
  290. /package/{src/themes → themes}/default/components.scss +0 -0
  291. /package/{src/themes → themes}/default/examples.scss +0 -0
  292. /package/{src/themes → themes}/default/index.scss +0 -0
  293. /package/{src/themes → themes}/default/mixins.scss +0 -0
  294. /package/{src/themes → themes}/default/variables.scss +0 -0
@@ -1,114 +1,26 @@
1
- /* eslint-disable no-param-reassign */
2
- import React, { PureComponent } from 'react';
3
- import PropTypes from 'prop-types';
4
- import OLMap from 'ol/Map';
5
- import { getTopLeft, getBottomRight } from 'ol/extent';
6
- import NorthArrowSimple from '../../images/northArrow.url.svg';
7
- import NorthArrowCircle from '../../images/northArrowCircle.url.svg';
8
-
1
+ import React, { PureComponent } from "react";
2
+ import PropTypes from "prop-types";
3
+ import OLMap from "ol/Map";
4
+ import { getTopLeft, getBottomRight } from "ol/extent";
5
+ import NorthArrowSimple from "../../images/northArrow.url.svg";
6
+ import NorthArrowCircle from "../../images/northArrowCircle.url.svg";
9
7
  const extraDataImgPropType = PropTypes.shape({
10
8
  src: PropTypes.string,
11
9
  width: PropTypes.number,
12
10
  height: PropTypes.number,
13
11
  rotation: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
14
- circled: PropTypes.bool,
12
+ circled: PropTypes.bool
15
13
  });
16
-
17
14
  const propTypes = {
18
- /**
19
- * Automatically download the image saved.
20
- */
21
15
  autoDownload: PropTypes.bool,
22
-
23
- /**
24
- * Children content of the button.
25
- */
26
16
  children: PropTypes.node,
27
-
28
- /**
29
- * Output format of the image.
30
- */
31
- format: PropTypes.oneOf(['image/jpeg', 'image/png']),
32
-
33
- /** An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html). */
17
+ format: PropTypes.oneOf(["image/jpeg", "image/png"]),
34
18
  map: PropTypes.instanceOf(OLMap),
35
-
36
- /**
37
- * Extent for the export. If no extent is given, the whole map is exported.
38
- */
39
19
  extent: PropTypes.arrayOf(PropTypes.number),
40
-
41
- /**
42
- * Array of 4 [ol/Coordinate](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~Coordinate).
43
- * If no coordinates and no extent are given, the whole map is exported.
44
- * This property must be used to export rotated map.
45
- * If you don't need to export rotated map the extent property can be used as well.
46
- * If extent is specified, coordinates property is ignored.
47
- */
48
20
  coordinates: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
49
-
50
- /**
51
- * Scale the map for better quality. Possible values: 1, 2 or 3.
52
- * WARNING: The tiled layer with a WMTS or XYZ source must provides an url
53
- * for each scale in the config file.
54
- */
55
21
  scale: PropTypes.number,
56
-
57
- /**
58
- * Function called before the dowload process begins.
59
- */
60
22
  onSaveStart: PropTypes.func,
61
-
62
- /**
63
- * Function called after the dowload process ends.
64
- *
65
- * @param {object} error Error message the process fails.
66
- */
67
23
  onSaveEnd: PropTypes.func,
68
-
69
- /**
70
- * Extra data, such as copyright, north arrow configuration.
71
- * All extra data is optional.
72
- *
73
- * Example 1:
74
- *
75
- {
76
- copyright: {
77
- text: 'Example copyright', // Copyright text or function
78
- font: '10px Arial', // Font, default is '12px Arial'
79
- fillStyle: 'blue', // Fill style, default is 'black'
80
- },
81
- northArrow, // True if the north arrow
82
- // should be placed with default configuration
83
- // (default image, rotation=0, circled=false)
84
- }
85
- * Example 2:
86
- *
87
- {
88
- northArrow: {
89
- src: NorthArrowCustom,
90
- width: 60, // Width in px, default is 80
91
- height: 100, // Height in px, default is 80
92
- rotation: 25, // Absolute rotation in degrees as number or function
93
-
94
- }
95
- }
96
- * Example 3:
97
- *
98
- {
99
- copyright: {
100
- text: () => { // Copyright as function
101
- return this.copyright;
102
- },
103
- },
104
- northArrow: {
105
- rotation: () => { // Rotation as function
106
- return NorthArrow.radToDeg(this.map.getView().getRotation());
107
- },
108
- circled, // Display circle around the north arrow (Does not work for custom src)
109
- },
110
- }
111
- */
112
24
  extraData: PropTypes.shape({
113
25
  logo: extraDataImgPropType,
114
26
  northArrow: extraDataImgPropType,
@@ -118,18 +30,17 @@ const propTypes = {
118
30
  font: PropTypes.string,
119
31
  fillStyle: PropTypes.oneOfType([
120
32
  PropTypes.string,
121
- PropTypes.instanceOf(CanvasPattern),
33
+ PropTypes.instanceOf(CanvasPattern)
122
34
  ]),
123
- background: PropTypes.bool,
124
- }),
125
- }),
35
+ background: PropTypes.bool
36
+ })
37
+ })
126
38
  };
127
-
128
39
  const defaultProps = {
129
40
  autoDownload: true,
130
41
  children: null,
131
42
  map: null,
132
- format: 'image/png',
43
+ format: "image/png",
133
44
  extent: null,
134
45
  extraData: null,
135
46
  coordinates: null,
@@ -137,169 +48,113 @@ const defaultProps = {
137
48
  onSaveStart: (map) => {
138
49
  return Promise.resolve(map);
139
50
  },
140
- onSaveEnd: () => {},
51
+ onSaveEnd: () => {
52
+ }
141
53
  };
142
-
143
- /**
144
- * The CanvasSaveButton component creates a button to save
145
- * an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)
146
- * canvas as an image.
147
- */
148
54
  class CanvasSaveButton extends PureComponent {
149
55
  constructor(props) {
150
56
  super(props);
151
57
  this.padding = 5;
152
58
  }
153
-
154
59
  static getMargin(destCanvas) {
155
- const newMargin = destCanvas.width / 100; // 1% of the canvas width
60
+ const newMargin = destCanvas.width / 100;
156
61
  return newMargin;
157
62
  }
158
-
159
63
  onClick(evt) {
160
64
  const { map, onSaveStart, onSaveEnd, autoDownload } = this.props;
161
65
  if (window.navigator.msSaveBlob) {
162
- // ie only
163
66
  evt.preventDefault();
164
67
  evt.stopPropagation();
165
68
  }
166
69
  onSaveStart(map).then((mapToExport) => {
167
- return this.createCanvasImage(mapToExport || map)
168
- .then((canvas) => {
169
- if (autoDownload) {
170
- this.downloadCanvasImage(canvas).then((blob) => {
171
- onSaveEnd(mapToExport, canvas, blob);
172
- });
173
- } else {
174
- onSaveEnd(mapToExport, canvas);
175
- }
176
- })
177
- .catch((err) => {
178
- if (err) {
179
- // eslint-disable-next-line no-console
180
- console.error(err);
181
- }
182
- onSaveEnd(mapToExport, err);
183
- });
70
+ return this.createCanvasImage(mapToExport || map).then((canvas) => {
71
+ if (autoDownload) {
72
+ this.downloadCanvasImage(canvas).then((blob) => {
73
+ onSaveEnd(mapToExport, canvas, blob);
74
+ });
75
+ } else {
76
+ onSaveEnd(mapToExport, canvas);
77
+ }
78
+ }).catch((err) => {
79
+ if (err) {
80
+ console.error(err);
81
+ }
82
+ onSaveEnd(mapToExport, err);
83
+ });
184
84
  });
185
85
  }
186
-
187
86
  getDownloadImageName() {
188
87
  const { format } = this.props;
189
- const fileExt = format === 'image/jpeg' ? 'jpg' : 'png';
190
- return (
191
- `${window.document.title.replace(/ /g, '_').toLowerCase()}` +
192
- `.${fileExt}`
193
- );
88
+ const fileExt = format === "image/jpeg" ? "jpg" : "png";
89
+ return `${window.document.title.replace(/ /g, "_").toLowerCase()}.${fileExt}`;
194
90
  }
195
-
196
- // Ensure the font size fita with the image width.
197
91
  decreaseFontSize(destContext, maxWidth, copyright, scale) {
198
92
  const minFontSize = 8;
199
93
  let sizeMatch;
200
94
  let fontSize;
201
95
  do {
202
96
  sizeMatch = destContext.font.match(/[0-9]+(?:\.[0-9]+)?(px)/i);
203
- fontSize = parseInt(sizeMatch[0].replace(sizeMatch[1], ''), 10);
204
-
205
- // eslint-disable-next-line no-param-reassign
97
+ fontSize = parseInt(sizeMatch[0].replace(sizeMatch[1], ""), 10);
206
98
  destContext.font = destContext.font.replace(fontSize, fontSize - 1);
207
-
208
99
  if (fontSize - 1 === minFontSize) {
209
100
  this.multilineCopyright = true;
210
101
  }
211
- } while (
212
- fontSize - 1 > minFontSize &&
213
- destContext.measureText(copyright).width * scale > maxWidth
214
- );
215
-
102
+ } while (fontSize - 1 > minFontSize && destContext.measureText(copyright).width * scale > maxWidth);
216
103
  return destContext.font;
217
104
  }
218
-
219
- // eslint-disable-next-line class-methods-use-this
220
- drawTextBackground(
221
- destContext,
222
- textMeasure,
223
- textX,
224
- textY,
225
- padding,
226
- styleOptions = {},
227
- ) {
228
- /// get width of text
105
+ drawTextBackground(destContext, textMeasure, textX, textY, padding, styleOptions = {}) {
229
106
  const { width, height, actualBoundingBoxAscent } = textMeasure;
230
107
  destContext.save();
231
- // Dflt is a white background
232
- destContext.fillStyle = 'rgba(255,255,255,.8)';
233
-
234
- // To simplify usability the user could pass a boolean to use only default values.
235
- if (typeof styleOptions === 'object') {
108
+ destContext.fillStyle = "rgba(255,255,255,.8)";
109
+ if (typeof styleOptions === "object") {
236
110
  Object.entries(styleOptions).forEach(([key, value]) => {
237
111
  destContext[key] = value;
238
112
  });
239
113
  }
240
-
241
- /// draw background rect assuming height of font
242
114
  destContext.fillRect(
243
115
  textX - padding,
244
116
  textY - actualBoundingBoxAscent - padding,
245
117
  width + padding * 2,
246
- height + padding * 2,
118
+ height + padding * 2
247
119
  );
248
120
  destContext.restore();
249
121
  }
250
-
251
122
  drawCopyright(destContext, destCanvas, maxWidth) {
252
123
  const { extraData, scale } = this.props;
253
124
  const { text, font, fillStyle, background } = extraData.copyright;
254
- let copyright = typeof text === 'function' ? text() : text;
255
-
125
+ let copyright = typeof text === "function" ? text() : text;
256
126
  if (Array.isArray(copyright)) {
257
127
  copyright = copyright.join();
258
128
  }
259
-
260
129
  destContext.save();
261
130
  destContext.scale(scale, scale);
262
- destContext.font = font || '12px Arial';
131
+ destContext.font = font || "12px Arial";
263
132
  destContext.font = this.decreaseFontSize(
264
133
  destContext,
265
134
  maxWidth - this.padding,
266
135
  copyright,
267
- scale,
136
+ scale
268
137
  );
269
-
270
138
  destContext.scale(scale, scale);
271
- destContext.fillStyle = fillStyle || 'black';
272
-
273
- // We search if the display on 2 line is necessary
139
+ destContext.fillStyle = fillStyle || "black";
274
140
  let firstLine = copyright;
275
- const wordNumber = copyright.split(' ').length;
276
-
277
- // If the text is bigger than the max width we split it into 2 lines
141
+ const wordNumber = copyright.split(" ").length;
278
142
  if (this.multilineCopyright) {
279
143
  for (let i = 0; i < wordNumber; i += 1) {
280
- firstLine = firstLine.substring(0, firstLine.lastIndexOf(' '));
281
- // Stop removing word when fits within one line.
282
- if (
283
- destContext.measureText(firstLine).width * scale <
284
- maxWidth - this.padding
285
- ) {
144
+ firstLine = firstLine.substring(0, firstLine.lastIndexOf(" "));
145
+ if (destContext.measureText(firstLine).width * scale < maxWidth - this.padding) {
286
146
  break;
287
147
  }
288
148
  }
289
149
  }
290
- const secondLine = copyright.replace(firstLine, '');
291
-
292
- // Draw first line (line break isn't supported for fillText).
150
+ const secondLine = copyright.replace(firstLine, "");
293
151
  const textX = this.margin;
294
152
  let textMeasure = destContext.measureText(firstLine);
295
- textMeasure.height =
296
- textMeasure.actualBoundingBoxAscent +
297
- textMeasure.actualBoundingBoxDescent;
153
+ textMeasure.height = textMeasure.actualBoundingBoxAscent + textMeasure.actualBoundingBoxDescent;
298
154
  let firstLineY = destCanvas.height / scale - this.padding;
299
155
  const secondLineY = firstLineY;
300
156
  const paddingBetweenLines = 3;
301
157
  const paddingBackground = paddingBetweenLines / 2;
302
-
303
158
  if (secondLine) {
304
159
  firstLineY -= textMeasure.height + paddingBetweenLines;
305
160
  }
@@ -310,17 +165,13 @@ class CanvasSaveButton extends PureComponent {
310
165
  textX,
311
166
  firstLineY,
312
167
  paddingBackground,
313
- background,
168
+ background
314
169
  );
315
170
  }
316
171
  destContext.fillText(firstLine, textX, firstLineY);
317
-
318
- // Draw second line.
319
172
  if (secondLine) {
320
173
  textMeasure = destContext.measureText(secondLine);
321
- textMeasure.height =
322
- textMeasure.actualBoundingBoxAscent +
323
- textMeasure.actualBoundingBoxDescent;
174
+ textMeasure.height = textMeasure.actualBoundingBoxAscent + textMeasure.actualBoundingBoxDescent;
324
175
  if (background) {
325
176
  this.drawTextBackground(
326
177
  destContext,
@@ -328,155 +179,109 @@ class CanvasSaveButton extends PureComponent {
328
179
  textX,
329
180
  secondLineY,
330
181
  paddingBackground,
331
- background,
182
+ background
332
183
  );
333
184
  }
334
185
  destContext.fillText(secondLine, textX, secondLineY);
335
186
  }
336
-
337
187
  const firstLineMetrics = destContext.measureText(firstLine);
338
188
  const secondLineMetrics = destContext.measureText(secondLine);
339
- const heightFirstLine =
340
- firstLineMetrics.actualBoundingBoxAscent +
341
- firstLineMetrics.actualBoundingBoxDescent;
342
- const heightSecondLine =
343
- secondLineMetrics.actualBoundingBoxAscent +
344
- secondLineMetrics.actualBoundingBoxDescent;
345
- this.copyrightY =
346
- destCanvas.height -
347
- (heightFirstLine + paddingBetweenLines + heightSecondLine) / 2;
189
+ const heightFirstLine = firstLineMetrics.actualBoundingBoxAscent + firstLineMetrics.actualBoundingBoxDescent;
190
+ const heightSecondLine = secondLineMetrics.actualBoundingBoxAscent + secondLineMetrics.actualBoundingBoxDescent;
191
+ this.copyrightY = destCanvas.height - (heightFirstLine + paddingBetweenLines + heightSecondLine) / 2;
348
192
  destContext.restore();
349
193
  }
350
-
351
- drawElement(data, destCanvas, previousItemSize = [0, 0], side = 'right') {
352
- const destContext = destCanvas.getContext('2d');
194
+ drawElement(data, destCanvas, previousItemSize = [0, 0], side = "right") {
195
+ const destContext = destCanvas.getContext("2d");
353
196
  const { scale } = this.props;
354
197
  const { src, width, height, rotation } = data;
355
-
356
198
  return new Promise((resolve) => {
357
199
  const img = new Image();
358
- img.crossOrigin = 'Anonymous';
200
+ img.crossOrigin = "Anonymous";
359
201
  img.src = src;
360
202
  img.onload = () => {
361
203
  destContext.save();
362
204
  const elementWidth = (width || 80) * scale;
363
205
  const elementHeight = (height || 80) * scale;
364
- const left =
365
- side === 'left'
366
- ? this.margin + elementWidth / 2
367
- : destCanvas.width - this.margin - elementWidth / 2;
368
- const top =
369
- (side === 'left' && this.copyrightY
370
- ? this.copyrightY - 2 * this.padding
371
- : destCanvas.height) -
372
- this.margin -
373
- elementHeight / 2 -
374
- previousItemSize[1];
375
-
206
+ const left = side === "left" ? this.margin + elementWidth / 2 : destCanvas.width - this.margin - elementWidth / 2;
207
+ const top = (side === "left" && this.copyrightY ? this.copyrightY - 2 * this.padding : destCanvas.height) - this.margin - elementHeight / 2 - previousItemSize[1];
376
208
  destContext.translate(left, top);
377
-
378
209
  if (rotation) {
379
- const angle = typeof rotation === 'function' ? rotation() : rotation;
210
+ const angle = typeof rotation === "function" ? rotation() : rotation;
380
211
  destContext.rotate(angle * (Math.PI / 180));
381
212
  }
382
-
383
213
  destContext.drawImage(
384
214
  img,
385
215
  -elementWidth / 2,
386
216
  -elementHeight / 2,
387
217
  elementWidth,
388
- elementHeight,
218
+ elementHeight
389
219
  );
390
220
  destContext.restore();
391
-
392
- // Return the pixels width of the arrow and the margin right,
393
- // that must not be occupied by the copyright.
394
221
  resolve([
395
222
  elementWidth + 2 * this.padding,
396
- elementHeight + 2 * this.padding,
223
+ elementHeight + 2 * this.padding
397
224
  ]);
398
225
  };
399
-
400
226
  img.onerror = () => {
401
227
  resolve();
402
228
  };
403
229
  });
404
230
  }
405
-
406
231
  calculatePixelsToExport(mapToExport) {
407
232
  const { extent, coordinates } = this.props;
408
233
  let firstCoordinate;
409
234
  let oppositeCoordinate;
410
-
411
235
  if (extent) {
412
236
  firstCoordinate = getTopLeft(extent);
413
237
  oppositeCoordinate = getBottomRight(extent);
414
238
  } else if (coordinates) {
415
- // In case of coordinates coming from DragBox interaction:
416
- // firstCoordinate is the first coordinate drawn by the user.
417
- // oppositeCoordinate is the coordinate of the point dragged by the user.
418
239
  [firstCoordinate, , oppositeCoordinate] = coordinates;
419
240
  }
420
-
421
241
  if (firstCoordinate && oppositeCoordinate) {
422
242
  const firstPixel = mapToExport.getPixelFromCoordinate(firstCoordinate);
423
- const oppositePixel =
424
- mapToExport.getPixelFromCoordinate(oppositeCoordinate);
243
+ const oppositePixel = mapToExport.getPixelFromCoordinate(oppositeCoordinate);
425
244
  const pixelTopLeft = [
426
245
  firstPixel[0] <= oppositePixel[0] ? firstPixel[0] : oppositePixel[0],
427
- firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1],
246
+ firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1]
428
247
  ];
429
248
  const pixelBottomRight = [
430
249
  firstPixel[0] > oppositePixel[0] ? firstPixel[0] : oppositePixel[0],
431
- firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1],
250
+ firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1]
432
251
  ];
433
-
434
252
  return {
435
253
  x: pixelTopLeft[0],
436
254
  y: pixelTopLeft[1],
437
255
  w: pixelBottomRight[0] - pixelTopLeft[0],
438
- h: pixelBottomRight[1] - pixelTopLeft[1],
256
+ h: pixelBottomRight[1] - pixelTopLeft[1]
439
257
  };
440
258
  }
441
259
  return null;
442
260
  }
443
-
444
261
  createCanvasImage(mapToExport) {
445
262
  const { extraData } = this.props;
446
-
447
263
  return new Promise((resolve) => {
448
- mapToExport.once('rendercomplete', () => {
449
- // Find all layer canvases and add it to dest canvas.
450
- const canvases = mapToExport
451
- .getTargetElement()
452
- .getElementsByTagName('canvas');
453
-
454
- // Create the canvas to export with the good size.
264
+ mapToExport.once("rendercomplete", () => {
265
+ const canvases = mapToExport.getTargetElement().getElementsByTagName("canvas");
455
266
  let destCanvas;
456
267
  let destContext;
457
-
458
- // canvases is an HTMLCollection, we don't try to transform to array because some compilers like cra doesn't translate it right.
459
268
  for (let i = 0; i < canvases.length; i += 1) {
460
269
  const canvas = canvases[i];
461
270
  if (!canvas.width || !canvas.height) {
462
- // eslint-disable-next-line no-continue
463
271
  continue;
464
272
  }
465
273
  const clip = this.calculatePixelsToExport(mapToExport) || {
466
274
  x: 0,
467
275
  y: 0,
468
276
  w: canvas.width,
469
- h: canvas.height,
277
+ h: canvas.height
470
278
  };
471
-
472
279
  if (!destCanvas) {
473
- destCanvas = document.createElement('canvas');
280
+ destCanvas = document.createElement("canvas");
474
281
  destCanvas.width = clip.w;
475
282
  destCanvas.height = clip.h;
476
- destContext = destCanvas.getContext('2d');
283
+ destContext = destCanvas.getContext("2d");
477
284
  }
478
-
479
- // Draw canvas to the canvas to export.
480
285
  destContext.drawImage(
481
286
  canvas,
482
287
  clip.x,
@@ -486,46 +291,30 @@ class CanvasSaveButton extends PureComponent {
486
291
  0,
487
292
  0,
488
293
  destCanvas.width,
489
- destCanvas.height,
294
+ destCanvas.height
490
295
  );
491
296
  }
492
-
493
297
  this.margin = CanvasSaveButton.getMargin(destCanvas);
494
-
495
- // Custom info
496
298
  let logoPromise = Promise.resolve();
497
299
  if (destContext && extraData && extraData.logo) {
498
300
  logoPromise = this.drawElement(extraData.logo, destCanvas);
499
301
  }
500
-
501
302
  logoPromise.then((logoSize = [0, 0]) => {
502
- // North arrow
503
303
  let arrowPromise = Promise.resolve();
504
304
  if (destContext && extraData && extraData.northArrow) {
505
305
  arrowPromise = this.drawElement(
506
306
  {
507
- src: extraData.northArrow.circled
508
- ? NorthArrowCircle
509
- : NorthArrowSimple,
510
- ...extraData.northArrow,
307
+ src: extraData.northArrow.circled ? NorthArrowCircle : NorthArrowSimple,
308
+ ...extraData.northArrow
511
309
  },
512
310
  destCanvas,
513
- logoSize,
311
+ logoSize
514
312
  );
515
313
  }
516
-
517
- // Copyright
518
314
  arrowPromise.then((arrowSize = [0, 0]) => {
519
315
  const widestElement = Math.max(logoSize[0], arrowSize[0]);
520
- if (
521
- destContext &&
522
- extraData &&
523
- extraData.copyright &&
524
- extraData.copyright.text
525
- ) {
526
- const maxWidth = widestElement
527
- ? destContext.canvas.width - widestElement - this.margin
528
- : destContext.canvas.width;
316
+ if (destContext && extraData && extraData.copyright && extraData.copyright.text) {
317
+ const maxWidth = widestElement ? destContext.canvas.width - widestElement - this.margin : destContext.canvas.width;
529
318
  this.drawCopyright(destContext, destCanvas, maxWidth);
530
319
  }
531
320
  let qrCodePromise = Promise.resolve();
@@ -533,8 +322,8 @@ class CanvasSaveButton extends PureComponent {
533
322
  qrCodePromise = this.drawElement(
534
323
  extraData.qrCode,
535
324
  destCanvas,
536
- undefined,
537
- 'left',
325
+ void 0,
326
+ "left"
538
327
  );
539
328
  }
540
329
  qrCodePromise.then(() => {
@@ -546,38 +335,32 @@ class CanvasSaveButton extends PureComponent {
546
335
  mapToExport.renderSync();
547
336
  });
548
337
  }
549
-
550
338
  downloadCanvasImage(canvas) {
551
- // Use blob for large images
552
339
  const promise = new Promise((resolve) => {
553
340
  const { format } = this.props;
554
341
  if (/msie (9|10)/gi.test(window.navigator.userAgent.toLowerCase())) {
555
- // ie 9 and 10
556
342
  const url = canvas.toDataURL(format);
557
- const w = window.open('about:blank', '');
343
+ const w = window.open("about:blank", "");
558
344
  w.document.write(`<img src="${url}" alt="from canvas"/>`);
559
345
  resolve(url);
560
346
  }
561
347
  if (window.navigator.msSaveBlob) {
562
- // ie 11 and higher
563
348
  let image;
564
349
  try {
565
350
  image = canvas.msToBlob();
566
351
  } catch (e) {
567
- // eslint-disable-next-line no-console
568
352
  console.log(e);
569
353
  }
570
354
  const blob = new Blob([image], {
571
- type: format,
355
+ type: format
572
356
  });
573
357
  resolve(blob);
574
358
  window.navigator.msSaveBlob(blob, this.getDownloadImageName());
575
359
  } else {
576
360
  canvas.toBlob((blob) => {
577
- const link = document.createElement('a');
361
+ const link = document.createElement("a");
578
362
  link.download = this.getDownloadImageName();
579
363
  link.href = URL.createObjectURL(blob);
580
- // append child to document for firefox to be able to download.
581
364
  document.body.appendChild(link);
582
365
  link.click();
583
366
  resolve(blob);
@@ -586,10 +369,8 @@ class CanvasSaveButton extends PureComponent {
586
369
  });
587
370
  return promise;
588
371
  }
589
-
590
372
  render() {
591
373
  const { children, ...other } = this.props;
592
-
593
374
  delete other.onSaveStart;
594
375
  delete other.onSaveEnd;
595
376
  delete other.extraData;
@@ -599,28 +380,20 @@ class CanvasSaveButton extends PureComponent {
599
380
  delete other.coordinates;
600
381
  delete other.autoDownload;
601
382
  delete other.scale;
602
-
603
- return (
604
- <div
605
- role="button"
606
- className="rs-canvas-save-button"
607
- tabIndex={0}
608
- // eslint-disable-next-line react/jsx-props-no-spreading
609
- {...other}
610
- onClick={(e) => {
611
- return this.onClick(e);
612
- }}
613
- onKeyPress={(e) => {
614
- return e.which === 13 && this.onClick(e);
615
- }}
616
- >
617
- {children}
618
- </div>
619
- );
383
+ return /* @__PURE__ */ React.createElement("div", {
384
+ role: "button",
385
+ className: "rs-canvas-save-button",
386
+ tabIndex: 0,
387
+ ...other,
388
+ onClick: (e) => {
389
+ return this.onClick(e);
390
+ },
391
+ onKeyPress: (e) => {
392
+ return e.which === 13 && this.onClick(e);
393
+ }
394
+ }, children);
620
395
  }
621
396
  }
622
-
623
397
  CanvasSaveButton.propTypes = propTypes;
624
398
  CanvasSaveButton.defaultProps = defaultProps;
625
-
626
399
  export default CanvasSaveButton;