react-spatial 1.2.2 → 1.2.3-beta.3

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 (186) hide show
  1. package/LayerService.js +128 -184
  2. package/LayerService.js.map +7 -1
  3. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
  4. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
  5. package/components/BaseLayerSwitcher/index.js +1 -3
  6. package/components/BaseLayerSwitcher/index.js.map +7 -1
  7. package/components/BasicMap/BasicMap.js +147 -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 +165 -419
  12. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
  13. package/components/CanvasSaveButton/index.js +1 -3
  14. package/components/CanvasSaveButton/index.js.map +7 -1
  15. package/components/Copyright/Copyright.js +29 -70
  16. package/components/Copyright/Copyright.js.map +7 -1
  17. package/components/Copyright/index.js +1 -3
  18. package/components/Copyright/index.js.map +7 -1
  19. package/components/FeatureExportButton/FeatureExportButton.js +40 -106
  20. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
  21. package/components/FeatureExportButton/index.js +1 -3
  22. package/components/FeatureExportButton/index.js.map +7 -1
  23. package/components/FilterButton/FilterButton.js +41 -106
  24. package/components/FilterButton/FilterButton.js.map +7 -1
  25. package/components/FilterButton/index.js +1 -3
  26. package/components/FilterButton/index.js.map +7 -1
  27. package/components/FitExtent/FitExtent.js +17 -50
  28. package/components/FitExtent/FitExtent.js.map +7 -1
  29. package/components/FitExtent/index.js +1 -3
  30. package/components/FitExtent/index.js.map +7 -1
  31. package/components/FollowButton/FollowButton.js +41 -111
  32. package/components/FollowButton/FollowButton.js.map +7 -1
  33. package/components/FollowButton/index.js +1 -3
  34. package/components/FollowButton/index.js.map +7 -1
  35. package/components/Geolocation/Geolocation.js +104 -213
  36. package/components/Geolocation/Geolocation.js.map +7 -1
  37. package/components/Geolocation/index.js +1 -3
  38. package/components/Geolocation/index.js.map +7 -1
  39. package/components/LayerTree/LayerTree.js +204 -410
  40. package/components/LayerTree/LayerTree.js.map +7 -1
  41. package/components/LayerTree/index.js +1 -3
  42. package/components/LayerTree/index.js.map +7 -1
  43. package/components/MousePosition/MousePosition.js +61 -130
  44. package/components/MousePosition/MousePosition.js.map +7 -1
  45. package/components/MousePosition/index.js +1 -3
  46. package/components/MousePosition/index.js.map +7 -1
  47. package/components/NorthArrow/NorthArrow.js +22 -62
  48. package/components/NorthArrow/NorthArrow.js.map +7 -1
  49. package/components/NorthArrow/index.js +1 -3
  50. package/components/NorthArrow/index.js.map +7 -1
  51. package/components/Overlay/Overlay.js +83 -130
  52. package/components/Overlay/Overlay.js.map +7 -1
  53. package/components/Overlay/index.js +1 -3
  54. package/components/Overlay/index.js.map +7 -1
  55. package/components/Permalink/Permalink.js +150 -244
  56. package/components/Permalink/Permalink.js.map +7 -1
  57. package/components/Permalink/index.js +1 -3
  58. package/components/Permalink/index.js.map +7 -1
  59. package/components/Popup/Popup.js +106 -233
  60. package/components/Popup/Popup.js.map +7 -1
  61. package/components/Popup/index.js +1 -3
  62. package/components/Popup/index.js.map +7 -1
  63. package/components/ResizeHandler/ResizeHandler.js +58 -113
  64. package/components/ResizeHandler/ResizeHandler.js.map +7 -1
  65. package/components/ResizeHandler/index.js +1 -3
  66. package/components/ResizeHandler/index.js.map +7 -1
  67. package/components/RouteSchedule/RouteSchedule.js +150 -283
  68. package/components/RouteSchedule/RouteSchedule.js.map +7 -1
  69. package/components/RouteSchedule/index.js +1 -3
  70. package/components/RouteSchedule/index.js.map +7 -1
  71. package/components/ScaleLine/ScaleLine.js +21 -45
  72. package/components/ScaleLine/ScaleLine.js.map +7 -1
  73. package/components/ScaleLine/index.js +1 -3
  74. package/components/ScaleLine/index.js.map +7 -1
  75. package/components/Search/Search.js +122 -186
  76. package/components/Search/Search.js.map +7 -1
  77. package/components/Search/SearchService.js +45 -69
  78. package/components/Search/SearchService.js.map +7 -1
  79. package/components/Search/engines/Engine.js +18 -25
  80. package/components/Search/engines/Engine.js.map +7 -1
  81. package/components/Search/engines/StopFinder.js +21 -38
  82. package/components/Search/engines/StopFinder.js.map +7 -1
  83. package/components/Search/index.js +3 -6
  84. package/components/Search/index.js.map +7 -1
  85. package/components/StopsFinder/StopsFinder.js +123 -174
  86. package/components/StopsFinder/StopsFinder.js.map +7 -1
  87. package/components/StopsFinder/StopsFinderOption.js +37 -54
  88. package/components/StopsFinder/StopsFinderOption.js.map +7 -1
  89. package/components/StopsFinder/index.js +1 -3
  90. package/components/StopsFinder/index.js.map +7 -1
  91. package/components/TrackerControl/TrackerControl.js +73 -128
  92. package/components/TrackerControl/TrackerControl.js.map +7 -1
  93. package/components/TrackerControl/index.js +1 -3
  94. package/components/TrackerControl/index.js.map +7 -1
  95. package/components/Zoom/Zoom.js +69 -112
  96. package/components/Zoom/Zoom.js.map +7 -1
  97. package/components/Zoom/index.js +1 -3
  98. package/components/Zoom/index.js.map +7 -1
  99. package/package.json +10 -5
  100. package/propTypes.js +17 -23
  101. package/propTypes.js.map +7 -1
  102. package/setupTests.js +2 -4
  103. package/setupTests.js.map +7 -1
  104. package/themes/README.md +26 -0
  105. package/themes/default/components.scss +0 -1
  106. package/themes/default/examples.scss +0 -1
  107. package/utils/GlobalsForOle.js +63 -64
  108. package/utils/GlobalsForOle.js.map +7 -1
  109. package/utils/KML.js +178 -364
  110. package/utils/KML.js.map +7 -1
  111. package/utils/KMLFormat.js +37 -73
  112. package/utils/KMLFormat.js.map +7 -1
  113. package/utils/Styles.js +24 -32
  114. package/utils/Styles.js.map +7 -1
  115. package/utils/getPolygonPattern.js +11 -44
  116. package/utils/getPolygonPattern.js.map +7 -1
  117. package/utils/timeUtils.js +16 -35
  118. package/utils/timeUtils.js.map +7 -1
  119. package/LayerService.test.js +0 -160
  120. package/LayerService.test.js.map +0 -1
  121. package/Projections.js +0 -16
  122. package/Projections.js.map +0 -1
  123. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
  124. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
  125. package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
  126. package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
  127. package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
  128. package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
  129. package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
  130. package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
  131. package/components/BaseLayerToggler/index.js +0 -3
  132. package/components/BaseLayerToggler/index.js.map +0 -1
  133. package/components/BasicMap/BasicMap.test.js +0 -288
  134. package/components/BasicMap/BasicMap.test.js.map +0 -1
  135. package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
  136. package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
  137. package/components/Copyright/Copyright.test.js +0 -133
  138. package/components/Copyright/Copyright.test.js.map +0 -1
  139. package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
  140. package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
  141. package/components/FilterButton/FilterButton.test.js +0 -48
  142. package/components/FilterButton/FilterButton.test.js.map +0 -1
  143. package/components/FitExtent/FitExtent.test.js +0 -44
  144. package/components/FitExtent/FitExtent.test.js.map +0 -1
  145. package/components/FollowButton/FollowButton.test.js +0 -57
  146. package/components/FollowButton/FollowButton.test.js.map +0 -1
  147. package/components/Geolocation/Geolocation.test.js +0 -263
  148. package/components/Geolocation/Geolocation.test.js.map +0 -1
  149. package/components/LayerTree/LayerTree.test.js +0 -323
  150. package/components/LayerTree/LayerTree.test.js.map +0 -1
  151. package/components/MousePosition/MousePosition.test.js +0 -125
  152. package/components/MousePosition/MousePosition.test.js.map +0 -1
  153. package/components/NorthArrow/NorthArrow.test.js +0 -106
  154. package/components/NorthArrow/NorthArrow.test.js.map +0 -1
  155. package/components/Overlay/Overlay.test.js +0 -145
  156. package/components/Overlay/Overlay.test.js.map +0 -1
  157. package/components/Permalink/Permalink.test.js +0 -267
  158. package/components/Permalink/Permalink.test.js.map +0 -1
  159. package/components/Popup/Popup.test.js +0 -291
  160. package/components/Popup/Popup.test.js.map +0 -1
  161. package/components/ResizeHandler/ResizeHandler.test.js +0 -410
  162. package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
  163. package/components/RouteSchedule/RouteSchedule.test.js +0 -102
  164. package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
  165. package/components/ScaleLine/ScaleLine.test.js +0 -32
  166. package/components/ScaleLine/ScaleLine.test.js.map +0 -1
  167. package/components/Search/Search.test.js +0 -15
  168. package/components/Search/Search.test.js.map +0 -1
  169. package/components/StopsFinder/StopsFinder.test.js +0 -19
  170. package/components/StopsFinder/StopsFinder.test.js.map +0 -1
  171. package/components/TrackerControl/TrackerControl.test.js +0 -17
  172. package/components/TrackerControl/TrackerControl.test.js.map +0 -1
  173. package/components/Zoom/Zoom.test.js +0 -150
  174. package/components/Zoom/Zoom.test.js.map +0 -1
  175. package/styleguidist/ComponentsList.js +0 -52
  176. package/styleguidist/ComponentsList.js.map +0 -1
  177. package/styleguidist/StyleGuide.js +0 -253
  178. package/styleguidist/StyleGuide.js.map +0 -1
  179. package/utils/KML.test.js +0 -163
  180. package/utils/KML.test.js.map +0 -1
  181. package/utils/KMLFormat.test.js +0 -22
  182. package/utils/KMLFormat.test.js.map +0 -1
  183. package/utils/getPolygonPattern.test.js +0 -66
  184. package/utils/getPolygonPattern.test.js.map +0 -1
  185. package/utils/timeUtils.test.js +0 -32
  186. package/utils/timeUtils.test.js.map +0 -1
