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,119 +1,68 @@
|
|
|
1
|
-
import React, { PureComponent } from
|
|
2
|
-
import PropTypes from
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
import VectorLayer from 'ol/layer/Vector';
|
|
16
|
-
import VectorSource from 'ol/source/Vector';
|
|
17
|
-
|
|
18
|
-
import { FaRegDotCircle } from 'react-icons/fa';
|
|
19
|
-
|
|
1
|
+
import React, { PureComponent } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import OLMap from "ol/Map";
|
|
4
|
+
import { transform } from "ol/proj";
|
|
5
|
+
import Point from "ol/geom/Point";
|
|
6
|
+
import Feature from "ol/Feature";
|
|
7
|
+
import { unByKey } from "ol/Observable";
|
|
8
|
+
import Style from "ol/style/Style";
|
|
9
|
+
import Circle from "ol/style/Circle";
|
|
10
|
+
import Fill from "ol/style/Fill";
|
|
11
|
+
import Stroke from "ol/style/Stroke";
|
|
12
|
+
import VectorLayer from "ol/layer/Vector";
|
|
13
|
+
import VectorSource from "ol/source/Vector";
|
|
14
|
+
import { FaRegDotCircle } from "react-icons/fa";
|
|
20
15
|
const propTypes = {
|
|
21
|
-
/**
|
|
22
|
-
* CSS class of the button.
|
|
23
|
-
*/
|
|
24
16
|
className: PropTypes.string,
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Children content of the Geolocation button.
|
|
28
|
-
*/
|
|
29
17
|
children: PropTypes.node,
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
33
|
-
*/
|
|
34
18
|
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Function triggered when geolocating is not successful.
|
|
38
|
-
*/
|
|
39
19
|
onError: PropTypes.func,
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Function triggered after successful geoLocation calls. Takes the ol/map, the current lat/lon coordinate and the component instance as arguments.
|
|
43
|
-
*/
|
|
44
20
|
onSuccess: PropTypes.func,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Function triggered after the geolocation is activated. Takes the ol/map and the component instance as arguments.
|
|
48
|
-
*/
|
|
49
21
|
onActivate: PropTypes.func,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Function triggered after the geolocation is deactivated. Takes the ol/map and the component instance as arguments..
|
|
53
|
-
*/
|
|
54
22
|
onDeactivate: PropTypes.func,
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* If true, the map is not centered after it has been dragged once.
|
|
58
|
-
*/
|
|
59
23
|
noCenterAfterDrag: PropTypes.bool,
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* If true, the map will constantly recenter to the current Position
|
|
63
|
-
*/
|
|
64
24
|
alwaysRecenterToPosition: PropTypes.bool,
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Color (Number array with rgb values) or style function.
|
|
68
|
-
* If a color is given, the style is animated.
|
|
69
|
-
*/
|
|
70
25
|
colorOrStyleFunc: PropTypes.oneOfType([
|
|
71
26
|
PropTypes.arrayOf(PropTypes.number),
|
|
72
|
-
PropTypes.func
|
|
73
|
-
])
|
|
27
|
+
PropTypes.func
|
|
28
|
+
])
|
|
74
29
|
};
|
|
75
|
-
|
|
76
30
|
const defaultProps = {
|
|
77
|
-
className:
|
|
78
|
-
children:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
31
|
+
className: "rs-geolocation",
|
|
32
|
+
children: /* @__PURE__ */ React.createElement(FaRegDotCircle, {
|
|
33
|
+
focusable: false
|
|
34
|
+
}),
|
|
35
|
+
onError: () => {
|
|
36
|
+
},
|
|
37
|
+
onSuccess: () => {
|
|
38
|
+
},
|
|
39
|
+
onActivate: () => {
|
|
40
|
+
},
|
|
41
|
+
onDeactivate: () => {
|
|
42
|
+
},
|
|
83
43
|
noCenterAfterDrag: false,
|
|
84
44
|
alwaysRecenterToPosition: true,
|
|
85
|
-
colorOrStyleFunc: [235, 0, 0]
|
|
45
|
+
colorOrStyleFunc: [235, 0, 0]
|
|
86
46
|
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The GeoLocation component creates a button to display the current device's location on an
|
|
90
|
-
* [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
91
|
-
*/
|
|
92
47
|
class Geolocation extends PureComponent {
|
|
93
48
|
constructor(props) {
|
|
94
49
|
super(props);
|
|
95
|
-
|
|
96
50
|
this.layer = new VectorLayer({
|
|
97
|
-
source: new VectorSource()
|
|
51
|
+
source: new VectorSource()
|
|
98
52
|
});
|
|
99
|
-
|
|
100
53
|
this.isRecenteringToPosition = true;
|
|
101
|
-
|
|
102
54
|
this.state = {
|
|
103
|
-
active: false
|
|
55
|
+
active: false
|
|
104
56
|
};
|
|
105
|
-
this.point =
|
|
57
|
+
this.point = void 0;
|
|
106
58
|
}
|
|
107
|
-
|
|
108
59
|
componentWillUnmount() {
|
|
109
60
|
this.deactivate();
|
|
110
61
|
}
|
|
111
|
-
|
|
112
62
|
toggle() {
|
|
113
63
|
const { active } = this.state;
|
|
114
64
|
const { onError } = this.props;
|
|
115
|
-
const geolocation =
|
|
116
|
-
|
|
65
|
+
const geolocation = "geolocation" in navigator;
|
|
117
66
|
if (!geolocation) {
|
|
118
67
|
onError();
|
|
119
68
|
} else if (!active) {
|
|
@@ -122,89 +71,71 @@ class Geolocation extends PureComponent {
|
|
|
122
71
|
this.deactivate();
|
|
123
72
|
}
|
|
124
73
|
}
|
|
125
|
-
|
|
126
74
|
error() {
|
|
127
75
|
const { onError } = this.props;
|
|
128
|
-
|
|
129
76
|
this.deactivate();
|
|
130
77
|
onError();
|
|
131
78
|
}
|
|
132
|
-
|
|
133
79
|
deactivate() {
|
|
134
80
|
const { map, onDeactivate } = this.props;
|
|
135
81
|
window.clearInterval(this.interval);
|
|
136
82
|
this.layer.setMap(null);
|
|
137
83
|
navigator.geolocation.clearWatch(this.watch);
|
|
138
|
-
|
|
139
84
|
this.setState({
|
|
140
|
-
active: false
|
|
85
|
+
active: false
|
|
141
86
|
});
|
|
142
|
-
|
|
143
87
|
this.isRecenteringToPosition = true;
|
|
144
|
-
this.point =
|
|
88
|
+
this.point = void 0;
|
|
145
89
|
onDeactivate(map, this);
|
|
146
90
|
unByKey(this.dragListener);
|
|
147
91
|
}
|
|
148
|
-
|
|
149
92
|
activate() {
|
|
150
93
|
const { map, noCenterAfterDrag, onActivate } = this.props;
|
|
151
|
-
|
|
152
94
|
this.projection = map.getView().getProjection().getCode();
|
|
153
95
|
this.point = new Point([0, 0]);
|
|
154
96
|
this.highlight();
|
|
155
97
|
this.layer.setMap(map);
|
|
156
98
|
this.setState({ active: true });
|
|
157
|
-
|
|
158
99
|
this.watch = navigator.geolocation.watchPosition(
|
|
159
100
|
this.update.bind(this),
|
|
160
101
|
this.error.bind(this),
|
|
161
102
|
{
|
|
162
|
-
enableHighAccuracy: true
|
|
163
|
-
}
|
|
103
|
+
enableHighAccuracy: true
|
|
104
|
+
}
|
|
164
105
|
);
|
|
165
|
-
|
|
166
106
|
if (noCenterAfterDrag) {
|
|
167
|
-
this.dragListener = map.on(
|
|
107
|
+
this.dragListener = map.on("pointerdrag", () => {
|
|
168
108
|
this.isRecenteringToPosition = false;
|
|
169
109
|
});
|
|
170
110
|
}
|
|
171
|
-
|
|
172
111
|
onActivate(map, this);
|
|
173
112
|
}
|
|
174
|
-
|
|
175
113
|
update({ coords: { latitude, longitude } }) {
|
|
176
114
|
const { map, alwaysRecenterToPosition, onSuccess } = this.props;
|
|
177
|
-
|
|
178
115
|
const position = transform(
|
|
179
116
|
[longitude, latitude],
|
|
180
|
-
|
|
181
|
-
this.projection
|
|
117
|
+
"EPSG:4326",
|
|
118
|
+
this.projection
|
|
182
119
|
);
|
|
183
120
|
this.point.setCoordinates(position);
|
|
184
|
-
|
|
185
121
|
if (this.isRecenteringToPosition) {
|
|
186
122
|
map.getView().setCenter(position);
|
|
187
123
|
if (!alwaysRecenterToPosition) {
|
|
188
124
|
this.isRecenteringToPosition = false;
|
|
189
125
|
}
|
|
190
126
|
}
|
|
191
|
-
|
|
192
127
|
onSuccess(map, [latitude, longitude], this);
|
|
193
128
|
}
|
|
194
|
-
|
|
195
129
|
highlight() {
|
|
196
130
|
const { colorOrStyleFunc } = this.props;
|
|
197
131
|
const feature = new Feature({
|
|
198
|
-
geometry: this.point
|
|
132
|
+
geometry: this.point
|
|
199
133
|
});
|
|
200
|
-
|
|
201
134
|
if (Array.isArray(colorOrStyleFunc)) {
|
|
202
135
|
const color = colorOrStyleFunc;
|
|
203
|
-
|
|
204
136
|
let decrease = true;
|
|
205
137
|
let opacity = 0.5;
|
|
206
138
|
let rotation = 0;
|
|
207
|
-
|
|
208
139
|
window.clearInterval(this.interval);
|
|
209
140
|
this.interval = window.setInterval(() => {
|
|
210
141
|
rotation += 0.03;
|
|
@@ -215,74 +146,60 @@ class Geolocation extends PureComponent {
|
|
|
215
146
|
feature.changed();
|
|
216
147
|
}
|
|
217
148
|
}, 50);
|
|
218
|
-
|
|
219
149
|
feature.setStyle(() => {
|
|
220
150
|
const circleStyle = new Style({
|
|
221
151
|
image: new Circle({
|
|
222
152
|
radius: 20,
|
|
223
153
|
rotation,
|
|
224
154
|
fill: new Fill({
|
|
225
|
-
color:
|
|
155
|
+
color: "rgba(255, 255, 255, 0.01)"
|
|
226
156
|
}),
|
|
227
157
|
stroke: new Stroke({
|
|
228
158
|
lineDash: [30, 10],
|
|
229
159
|
width: 6,
|
|
230
|
-
color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${opacity})
|
|
231
|
-
})
|
|
232
|
-
})
|
|
160
|
+
color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${opacity})`
|
|
161
|
+
})
|
|
162
|
+
})
|
|
233
163
|
});
|
|
234
|
-
|
|
235
164
|
circleStyle.getImage().setRotation(rotation);
|
|
236
|
-
|
|
237
165
|
return [
|
|
238
166
|
new Style({
|
|
239
167
|
image: new Circle({
|
|
240
168
|
radius: 10,
|
|
241
169
|
fill: new Fill({
|
|
242
|
-
color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.5)
|
|
243
|
-
})
|
|
244
|
-
})
|
|
170
|
+
color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.5)`
|
|
171
|
+
})
|
|
172
|
+
})
|
|
245
173
|
}),
|
|
246
|
-
circleStyle
|
|
174
|
+
circleStyle
|
|
247
175
|
];
|
|
248
176
|
});
|
|
249
177
|
} else {
|
|
250
178
|
feature.setStyle(colorOrStyleFunc);
|
|
251
179
|
}
|
|
252
|
-
|
|
253
180
|
this.layer.getSource().clear();
|
|
254
181
|
this.layer.getSource().addFeature(feature);
|
|
255
182
|
}
|
|
256
|
-
|
|
257
183
|
render() {
|
|
258
184
|
const { children, className } = this.props;
|
|
259
|
-
// Remove component props from other HTML props.
|
|
260
185
|
const other = Object.entries(this.props).reduce((props, [key, value]) => {
|
|
261
186
|
return propTypes[key] ? props : { ...props, [key]: value };
|
|
262
187
|
}, {});
|
|
263
188
|
const { active } = this.state;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
277
|
-
{...other}
|
|
278
|
-
>
|
|
279
|
-
{children}
|
|
280
|
-
</div>
|
|
281
|
-
);
|
|
189
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
190
|
+
role: "button",
|
|
191
|
+
tabIndex: "0",
|
|
192
|
+
className: `${className} ${active ? "rs-active" : ""}`,
|
|
193
|
+
onClick: () => {
|
|
194
|
+
return this.toggle();
|
|
195
|
+
},
|
|
196
|
+
onKeyPress: (e) => {
|
|
197
|
+
return e.which === 13 && this.toggle();
|
|
198
|
+
},
|
|
199
|
+
...other
|
|
200
|
+
}, children);
|
|
282
201
|
}
|
|
283
202
|
}
|
|
284
|
-
|
|
285
203
|
Geolocation.propTypes = propTypes;
|
|
286
204
|
Geolocation.defaultProps = defaultProps;
|
|
287
|
-
|
|
288
205
|
export default Geolocation;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Geolocation/Geolocation.js"],
|
|
4
|
+
"sourcesContent": ["import React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\n\nimport OLMap from 'ol/Map';\nimport { transform } from 'ol/proj';\nimport Point from 'ol/geom/Point';\nimport Feature from 'ol/Feature';\nimport { unByKey } from 'ol/Observable';\n\nimport Style from 'ol/style/Style';\nimport Circle from 'ol/style/Circle';\nimport Fill from 'ol/style/Fill';\nimport Stroke from 'ol/style/Stroke';\n\nimport VectorLayer from 'ol/layer/Vector';\nimport VectorSource from 'ol/source/Vector';\n\nimport { FaRegDotCircle } from 'react-icons/fa';\n\nconst propTypes = {\n /**\n * CSS class of the button.\n */\n className: PropTypes.string,\n\n /**\n * Children content of the Geolocation button.\n */\n children: PropTypes.node,\n\n /**\n * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\n map: PropTypes.instanceOf(OLMap).isRequired,\n\n /**\n * Function triggered when geolocating is not successful.\n */\n onError: PropTypes.func,\n\n /**\n * Function triggered after successful geoLocation calls. Takes the ol/map, the current lat/lon coordinate and the component instance as arguments.\n */\n onSuccess: PropTypes.func,\n\n /**\n * Function triggered after the geolocation is activated. Takes the ol/map and the component instance as arguments.\n */\n onActivate: PropTypes.func,\n\n /**\n * Function triggered after the geolocation is deactivated. Takes the ol/map and the component instance as arguments..\n */\n onDeactivate: PropTypes.func,\n\n /**\n * If true, the map is not centered after it has been dragged once.\n */\n noCenterAfterDrag: PropTypes.bool,\n\n /**\n * If true, the map will constantly recenter to the current Position\n */\n alwaysRecenterToPosition: PropTypes.bool,\n\n /**\n * Color (Number array with rgb values) or style function.\n * If a color is given, the style is animated.\n */\n colorOrStyleFunc: PropTypes.oneOfType([\n PropTypes.arrayOf(PropTypes.number),\n PropTypes.func,\n ]),\n};\n\nconst defaultProps = {\n className: 'rs-geolocation',\n children: <FaRegDotCircle focusable={false} />,\n onError: () => {},\n onSuccess: () => {},\n onActivate: () => {},\n onDeactivate: () => {},\n noCenterAfterDrag: false,\n alwaysRecenterToPosition: true,\n colorOrStyleFunc: [235, 0, 0],\n};\n\n/**\n * The GeoLocation component creates a button to display the current device's location on an\n * [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\nclass Geolocation extends PureComponent {\n constructor(props) {\n super(props);\n\n this.layer = new VectorLayer({\n source: new VectorSource(),\n });\n\n this.isRecenteringToPosition = true;\n\n this.state = {\n active: false,\n };\n this.point = undefined;\n }\n\n componentWillUnmount() {\n this.deactivate();\n }\n\n toggle() {\n const { active } = this.state;\n const { onError } = this.props;\n const geolocation = 'geolocation' in navigator;\n\n if (!geolocation) {\n onError();\n } else if (!active) {\n this.activate();\n } else {\n this.deactivate();\n }\n }\n\n error() {\n const { onError } = this.props;\n\n this.deactivate();\n onError();\n }\n\n deactivate() {\n const { map, onDeactivate } = this.props;\n window.clearInterval(this.interval);\n this.layer.setMap(null);\n navigator.geolocation.clearWatch(this.watch);\n\n this.setState({\n active: false,\n });\n\n this.isRecenteringToPosition = true;\n this.point = undefined;\n onDeactivate(map, this);\n unByKey(this.dragListener);\n }\n\n activate() {\n const { map, noCenterAfterDrag, onActivate } = this.props;\n\n this.projection = map.getView().getProjection().getCode();\n this.point = new Point([0, 0]);\n this.highlight();\n this.layer.setMap(map);\n this.setState({ active: true });\n\n this.watch = navigator.geolocation.watchPosition(\n this.update.bind(this),\n this.error.bind(this),\n {\n enableHighAccuracy: true,\n },\n );\n\n if (noCenterAfterDrag) {\n this.dragListener = map.on('pointerdrag', () => {\n this.isRecenteringToPosition = false;\n });\n }\n\n onActivate(map, this);\n }\n\n update({ coords: { latitude, longitude } }) {\n const { map, alwaysRecenterToPosition, onSuccess } = this.props;\n\n const position = transform(\n [longitude, latitude],\n 'EPSG:4326',\n this.projection,\n );\n this.point.setCoordinates(position);\n\n if (this.isRecenteringToPosition) {\n map.getView().setCenter(position);\n if (!alwaysRecenterToPosition) {\n this.isRecenteringToPosition = false;\n }\n }\n\n onSuccess(map, [latitude, longitude], this);\n }\n\n highlight() {\n const { colorOrStyleFunc } = this.props;\n const feature = new Feature({\n geometry: this.point,\n });\n\n if (Array.isArray(colorOrStyleFunc)) {\n const color = colorOrStyleFunc;\n\n let decrease = true;\n let opacity = 0.5;\n let rotation = 0;\n\n window.clearInterval(this.interval);\n this.interval = window.setInterval(() => {\n rotation += 0.03;\n decrease = opacity < 0.1 ? false : decrease;\n decrease = opacity > 0.5 ? true : decrease;\n opacity += decrease ? -0.03 : 0.03;\n if (feature) {\n feature.changed();\n }\n }, 50);\n\n feature.setStyle(() => {\n const circleStyle = new Style({\n image: new Circle({\n radius: 20,\n rotation,\n fill: new Fill({\n color: 'rgba(255, 255, 255, 0.01)',\n }),\n stroke: new Stroke({\n lineDash: [30, 10],\n width: 6,\n color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${opacity})`,\n }),\n }),\n });\n\n circleStyle.getImage().setRotation(rotation);\n\n return [\n new Style({\n image: new Circle({\n radius: 10,\n fill: new Fill({\n color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.5)`,\n }),\n }),\n }),\n circleStyle,\n ];\n });\n } else {\n feature.setStyle(colorOrStyleFunc);\n }\n\n this.layer.getSource().clear();\n this.layer.getSource().addFeature(feature);\n }\n\n render() {\n const { children, className } = this.props;\n // Remove component props from other HTML props.\n const other = Object.entries(this.props).reduce((props, [key, value]) => {\n return propTypes[key] ? props : { ...props, [key]: value };\n }, {});\n const { active } = this.state;\n\n return (\n <div\n role=\"button\"\n tabIndex=\"0\"\n className={`${className} ${active ? 'rs-active' : ''}`}\n onClick={() => {\n return this.toggle();\n }}\n onKeyPress={(e) => {\n return e.which === 13 && this.toggle();\n }}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n >\n {children}\n </div>\n );\n }\n}\n\nGeolocation.propTypes = propTypes;\nGeolocation.defaultProps = defaultProps;\n\nexport default Geolocation;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,qBAAqB;AACrC,OAAO,eAAe;AAEtB,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,OAAO,WAAW;AAClB,OAAO,aAAa;AACpB,SAAS,eAAe;AAExB,OAAO,WAAW;AAClB,OAAO,YAAY;AACnB,OAAO,UAAU;AACjB,OAAO,YAAY;AAEnB,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AAEzB,SAAS,sBAAsB;AAE/B,MAAM,YAAY;AAAA,EAIhB,WAAW,UAAU;AAAA,EAKrB,UAAU,UAAU;AAAA,EAKpB,KAAK,UAAU,WAAW,KAAK,EAAE;AAAA,EAKjC,SAAS,UAAU;AAAA,EAKnB,WAAW,UAAU;AAAA,EAKrB,YAAY,UAAU;AAAA,EAKtB,cAAc,UAAU;AAAA,EAKxB,mBAAmB,UAAU;AAAA,EAK7B,0BAA0B,UAAU;AAAA,EAMpC,kBAAkB,UAAU,UAAU;AAAA,IACpC,UAAU,QAAQ,UAAU,MAAM;AAAA,IAClC,UAAU;AAAA,EACZ,CAAC;AACH;AAEA,MAAM,eAAe;AAAA,EACnB,WAAW;AAAA,EACX,UAAU,oCAAC;AAAA,IAAe,WAAW;AAAA,GAAO;AAAA,E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AQ,EAAE,GAAG,OAAO,CAAC,MAAM,MAAM;AAAA,IAC3D,GAAG,CAAC,CAAC;AACL,UAAM,EAAE,OAAO,IAAI,KAAK;AAExB,WACE,oCAAC;AAAA,MACC,MAAK;AAAA,MACL,UAAS;AAAA,MACT,WAAW,GAAG,aAAa,SAAS,cAAc;AAAA,MAClD,SAAS,MAAM;AACb,eAAO,KAAK,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,CAAC,MAAM;AACjB,eAAO,EAAE,UAAU,MAAM,KAAK,OAAO;AAAA,MACvC;AAAA,MAEC,GAAG;AAAA,OAEH,QACH;AAAA,EAEJ;AACF;AAEA,YAAY,YAAY;AACxB,YAAY,eAAe;AAE3B,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Geolocation";
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { Layer, getLayersAsFlatArray } from "mobility-toolbox-js/ol";
|
|
4
|
+
import { unByKey } from "ol/Observable";
|
|
5
|
+
const propTypes = {
|
|
6
|
+
layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
|
|
7
|
+
className: PropTypes.string,
|
|
8
|
+
padding: PropTypes.number,
|
|
9
|
+
isItemHidden: PropTypes.func,
|
|
10
|
+
getParentClassName: PropTypes.func,
|
|
11
|
+
renderItem: PropTypes.func,
|
|
12
|
+
renderItemContent: PropTypes.func,
|
|
13
|
+
renderBeforeItem: PropTypes.func,
|
|
14
|
+
renderAfterItem: PropTypes.func,
|
|
15
|
+
renderLabel: PropTypes.func,
|
|
16
|
+
titles: PropTypes.shape({
|
|
17
|
+
layerShow: PropTypes.string,
|
|
18
|
+
layerHide: PropTypes.string,
|
|
19
|
+
subLayerShow: PropTypes.string,
|
|
20
|
+
subLayerHide: PropTypes.string
|
|
21
|
+
}),
|
|
22
|
+
expandChildren: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
|
|
23
|
+
t: PropTypes.func
|
|
24
|
+
};
|
|
25
|
+
const defaultProps = {
|
|
26
|
+
layers: [],
|
|
27
|
+
className: "rs-layer-tree",
|
|
28
|
+
padding: 30,
|
|
29
|
+
isItemHidden: () => {
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
getParentClassName: () => {
|
|
33
|
+
return void 0;
|
|
34
|
+
},
|
|
35
|
+
renderItem: null,
|
|
36
|
+
renderItemContent: null,
|
|
37
|
+
renderBeforeItem: null,
|
|
38
|
+
renderAfterItem: null,
|
|
39
|
+
renderLabel: (layer, layerComp) => {
|
|
40
|
+
const { t } = layerComp.props;
|
|
41
|
+
return t(layer.name);
|
|
42
|
+
},
|
|
43
|
+
titles: {
|
|
44
|
+
layerShow: "Show layer",
|
|
45
|
+
layerHide: "Hide layer",
|
|
46
|
+
subLayerShow: "Show sublayer",
|
|
47
|
+
subLayerHide: "Hide sublayer"
|
|
48
|
+
},
|
|
49
|
+
t: (s) => {
|
|
50
|
+
return s;
|
|
51
|
+
},
|
|
52
|
+
expandChildren: false
|
|
53
|
+
};
|
|
54
|
+
class LayerTree extends Component {
|
|
55
|
+
constructor(props) {
|
|
56
|
+
super(props);
|
|
57
|
+
const { layers, isItemHidden } = this.props;
|
|
58
|
+
const initialExpandedLayers = layers ? this.getExpandedLayers(
|
|
59
|
+
layers.filter((l) => {
|
|
60
|
+
return !isItemHidden(l) && (l.children || []).filter((child) => {
|
|
61
|
+
return child.visible;
|
|
62
|
+
}).filter((c) => {
|
|
63
|
+
return !isItemHidden(c);
|
|
64
|
+
}).length;
|
|
65
|
+
})
|
|
66
|
+
) : [];
|
|
67
|
+
this.state = {
|
|
68
|
+
rootLayer: new Layer(),
|
|
69
|
+
expandedLayers: initialExpandedLayers,
|
|
70
|
+
revision: 0
|
|
71
|
+
};
|
|
72
|
+
this.olKeys = [];
|
|
73
|
+
}
|
|
74
|
+
componentDidMount() {
|
|
75
|
+
this.updateLayers();
|
|
76
|
+
}
|
|
77
|
+
componentDidUpdate(prevProps) {
|
|
78
|
+
const { layers } = this.props;
|
|
79
|
+
if (layers !== prevProps.layers) {
|
|
80
|
+
this.updateLayers();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
componentWillUnmount() {
|
|
84
|
+
unByKey(this.olKeys);
|
|
85
|
+
this.olKeys = [];
|
|
86
|
+
}
|
|
87
|
+
onInputClick(layer, toggle = false) {
|
|
88
|
+
if (toggle) {
|
|
89
|
+
this.onToggle(layer);
|
|
90
|
+
} else if (layer.setVisible) {
|
|
91
|
+
layer.setVisible(!layer.visible);
|
|
92
|
+
} else {
|
|
93
|
+
layer.visible = !layer.visible;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
onToggle(layer) {
|
|
97
|
+
const { expandedLayers } = this.state;
|
|
98
|
+
const pos = expandedLayers.indexOf(layer);
|
|
99
|
+
if (pos > -1) {
|
|
100
|
+
expandedLayers.splice(pos, 1);
|
|
101
|
+
} else {
|
|
102
|
+
expandedLayers.push(...this.getExpandedLayers([layer]));
|
|
103
|
+
}
|
|
104
|
+
this.setState({ expandedLayers });
|
|
105
|
+
}
|
|
106
|
+
getExpandedLayers(layers) {
|
|
107
|
+
const { isItemHidden } = this.props;
|
|
108
|
+
const children = layers.flatMap((l) => {
|
|
109
|
+
return l.children.filter((c) => {
|
|
110
|
+
return !isItemHidden(c) && c.get("isAlwaysExpanded");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
if (!children.length) {
|
|
114
|
+
return layers;
|
|
115
|
+
}
|
|
116
|
+
return [...layers, this.getExpandedLayers(children)].flat();
|
|
117
|
+
}
|
|
118
|
+
updateLayers() {
|
|
119
|
+
const { layers, expandChildren } = this.props;
|
|
120
|
+
let rootLayer = new Layer();
|
|
121
|
+
if (Array.isArray(layers)) {
|
|
122
|
+
if (layers.length === 1) {
|
|
123
|
+
[rootLayer] = layers;
|
|
124
|
+
}
|
|
125
|
+
rootLayer = new Layer({ children: layers });
|
|
126
|
+
} else {
|
|
127
|
+
rootLayer = layers;
|
|
128
|
+
}
|
|
129
|
+
getLayersAsFlatArray(rootLayer).forEach((layer) => {
|
|
130
|
+
this.olKeys.push(
|
|
131
|
+
layer.on("propertychange", () => {
|
|
132
|
+
const { revision } = this.state;
|
|
133
|
+
this.setState({ revision: revision + 1 });
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
const state = { rootLayer };
|
|
138
|
+
if (typeof expandChildren === "function" ? expandChildren(layers) : expandChildren) {
|
|
139
|
+
state.expandedLayers = rootLayer.children.flatMap((l) => {
|
|
140
|
+
return this.expandLayer(l);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
this.setState(state);
|
|
144
|
+
}
|
|
145
|
+
expandLayer(layer, expLayers = []) {
|
|
146
|
+
const { isItemHidden } = this.props;
|
|
147
|
+
if (layer.visible && !isItemHidden(layer)) {
|
|
148
|
+
const children = layer.children.filter((c) => {
|
|
149
|
+
return !isItemHidden(c) && !c.get("isAlwaysExpanded");
|
|
150
|
+
}).flatMap((c) => {
|
|
151
|
+
return this.expandLayer(c, expLayers);
|
|
152
|
+
});
|
|
153
|
+
return [...expLayers, ...children, layer];
|
|
154
|
+
}
|
|
155
|
+
return expLayers;
|
|
156
|
+
}
|
|
157
|
+
renderInput(layer, inputProps) {
|
|
158
|
+
const { titles, isItemHidden } = this.props;
|
|
159
|
+
let tabIndex = 0;
|
|
160
|
+
if (!(layer.children || []).filter((c) => {
|
|
161
|
+
return !isItemHidden(c);
|
|
162
|
+
}).length) {
|
|
163
|
+
tabIndex = -1;
|
|
164
|
+
}
|
|
165
|
+
const inputType = layer.get("group") ? "radio" : "checkbox";
|
|
166
|
+
return /* @__PURE__ */ React.createElement("label", {
|
|
167
|
+
className: `rs-layer-tree-input rs-layer-tree-input-${inputType} rs-${inputType}`,
|
|
168
|
+
tabIndex,
|
|
169
|
+
title: layer.visible ? titles.layerHide : titles.layerShow,
|
|
170
|
+
"aria-label": layer.visible ? titles.layerHide : titles.layerShow,
|
|
171
|
+
onKeyPress: (e) => {
|
|
172
|
+
if (e.which === 13) {
|
|
173
|
+
this.onInputClick(layer);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, /* @__PURE__ */ React.createElement("input", {
|
|
177
|
+
type: inputType,
|
|
178
|
+
tabIndex: -1,
|
|
179
|
+
checked: layer.visible,
|
|
180
|
+
readOnly: true,
|
|
181
|
+
onClick: () => {
|
|
182
|
+
return this.onInputClick(layer);
|
|
183
|
+
},
|
|
184
|
+
...inputProps
|
|
185
|
+
}), /* @__PURE__ */ React.createElement("span", null));
|
|
186
|
+
}
|
|
187
|
+
renderArrow(layer) {
|
|
188
|
+
const { isItemHidden } = this.props;
|
|
189
|
+
const { expandedLayers } = this.state;
|
|
190
|
+
if (!(layer.children || []).filter((c) => {
|
|
191
|
+
return !isItemHidden(c);
|
|
192
|
+
}).length || layer.get("isAlwaysExpanded")) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
196
|
+
className: `rs-layer-tree-arrow rs-layer-tree-arrow-${!expandedLayers.includes(layer) ? "collapsed" : "expanded"}`
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
renderToggleButton(layer, toggleProps) {
|
|
200
|
+
const { t, titles, isItemHidden, renderLabel } = this.props;
|
|
201
|
+
const { expandedLayers } = this.state;
|
|
202
|
+
const onInputClick = () => {
|
|
203
|
+
this.onInputClick(
|
|
204
|
+
layer,
|
|
205
|
+
(layer.children || []).filter((c) => {
|
|
206
|
+
return !isItemHidden(c);
|
|
207
|
+
}).length && !layer.get("isAlwaysExpanded")
|
|
208
|
+
);
|
|
209
|
+
};
|
|
210
|
+
const title = `${t(layer.name)} ${expandedLayers.includes(layer) ? titles.subLayerHide : titles.subLayerShow}`;
|
|
211
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
212
|
+
role: "button",
|
|
213
|
+
tabIndex: 0,
|
|
214
|
+
className: "rs-layer-tree-toggle",
|
|
215
|
+
title,
|
|
216
|
+
"aria-expanded": expandedLayers.includes(layer),
|
|
217
|
+
"aria-label": title,
|
|
218
|
+
onClick: onInputClick,
|
|
219
|
+
onKeyPress: onInputClick,
|
|
220
|
+
...toggleProps
|
|
221
|
+
}, /* @__PURE__ */ React.createElement("div", null, renderLabel(layer, this)), this.renderArrow(layer));
|
|
222
|
+
}
|
|
223
|
+
renderItemContent(layer, inputProps = {}, toggleProps = {}) {
|
|
224
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, this.renderInput(layer, inputProps), this.renderToggleButton(layer, toggleProps));
|
|
225
|
+
}
|
|
226
|
+
renderItem(layer, level) {
|
|
227
|
+
const { isItemHidden } = this.props;
|
|
228
|
+
const { expandedLayers } = this.state;
|
|
229
|
+
const {
|
|
230
|
+
renderItem,
|
|
231
|
+
renderItemContent,
|
|
232
|
+
renderBeforeItem,
|
|
233
|
+
renderAfterItem,
|
|
234
|
+
padding,
|
|
235
|
+
getParentClassName
|
|
236
|
+
} = this.props;
|
|
237
|
+
const children = expandedLayers.includes(layer) ? [
|
|
238
|
+
...(layer.children || []).filter((c) => {
|
|
239
|
+
return !isItemHidden(c);
|
|
240
|
+
})
|
|
241
|
+
] : [];
|
|
242
|
+
if (renderItem) {
|
|
243
|
+
return renderItem(layer, this.onInputClick, this.onToggle);
|
|
244
|
+
}
|
|
245
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
246
|
+
className: getParentClassName(),
|
|
247
|
+
key: layer.key
|
|
248
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
249
|
+
className: `rs-layer-tree-item ${layer.visible ? "rs-visible" : ""}`,
|
|
250
|
+
style: {
|
|
251
|
+
paddingLeft: `${padding * level}px`
|
|
252
|
+
}
|
|
253
|
+
}, renderItemContent ? renderItemContent(layer, this) : this.renderItemContent(layer)), renderBeforeItem && renderBeforeItem(layer, level, this), [...children].reverse().map((child) => {
|
|
254
|
+
return this.renderItem(child, level + 1);
|
|
255
|
+
}), renderAfterItem && renderAfterItem(layer, level, this));
|
|
256
|
+
}
|
|
257
|
+
renderTree() {
|
|
258
|
+
const { isItemHidden } = this.props;
|
|
259
|
+
const { rootLayer } = this.state;
|
|
260
|
+
if (!rootLayer?.children?.length) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, rootLayer.children.filter((l) => {
|
|
264
|
+
return !isItemHidden(l);
|
|
265
|
+
}).reverse().map((l) => {
|
|
266
|
+
return this.renderItem(l, 0);
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
render() {
|
|
270
|
+
const { className } = this.props;
|
|
271
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
272
|
+
className
|
|
273
|
+
}, this.renderTree());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
LayerTree.propTypes = propTypes;
|
|
277
|
+
LayerTree.defaultProps = defaultProps;
|
|
278
|
+
export default LayerTree;
|