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