@@ -1,237 +1,92 @@
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 = {
11
- /**
12
- * Automatically download the image saved.
13
- */
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";
7
+ const propTypes = {
14
8
  autoDownload: PropTypes.bool,
15
-
16
- /**
17
- * Children content of the button.
18
- */
19
9
  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). */
10
+ format: PropTypes.oneOf(["image/jpeg", "image/png"]),
27
11
  map: PropTypes.instanceOf(OLMap),
28
-
29
- /**
30
- * Extent for the export. If no extent is given, the whole map is exported.
31
- */
32
12
  extent: PropTypes.arrayOf(PropTypes.number),
33
-
34
- /**
35
- * Array of 4 [ol/Coordinate](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~Coordinate).
36
- * If no coordinates and no extent are given, the whole map is exported.
37
- * This property must be used to export rotated map.
38
- * If you don't need to export rotated map the extent property can be used as well.
39
- * If extent is specified, coordinates property is ignored.
40
- */
41
13
  coordinates: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
42
-
43
- /**
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.
47
- */
48
14
  scale: PropTypes.number,
49
-
50
- /**
51
- * Function called before the dowload process begins.
52
- */
53
15
  onSaveStart: PropTypes.func,
54
-
55
- /**
56
- * Function called after the dowload process ends.
57
- *
58
- * @param {object} error Error message the process fails.
59
- */
60
16
  onSaveEnd: PropTypes.func,
61
-
62
- /**
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
- }
104
- */
105
- extraData: PropTypes.object,
17
+ extraData: PropTypes.object
106
18
  };
