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.
- package/README.md +5 -10
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +243 -220
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.scss +6 -5
- package/components/BaseLayerSwitcher/index.js +1 -3
- package/components/BaseLayerSwitcher/index.js.map +7 -1
- package/components/BasicMap/BasicMap.js +165 -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 +434 -556
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
- package/components/CanvasSaveButton/CanvasSaveButton.md.scss +1 -1
- package/components/CanvasSaveButton/index.js +1 -3
- package/components/CanvasSaveButton/index.js.map +7 -1
- package/components/Copyright/Copyright.js +44 -77
- 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 +44 -92
- 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/FitExtent/FitExtent.js +31 -46
- 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/Geolocation/Geolocation.js +158 -228
- package/components/Geolocation/Geolocation.js.map +7 -1
- package/components/Geolocation/Geolocation.scss +7 -5
- package/components/Geolocation/index.js +1 -3
- package/components/Geolocation/index.js.map +7 -1
- package/components/LayerTree/LayerTree.js +359 -357
- package/components/LayerTree/LayerTree.js.map +7 -1
- package/components/LayerTree/LayerTree.scss +4 -6
- package/components/LayerTree/index.js +1 -3
- package/components/LayerTree/index.js.map +7 -1
- package/components/MousePosition/MousePosition.js +71 -109
- 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 +37 -61
- 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 +93 -123
- 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 +194 -229
- 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 +139 -215
- package/components/Popup/Popup.js.map +7 -1
- package/components/Popup/Popup.md.scss +1 -0
- package/components/Popup/Popup.scss +3 -1
- package/components/Popup/index.js +1 -3
- package/components/Popup/index.js.map +7 -1
- package/components/ResizeHandler/ResizeHandler.js +88 -137
- 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 +227 -277
- package/components/RouteSchedule/RouteSchedule.js.map +7 -1
- package/components/RouteSchedule/RouteSchedule.md.scss +4 -2
- package/components/RouteSchedule/RouteSchedule.scss +12 -23
- package/components/RouteSchedule/index.js +1 -3
- package/components/RouteSchedule/index.js.map +7 -1
- package/components/ScaleLine/ScaleLine.js +17 -39
- package/components/ScaleLine/ScaleLine.js.map +7 -1
- package/components/ScaleLine/ScaleLine.scss +6 -4
- package/components/ScaleLine/index.js +1 -3
- package/components/ScaleLine/index.js.map +7 -1
- package/components/StopsFinder/StopsFinder.js +134 -162
- package/components/StopsFinder/StopsFinder.js.map +7 -1
- package/components/StopsFinder/StopsFinderOption.js +30 -60
- 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/Zoom/Zoom.js +102 -106
- package/components/Zoom/Zoom.js.map +7 -1
- package/components/Zoom/Zoom.md.scss +3 -1
- package/components/Zoom/Zoom.scss +7 -5
- package/components/Zoom/index.js +1 -3
- package/components/Zoom/index.js.map +7 -1
- package/images/geops_qr.png +0 -0
- package/package.json +88 -182
- package/propTypes.js +36 -24
- package/propTypes.js.map +7 -1
- package/setupTests.js +21 -4
- package/setupTests.js.map +7 -1
- package/themes/README.md +26 -0
- package/themes/default/components.scss +9 -14
- package/themes/default/examples.scss +20 -20
- package/themes/default/index.scss +3 -3
- package/themes/default/mixins.scss +7 -5
- package/themes/default/variables.scss +27 -25
- package/utils/GlobalsForOle.js +72 -73
- package/utils/GlobalsForOle.js.map +7 -1
- package/utils/KML.js +320 -381
- package/utils/KML.js.map +7 -1
- package/utils/Styles.js +25 -33
- package/utils/Styles.js.map +7 -1
- package/utils/getLayersAsFlatArray.js +14 -0
- package/utils/getLayersAsFlatArray.js.map +7 -0
- package/utils/getPolygonPattern.js +11 -44
- package/utils/getPolygonPattern.js.map +7 -1
- package/utils/timeUtils.js +20 -35
- package/utils/timeUtils.js.map +7 -1
- package/LayerService.js +0 -193
- package/LayerService.js.map +0 -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.js +0 -131
- package/components/FilterButton/FilterButton.js.map +0 -1
- package/components/FilterButton/FilterButton.scss +0 -36
- package/components/FilterButton/FilterButton.test.js +0 -48
- package/components/FilterButton/FilterButton.test.js.map +0 -1
- package/components/FilterButton/index.js +0 -3
- package/components/FilterButton/index.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.js +0 -143
- package/components/FollowButton/FollowButton.js.map +0 -1
- package/components/FollowButton/FollowButton.scss +0 -36
- package/components/FollowButton/FollowButton.test.js +0 -57
- package/components/FollowButton/FollowButton.test.js.map +0 -1
- package/components/FollowButton/index.js +0 -3
- package/components/FollowButton/index.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.js +0 -230
- package/components/Search/Search.js.map +0 -1
- package/components/Search/Search.md.scss +0 -4
- package/components/Search/Search.scss +0 -78
- package/components/Search/Search.test.js +0 -15
- package/components/Search/Search.test.js.map +0 -1
- package/components/Search/SearchService.js +0 -72
- package/components/Search/SearchService.js.map +0 -1
- package/components/Search/engines/Engine.js +0 -26
- package/components/Search/engines/Engine.js.map +0 -1
- package/components/Search/engines/StopFinder.js +0 -47
- package/components/Search/engines/StopFinder.js.map +0 -1
- package/components/Search/index.js +0 -6
- package/components/Search/index.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.js +0 -171
- package/components/TrackerControl/TrackerControl.js.map +0 -1
- package/components/TrackerControl/TrackerControl.scss +0 -30
- package/components/TrackerControl/TrackerControl.test.js +0 -17
- package/components/TrackerControl/TrackerControl.test.js.map +0 -1
- package/components/TrackerControl/index.js +0 -3
- package/components/TrackerControl/index.js.map +0 -1
- package/components/Zoom/Zoom.test.js +0 -150
- package/components/Zoom/Zoom.test.js.map +0 -1
- package/images/FilterButton/filter.svg +0 -1
- package/images/FollowButton/follow.svg +0 -1
- package/images/baselayer/osm.baselayer.hot.png +0 -0
- package/images/baselayer/osm.baselayer.png +0 -0
- 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.js +0 -105
- package/utils/KMLFormat.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,36 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
49
|
-
|
|
35
|
+
extent: PropTypes.arrayOf(PropTypes.number),
|
|
50
36
|
/**
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
204
|
+
const backgroundX = margin;
|
|
205
|
+
lineTop -= paddingBackground * 2;
|
|
206
|
+
drawTextBackground(
|
|
307
207
|
destContext,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
369
|
+
scale,
|
|
370
|
+
margin,
|
|
371
|
+
padding,
|
|
372
|
+
void 0,
|
|
373
|
+
"left"
|
|
505
374
|
);
|
|
506
375
|
}
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|