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