react-spatial 2.0.0-beta.1 → 2.0.0-beta.2

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