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.
- package/LayerService.js +128 -184
- package/LayerService.js.map +7 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
- package/components/BaseLayerSwitcher/index.js +1 -3
- package/components/BaseLayerSwitcher/index.js.map +7 -1
- package/components/BasicMap/BasicMap.js +147 -285
- package/components/BasicMap/BasicMap.js.map +7 -1
- package/components/BasicMap/index.js +1 -3
- package/components/BasicMap/index.js.map +7 -1
- package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
- package/components/CanvasSaveButton/index.js +1 -3
- package/components/CanvasSaveButton/index.js.map +7 -1
- package/components/Copyright/Copyright.js +29 -70
- package/components/Copyright/Copyright.js.map +7 -1
- package/components/Copyright/index.js +1 -3
- package/components/Copyright/index.js.map +7 -1
- package/components/FeatureExportButton/FeatureExportButton.js +40 -106
- package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
- package/components/FeatureExportButton/index.js +1 -3
- package/components/FeatureExportButton/index.js.map +7 -1
- package/components/FilterButton/FilterButton.js +41 -106
- package/components/FilterButton/FilterButton.js.map +7 -1
- package/components/FilterButton/index.js +1 -3
- package/components/FilterButton/index.js.map +7 -1
- package/components/FitExtent/FitExtent.js +17 -50
- package/components/FitExtent/FitExtent.js.map +7 -1
- package/components/FitExtent/index.js +1 -3
- package/components/FitExtent/index.js.map +7 -1
- package/components/FollowButton/FollowButton.js +41 -111
- package/components/FollowButton/FollowButton.js.map +7 -1
- package/components/FollowButton/index.js +1 -3
- package/components/FollowButton/index.js.map +7 -1
- package/components/Geolocation/Geolocation.js +104 -213
- package/components/Geolocation/Geolocation.js.map +7 -1
- package/components/Geolocation/index.js +1 -3
- package/components/Geolocation/index.js.map +7 -1
- package/components/LayerTree/LayerTree.js +204 -410
- package/components/LayerTree/LayerTree.js.map +7 -1
- package/components/LayerTree/index.js +1 -3
- package/components/LayerTree/index.js.map +7 -1
- package/components/MousePosition/MousePosition.js +61 -130
- package/components/MousePosition/MousePosition.js.map +7 -1
- package/components/MousePosition/index.js +1 -3
- package/components/MousePosition/index.js.map +7 -1
- package/components/NorthArrow/NorthArrow.js +22 -62
- package/components/NorthArrow/NorthArrow.js.map +7 -1
- package/components/NorthArrow/index.js +1 -3
- package/components/NorthArrow/index.js.map +7 -1
- package/components/Overlay/Overlay.js +83 -130
- package/components/Overlay/Overlay.js.map +7 -1
- package/components/Overlay/index.js +1 -3
- package/components/Overlay/index.js.map +7 -1
- package/components/Permalink/Permalink.js +150 -244
- package/components/Permalink/Permalink.js.map +7 -1
- package/components/Permalink/index.js +1 -3
- package/components/Permalink/index.js.map +7 -1
- package/components/Popup/Popup.js +106 -233
- package/components/Popup/Popup.js.map +7 -1
- package/components/Popup/index.js +1 -3
- package/components/Popup/index.js.map +7 -1
- package/components/ResizeHandler/ResizeHandler.js +58 -113
- package/components/ResizeHandler/ResizeHandler.js.map +7 -1
- package/components/ResizeHandler/index.js +1 -3
- package/components/ResizeHandler/index.js.map +7 -1
- package/components/RouteSchedule/RouteSchedule.js +150 -283
- package/components/RouteSchedule/RouteSchedule.js.map +7 -1
- package/components/RouteSchedule/index.js +1 -3
- package/components/RouteSchedule/index.js.map +7 -1
- package/components/ScaleLine/ScaleLine.js +21 -45
- package/components/ScaleLine/ScaleLine.js.map +7 -1
- package/components/ScaleLine/index.js +1 -3
- package/components/ScaleLine/index.js.map +7 -1
- package/components/Search/Search.js +122 -186
- package/components/Search/Search.js.map +7 -1
- package/components/Search/SearchService.js +45 -69
- package/components/Search/SearchService.js.map +7 -1
- package/components/Search/engines/Engine.js +18 -25
- package/components/Search/engines/Engine.js.map +7 -1
- package/components/Search/engines/StopFinder.js +21 -38
- package/components/Search/engines/StopFinder.js.map +7 -1
- package/components/Search/index.js +3 -6
- package/components/Search/index.js.map +7 -1
- package/components/StopsFinder/StopsFinder.js +123 -174
- package/components/StopsFinder/StopsFinder.js.map +7 -1
- package/components/StopsFinder/StopsFinderOption.js +37 -54
- package/components/StopsFinder/StopsFinderOption.js.map +7 -1
- package/components/StopsFinder/index.js +1 -3
- package/components/StopsFinder/index.js.map +7 -1
- package/components/TrackerControl/TrackerControl.js +73 -128
- package/components/TrackerControl/TrackerControl.js.map +7 -1
- package/components/TrackerControl/index.js +1 -3
- package/components/TrackerControl/index.js.map +7 -1
- package/components/Zoom/Zoom.js +69 -112
- package/components/Zoom/Zoom.js.map +7 -1
- package/components/Zoom/index.js +1 -3
- package/components/Zoom/index.js.map +7 -1
- package/package.json +10 -5
- package/propTypes.js +17 -23
- package/propTypes.js.map +7 -1
- package/setupTests.js +2 -4
- package/setupTests.js.map +7 -1
- package/themes/README.md +26 -0
- package/themes/default/components.scss +0 -1
- package/themes/default/examples.scss +0 -1
- package/utils/GlobalsForOle.js +63 -64
- package/utils/GlobalsForOle.js.map +7 -1
- package/utils/KML.js +178 -364
- package/utils/KML.js.map +7 -1
- package/utils/KMLFormat.js +37 -73
- package/utils/KMLFormat.js.map +7 -1
- package/utils/Styles.js +24 -32
- package/utils/Styles.js.map +7 -1
- package/utils/getPolygonPattern.js +11 -44
- package/utils/getPolygonPattern.js.map +7 -1
- package/utils/timeUtils.js +16 -35
- package/utils/timeUtils.js.map +7 -1
- package/LayerService.test.js +0 -160
- package/LayerService.test.js.map +0 -1
- package/Projections.js +0 -16
- package/Projections.js.map +0 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
- package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
- package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
- package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
- package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
- package/components/BaseLayerToggler/index.js +0 -3
- package/components/BaseLayerToggler/index.js.map +0 -1
- package/components/BasicMap/BasicMap.test.js +0 -288
- package/components/BasicMap/BasicMap.test.js.map +0 -1
- package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
- package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
- package/components/Copyright/Copyright.test.js +0 -133
- package/components/Copyright/Copyright.test.js.map +0 -1
- package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
- package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
- package/components/FilterButton/FilterButton.test.js +0 -48
- package/components/FilterButton/FilterButton.test.js.map +0 -1
- package/components/FitExtent/FitExtent.test.js +0 -44
- package/components/FitExtent/FitExtent.test.js.map +0 -1
- package/components/FollowButton/FollowButton.test.js +0 -57
- package/components/FollowButton/FollowButton.test.js.map +0 -1
- package/components/Geolocation/Geolocation.test.js +0 -263
- package/components/Geolocation/Geolocation.test.js.map +0 -1
- package/components/LayerTree/LayerTree.test.js +0 -323
- package/components/LayerTree/LayerTree.test.js.map +0 -1
- package/components/MousePosition/MousePosition.test.js +0 -125
- package/components/MousePosition/MousePosition.test.js.map +0 -1
- package/components/NorthArrow/NorthArrow.test.js +0 -106
- package/components/NorthArrow/NorthArrow.test.js.map +0 -1
- package/components/Overlay/Overlay.test.js +0 -145
- package/components/Overlay/Overlay.test.js.map +0 -1
- package/components/Permalink/Permalink.test.js +0 -267
- package/components/Permalink/Permalink.test.js.map +0 -1
- package/components/Popup/Popup.test.js +0 -291
- package/components/Popup/Popup.test.js.map +0 -1
- package/components/ResizeHandler/ResizeHandler.test.js +0 -410
- package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
- package/components/RouteSchedule/RouteSchedule.test.js +0 -102
- package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
- package/components/ScaleLine/ScaleLine.test.js +0 -32
- package/components/ScaleLine/ScaleLine.test.js.map +0 -1
- package/components/Search/Search.test.js +0 -15
- package/components/Search/Search.test.js.map +0 -1
- package/components/StopsFinder/StopsFinder.test.js +0 -19
- package/components/StopsFinder/StopsFinder.test.js.map +0 -1
- package/components/TrackerControl/TrackerControl.test.js +0 -17
- package/components/TrackerControl/TrackerControl.test.js.map +0 -1
- package/components/Zoom/Zoom.test.js +0 -150
- package/components/Zoom/Zoom.test.js.map +0 -1
- package/styleguidist/ComponentsList.js +0 -52
- package/styleguidist/ComponentsList.js.map +0 -1
- package/styleguidist/StyleGuide.js +0 -253
- package/styleguidist/StyleGuide.js.map +0 -1
- package/utils/KML.test.js +0 -163
- package/utils/KML.test.js.map +0 -1
- package/utils/KMLFormat.test.js +0 -22
- package/utils/KMLFormat.test.js.map +0 -1
- package/utils/getPolygonPattern.test.js +0 -66
- package/utils/getPolygonPattern.test.js.map +0 -1
- package/utils/timeUtils.test.js +0 -32
- package/utils/timeUtils.test.js.map +0 -1
|
@@ -1,237 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
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:
|
|
23
|
+
format: "image/png",
|
|
113
24
|
extent: null,
|
|
114
25
|
extraData: null,
|
|
115
26
|
coordinates: null,
|
|
116
27
|
scale: 1,
|
|
117
|
-
onSaveStart:
|
|
28
|
+
onSaveStart: (map) => {
|
|
118
29
|
return Promise.resolve(map);
|
|
119
30
|
},
|
|
120
|
-
onSaveEnd:
|
|
31
|
+
onSaveEnd: () => {
|
|
32
|
+
}
|
|
121
33
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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(
|
|
155
|
-
return this
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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],
|
|
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
|
-
|
|
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
|
-
|
|
222
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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 ||
|
|
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 ||
|
|
271
|
-
|
|
272
|
-
|
|
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 (
|
|
279
|
-
firstLine = firstLine.substring(0, firstLine.lastIndexOf(
|
|
280
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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 =
|
|
173
|
+
img.onload = () => {
|
|
356
174
|
destContext.save();
|
|
357
|
-
|
|
358
|
-
|
|
175
|
+
const elementWidth = (width || 80) * scale;
|
|
176
|
+
const elementHeight = (height || 80) * scale;
|
|
359
177
|
destContext.translate(
|
|
360
|
-
destCanvas.width - 2 * this
|
|
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
|
-
|
|
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
|
|
385
|
-
elementHeight + 2 * this
|
|
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
|
-
|
|
395
|
-
|
|
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
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
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(
|
|
252
|
+
destCanvas = document.createElement("canvas");
|
|
467
253
|
destCanvas.width = clip.w;
|
|
468
254
|
destCanvas.height = clip.h;
|
|
469
|
-
destContext = destCanvas.getContext(
|
|
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
|
|
271
|
+
logoPromise = this.drawElement(extraData.logo, destCanvas);
|
|
490
272
|
}
|
|
491
|
-
|
|
492
|
-
|
|
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
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
533
|
-
|
|
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
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
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
|
-
|
|
556
|
-
type: format
|
|
314
|
+
const blob = new Blob([image], {
|
|
315
|
+
type: format
|
|
557
316
|
});
|
|
558
317
|
resolve(blob);
|
|
559
|
-
window.navigator.msSaveBlob(blob, this
|
|
318
|
+
window.navigator.msSaveBlob(blob, this.getDownloadImageName());
|
|
560
319
|
} else {
|
|
561
|
-
canvas.toBlob(
|
|
562
|
-
|
|
563
|
-
link.download = this
|
|
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
|
-
|
|
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
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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
|