107
-
108
- var defaultProps = {
19
+ const defaultProps = {
109
20
  autoDownload: true,
110
21
  children: null,
111
22
  map: null,
112
- format: 'image/png',
23
+ format: "image/png",
113
24
  extent: null,
114
25
  extraData: null,
115
26
  coordinates: null,
116
27
  scale: 1,
117
- onSaveStart: function (map) {
28
+ onSaveStart: (map) => {
118
29
  return Promise.resolve(map);
119
30
  },
120
- onSaveEnd: function () {},
31
+ onSaveEnd: () => {
32
+ }
121
33
  };
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';
34
+ class CanvasSaveButton extends PureComponent {
35
+ constructor(props) {
36
+ super(props);
37
+ const { format } = this.props;
38
+ this.fileExt = format === "image/jpeg" ? "jpg" : "png";
134
39
  this.padding = 5;
135
40
  }
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;
41
+ onClick(evt) {
42
+ const { map, onSaveStart, onSaveEnd, autoDownload } = this.props;
149
43
  if (window.navigator.msSaveBlob) {
150
- // ie only
151
44
  evt.preventDefault();
152
45
  evt.stopPropagation();
153
46
  }
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
- });
47
+ onSaveStart(map).then((mapToExport) => {
48
+ return this.createCanvasImage(mapToExport || map).then((canvas) => {
49
+ if (autoDownload) {
50
+ this.downloadCanvasImage(canvas).then((blob) => {
51
+ onSaveEnd(mapToExport, canvas, blob);
52
+ });
53
+ } else {
54
+ onSaveEnd(mapToExport, canvas);
55
+ }
56
+ }).catch((err) => {
57
+ if (err) {
58
+ console.error(err);
59
+ }
60
+ onSaveEnd(mapToExport, err);
61
+ });
172
62
  });
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;
63
+ }
64
+ getDownloadImageName() {
65
+ return `${window.document.title.replace(/ /g, "_").toLowerCase()}.${this.fileExt}`;
66
+ }
67
+ decreaseFontSize(destContext, maxWidth, copyright, scale) {
68
+ const minFontSize = 8;
69
+ let sizeMatch;
70
+ let fontSize;
187
71
  do {
188
72
  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
73
+ fontSize = parseInt(sizeMatch[0].replace(sizeMatch[1], ""), 10);
192
74
  destContext.font = destContext.font.replace(fontSize, fontSize - 1);
193
-
194
75
  if (fontSize - 1 === minFontSize) {
195
76
  this.multilineCopyright = true;
196
77
  }
197
- } while (
198
- fontSize - 1 > minFontSize &&
199
- destContext.measureText(copyright).width * scale > maxWidth
200
- );
201
-
78
+ } while (fontSize - 1 > minFontSize && destContext.measureText(copyright).width * scale > maxWidth);
202
79
  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;
80
+ }
81
+ drawTextBackground(destContext, textMeasure, textX, textY, padding, styleOptions = {}) {
82
+ const { width, height, actualBoundingBoxAscent } = textMeasure;
220
83
  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
-
84
+ destContext.fillStyle = "rgba(255,255,255,.8)";
85
+ if (typeof styleOptions === "object") {
86
+ Object.entries(styleOptions).forEach(([key, value]) => {
230
87
  destContext[key] = value;
231
88
  });
232
89
  }
233
-
234
- /// draw background rect assuming height of font
235
90
  destContext.fillRect(
236
91
  textX - padding,
237
92
  textY - actualBoundingBoxAscent - padding,
@@ -239,66 +94,43 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
239
94
  height + padding * 2
240
95
  );
241
96
  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
-
97
+ }
98
+ drawCopyright(destContext, destCanvas, maxWidth) {
99
+ const { extraData, scale } = this.props;
100
+ const { text, font, fillStyle, background } = extraData.copyright;
101
+ let copyright = typeof text === "function" ? text() : text;
255
102
  if (Array.isArray(copyright)) {
256
103
  copyright = copyright.join();
257
104
  }
258
-
259
105
  destContext.save();
260
106
  destContext.scale(scale, scale);
261
- destContext.font = font || '12px Arial';
107
+ destContext.font = font || "12px Arial";
262
108
  destContext.font = this.decreaseFontSize(
263
109
  destContext,
264
110
  maxWidth - this.padding,
265
111
  copyright,
266
112
  scale
267
113
  );
268
-
269
114
  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
115
+ destContext.fillStyle = fillStyle || "black";
116
+ let firstLine = copyright;
117
+ const wordNumber = copyright.split(" ").length;
277
118
  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
- ) {
119
+ for (let i = 0; i < wordNumber; i += 1) {
120
+ firstLine = firstLine.substring(0, firstLine.lastIndexOf(" "));
121
+ if (destContext.measureText(firstLine).width * scale < maxWidth - this.padding) {
285
122
  break;
286
123
  }
287
124
  }
288
125
  }
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
-
126
+ const secondLine = copyright.replace(firstLine, "");
127
+ const textX = this.padding;
128
+ let textMeasure = destContext.measureText(firstLine);
129
+ textMeasure.height = textMeasure.actualBoundingBoxAscent + textMeasure.actualBoundingBoxDescent;
130
+ let firstLineY = destCanvas.height / scale - this.padding;
131
+ const secondLineY = firstLineY;
132
+ const paddingBetweenLines = 3;
133
+ const paddingBackground = paddingBetweenLines / 2;
302
134
  if (secondLine) {
303
135
  firstLineY -= textMeasure.height + paddingBetweenLines;
304
136
  }
@@ -313,13 +145,9 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
313
145
  );
314
146
  }
315
147
  destContext.fillText(firstLine, textX, firstLineY);
316
-
317
- // Draw second line.
318
148
  if (secondLine) {
319
149
  textMeasure = destContext.measureText(secondLine);
320
- textMeasure.height =
321
- textMeasure.actualBoundingBoxAscent +
322
- textMeasure.actualBoundingBoxDescent;
150
+ textMeasure.height = textMeasure.actualBoundingBoxAscent + textMeasure.actualBoundingBoxDescent;
323
151
  if (background) {
324
152
  this.drawTextBackground(
325
153
  destContext,
@@ -332,43 +160,28 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
332
160
  }
333
161
  destContext.fillText(secondLine, textX, secondLineY);
334
162
  }
335
-
336
163
  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';
164
+ }
165
+ drawElement(data, destCanvas, previousItemSize = [0, 0]) {
166
+ const destContext = destCanvas.getContext("2d");
167
+ const { scale } = this.props;
168
+ const { src, width, height, rotation } = data;
169
+ return new Promise((resolve) => {
170
+ const img = new Image();
171
+ img.crossOrigin = "Anonymous";
354
172
  img.src = src;
355
- img.onload = function () {
173
+ img.onload = () => {
356
174
  destContext.save();
357
- var elementWidth = (width || 80) * scale;
358
- var elementHeight = (height || 80) * scale;
175
+ const elementWidth = (width || 80) * scale;
176
+ const elementHeight = (height || 80) * scale;
359
177
  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]
178
+ destCanvas.width - 2 * this.padding - elementWidth / 2,
179
+ destCanvas.height - 2 * this.padding - elementHeight / 2 - previousItemSize[1]
365
180
  );
366
-
367
181
  if (rotation) {
368
- var angle = typeof rotation === 'function' ? rotation() : rotation;
182
+ const angle = typeof rotation === "function" ? rotation() : rotation;
369
183
  destContext.rotate(angle * (Math.PI / 180));
370
184
  }
371
-
372
185
  destContext.drawImage(
373
186
  img,
374
187
  -elementWidth / 2,
@@ -377,99 +190,70 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
377
190
  elementHeight
378
191
  );
379
192
  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
193
  resolve([
384
- elementWidth + 2 * this$1.padding,
385
- elementHeight + 2 * this$1.padding ]);
194
+ elementWidth + 2 * this.padding,
195
+ elementHeight + 2 * this.padding
196
+ ]);
386
197
  };
387
-
388
- img.onerror = function () {
198
+ img.onerror = () => {
389
199
  resolve();
390
200
  };
391
201
  });
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
-
202
+ }
203
+ calculatePixelsToExport(mapToExport) {
204
+ const { extent, coordinates } = this.props;
205
+ let firstCoordinate;
206
+ let oppositeCoordinate;
403
207
  if (extent) {
404
208
  firstCoordinate = getTopLeft(extent);
405
209
  oppositeCoordinate = getBottomRight(extent);
406
210
  } 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]);
211
+ [firstCoordinate, , oppositeCoordinate] = coordinates;
411
212
  }
412
-
413
213
  if (firstCoordinate && oppositeCoordinate) {
414
- var firstPixel = mapToExport.getPixelFromCoordinate(firstCoordinate);
415
- var oppositePixel =
416
- mapToExport.getPixelFromCoordinate(oppositeCoordinate);
417
- var pixelTopLeft = [
214
+ const firstPixel = mapToExport.getPixelFromCoordinate(firstCoordinate);
215
+ const oppositePixel = mapToExport.getPixelFromCoordinate(oppositeCoordinate);
216
+ const pixelTopLeft = [
418
217
  firstPixel[0] <= oppositePixel[0] ? firstPixel[0] : oppositePixel[0],
419
- firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1] ];
420
- var pixelBottomRight = [
218
+ firstPixel[1] <= oppositePixel[1] ? firstPixel[1] : oppositePixel[1]
219
+ ];
220
+ const pixelBottomRight = [
421
221
  firstPixel[0] > oppositePixel[0] ? firstPixel[0] : oppositePixel[0],
422
- firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1] ];
423
-
222
+ firstPixel[1] > oppositePixel[1] ? firstPixel[1] : oppositePixel[1]
223
+ ];
424
224
  return {
425
225
  x: pixelTopLeft[0],
426
226
  y: pixelTopLeft[1],
427
227
  w: pixelBottomRight[0] - pixelTopLeft[0],
428
- h: pixelBottomRight[1] - pixelTopLeft[1],
228
+ h: pixelBottomRight[1] - pixelTopLeft[1]
429
229
  };
430
230
  }
431
231
  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];
232
+ }
233
+ createCanvasImage(mapToExport) {
234
+ const { extraData } = this.props;
235
+ return new Promise((resolve) => {
236
+ mapToExport.once("rendercomplete", () => {
237
+ const canvases = mapToExport.getTargetElement().getElementsByTagName("canvas");
238
+ let destCanvas;
239
+ let destContext;
240
+ for (let i = 0; i < canvases.length; i += 1) {
241
+ const canvas = canvases[i];
454
242
  if (!canvas.width || !canvas.height) {
455
- // eslint-disable-next-line no-continue
456
243
  continue;
457
244
  }
458
- var clip = this$1.calculatePixelsToExport(mapToExport) || {
245
+ const clip = this.calculatePixelsToExport(mapToExport) || {
459
246
  x: 0,
460
247
  y: 0,
461
248
  w: canvas.width,
462
- h: canvas.height,
249
+ h: canvas.height
463
250
  };
464
-
465
251
  if (!destCanvas) {
466
- destCanvas = document.createElement('canvas');
252
+ destCanvas = document.createElement("canvas");
467
253
  destCanvas.width = clip.w;
468
254
  destCanvas.height = clip.h;
469
- destContext = destCanvas.getContext('2d');
255
+ destContext = destCanvas.getContext("2d");
470
256
  }
471
-
472
- // Draw canvas to the canvas to export.
473
257
  destContext.drawImage(
474
258
  canvas,
475
259
  clip.x,
@@ -482,44 +266,27 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
482
266
  destCanvas.height
483
267
  );
484
268
  }
485
-
486
- // Custom info
487
- var logoPromise = Promise.resolve();
269
+ let logoPromise = Promise.resolve();
488
270
  if (destContext && extraData && extraData.logo) {
489
- logoPromise = this$1.drawElement(extraData.logo, destCanvas);
271
+ logoPromise = this.drawElement(extraData.logo, destCanvas);
490
272
  }
491
-
492
- logoPromise.then(function (logoSize) {
493
- if ( logoSize === void 0 ) logoSize = [0, 0];
494
-
495
- // North arrow
496
- var arrowPromise = Promise.resolve();
273
+ logoPromise.then((logoSize = [0, 0]) => {
274
+ let arrowPromise = Promise.resolve();
497
275
  if (destContext && extraData && extraData.northArrow) {
498
- arrowPromise = this$1.drawElement(
499
- Object.assign({}, {src: extraData.northArrow.circled
500
- ? NorthArrowCircle
501
- : NorthArrowSimple},
502
- extraData.northArrow),
276
+ arrowPromise = this.drawElement(
277
+ {
278
+ src: extraData.northArrow.circled ? NorthArrowCircle : NorthArrowSimple,
279
+ ...extraData.northArrow
280
+ },
503
281
  destCanvas,
504
282
  logoSize
505
283
  );
506
284
  }
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);
285
+ arrowPromise.then((arrowSize = [0, 0]) => {
286
+ const widestElement = Math.max(logoSize[0], arrowSize[0]);
287
+ if (destContext && extraData && extraData.copyright && extraData.copyright.text) {
288
+ const maxWidth = widestElement ? destContext.canvas.width - widestElement : destContext.canvas.width;
289
+ this.drawCopyright(destContext, destCanvas, maxWidth);
523
290
  }
524
291
  resolve(destCanvas);
525
292
  });
@@ -527,42 +294,33 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
527
294
  });
528
295
  mapToExport.renderSync();
529
296
  });
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;
297
+ }
298
+ downloadCanvasImage(canvas) {
299
+ const promise = new Promise((resolve) => {
300
+ const { format } = this.props;
539
301
  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\"/>"));
302
+ const url = canvas.toDataURL(format);
303
+ const w = window.open("about:blank", "");
304
+ w.document.write(`<img src="${url}" alt="from canvas"/>`);
544
305
  resolve(url);
545
306
  }
546
307
  if (window.navigator.msSaveBlob) {
547
- // ie 11 and higher
548
- var image;
308
+ let image;
549
309
  try {
550
310
  image = canvas.msToBlob();
551
311
  } catch (e) {
552
- // eslint-disable-next-line no-console
553
312
  console.log(e);
554
313
  }
555
- var blob = new Blob([image], {
556
- type: format,
314
+ const blob = new Blob([image], {
315
+ type: format
557
316
  });
558
317
  resolve(blob);
559
- window.navigator.msSaveBlob(blob, this$1.getDownloadImageName());
318
+ window.navigator.msSaveBlob(blob, this.getDownloadImageName());
560
319
  } else {
561
- canvas.toBlob(function (blob) {
562
- var link = document.createElement('a');
563
- link.download = this$1.getDownloadImageName();
320
+ canvas.toBlob((blob) => {
321
+ const link = document.createElement("a");
322
+ link.download = this.getDownloadImageName();
564
323
  link.href = URL.createObjectURL(blob);
565
- // append child to document for firefox to be able to download.
566
324
  document.body.appendChild(link);
567
325
  link.click();
568
326
  resolve(blob);
@@ -570,16 +328,9 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
570
328
  }
571
329
  });
572
330
  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
-
331
+ }
332
+ render() {
333
+ const { children, ...other } = this.props;
583
334
  delete other.onSaveStart;
584
335
  delete other.onSaveEnd;
585
336
  delete other.extraData;
@@ -589,25 +340,20 @@ var CanvasSaveButton = /*@__PURE__*/(function (PureComponent) {
589
340
  delete other.coordinates;
590
341
  delete other.autoDownload;
591
342
  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
-
343
+ return /* @__PURE__ */ React.createElement("div", {
344
+ role: "button",
345
+ className: "rs-canvas-save-button",
346
+ tabIndex: 0,
347
+ ...other,
348
+ onClick: (e) => {
349
+ return this.onClick(e);
350
+ },
351
+ onKeyPress: (e) => {
352
+ return e.which === 13 && this.onClick(e);
353
+ }
354
+ }, children);
355
+ }
356
+ }
608
357
  CanvasSaveButton.propTypes = propTypes;
609
358
  CanvasSaveButton.defaultProps = defaultProps;
610
-
611
359
  export default CanvasSaveButton;
612
-
613
- //# sourceMappingURL=CanvasSaveButton.js.map