react-spatial 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/conventional-pr-title.yml +21 -0
- package/.github/workflows/main.yml +28 -0
- package/.husky/commit-msg +4 -0
- package/.husky/post-checkout +4 -0
- package/.husky/post-merge +4 -0
- package/.husky/post-rebase +4 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.whitesource +8 -0
- package/CHANGELOG.md +65 -0
- package/DEVELOP.md +113 -0
- package/__mocks__/mapbox-gl.js +11 -0
- package/__mocks__/resize-observer-polyfill.js +9 -0
- package/babel.config.js +3 -0
- package/commitlint.config.js +1 -0
- package/data/topic1.js +119 -0
- package/data/topic2.js +28 -0
- package/doc/README.md +21 -0
- package/doc/doc-config.json +4 -0
- package/package.json +4 -3
- package/pull_request_template.md +16 -0
- package/renovate.json +4 -0
- package/scripts/read-pkg-json.js +17 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +322 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +69 -0
- package/src/components/BaseLayerSwitcher/README.md +61 -0
- package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +88 -0
- package/src/components/BaseLayerSwitcher/index.js +1 -0
- package/src/components/BasicMap/BasicMap.js +413 -0
- package/src/components/BasicMap/BasicMap.test.js +281 -0
- package/src/components/BasicMap/README.md +18 -0
- package/src/components/BasicMap/index.js +1 -0
- package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.js +320 -93
- package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +148 -0
- package/src/components/CanvasSaveButton/README.md +76 -0
- package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +76 -0
- package/src/components/CanvasSaveButton/index.js +1 -0
- package/src/components/Copyright/Copyright.js +89 -0
- package/src/components/Copyright/Copyright.test.js +134 -0
- package/src/components/Copyright/README.md +36 -0
- package/src/components/Copyright/index.js +1 -0
- package/src/components/FeatureExportButton/FeatureExportButton.js +118 -0
- package/src/components/FeatureExportButton/FeatureExportButton.test.js +417 -0
- package/src/components/FeatureExportButton/README.md +76 -0
- package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +67 -0
- package/src/components/FeatureExportButton/index.js +1 -0
- package/src/components/FitExtent/FitExtent.js +62 -0
- package/src/components/FitExtent/FitExtent.test.js +48 -0
- package/src/components/FitExtent/README.md +34 -0
- package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +13 -0
- package/src/components/FitExtent/index.js +1 -0
- package/{components → src/components}/Geolocation/Geolocation.js +144 -61
- package/src/components/Geolocation/Geolocation.test.js +267 -0
- package/src/components/Geolocation/README.md +25 -0
- package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +92 -0
- package/src/components/Geolocation/index.js +1 -0
- package/src/components/LayerTree/LayerTree.js +487 -0
- package/src/components/LayerTree/LayerTree.test.js +337 -0
- package/src/components/LayerTree/README.md +92 -0
- package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +1746 -0
- package/src/components/LayerTree/index.js +1 -0
- package/src/components/MousePosition/MousePosition.js +175 -0
- package/src/components/MousePosition/MousePosition.test.js +132 -0
- package/src/components/MousePosition/README.md +50 -0
- package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +76 -0
- package/src/components/MousePosition/index.js +1 -0
- package/src/components/NorthArrow/NorthArrow.js +75 -0
- package/src/components/NorthArrow/NorthArrow.test.js +104 -0
- package/src/components/NorthArrow/README.md +59 -0
- package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +117 -0
- package/src/components/NorthArrow/index.js +1 -0
- package/src/components/Overlay/Overlay.js +176 -0
- package/src/components/Overlay/Overlay.test.js +149 -0
- package/src/components/Overlay/README.md +59 -0
- package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +9 -0
- package/src/components/Overlay/index.js +1 -0
- package/src/components/Permalink/Permalink.js +326 -0
- package/src/components/Permalink/Permalink.test.js +285 -0
- package/src/components/Permalink/README.md +105 -0
- package/src/components/Permalink/index.js +1 -0
- package/{components → src/components}/Popup/Popup.js +165 -55
- package/src/components/Popup/Popup.test.js +307 -0
- package/src/components/Popup/README.md +93 -0
- package/src/components/Popup/__snapshots__/Popup.test.js.snap +180 -0
- package/src/components/Popup/index.js +1 -0
- package/src/components/README.md +41 -0
- package/{components → src/components}/ResizeHandler/ResizeHandler.js +50 -15
- package/src/components/ResizeHandler/ResizeHandler.test.js +344 -0
- package/src/components/ResizeHandler/index.js +1 -0
- package/src/components/RouteSchedule/README.md +118 -0
- package/src/components/RouteSchedule/RouteSchedule.js +370 -0
- package/src/components/RouteSchedule/RouteSchedule.test.js +113 -0
- package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +248 -0
- package/src/components/RouteSchedule/index.js +1 -0
- package/src/components/ScaleLine/README.md +29 -0
- package/src/components/ScaleLine/ScaleLine.js +50 -0
- package/src/components/ScaleLine/ScaleLine.test.js +30 -0
- package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +7 -0
- package/src/components/ScaleLine/index.js +1 -0
- package/src/components/StopsFinder/README.md +50 -0
- package/src/components/StopsFinder/StopsFinder.js +284 -0
- package/src/components/StopsFinder/StopsFinder.test.js +17 -0
- package/src/components/StopsFinder/StopsFinderOption.js +61 -0
- package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +133 -0
- package/src/components/StopsFinder/index.js +1 -0
- package/src/components/Zoom/README.md +25 -0
- package/src/components/Zoom/Zoom.js +180 -0
- package/src/components/Zoom/Zoom.test.js +141 -0
- package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +201 -0
- package/src/components/Zoom/index.js +1 -0
- package/{propTypes.js → src/propTypes.js} +16 -12
- package/{setupTests.js → src/setupTests.js} +1 -1
- package/src/styleguidist/ComponentsList.js +52 -0
- package/src/styleguidist/StyleGuide.js +277 -0
- package/src/styleguidist/styleguidist.css +38 -0
- package/src/utils/GlobalsForOle.js +99 -0
- package/src/utils/KML.js +594 -0
- package/src/utils/KML.test.js +337 -0
- package/src/utils/KMLFormat.js +100 -0
- package/src/utils/KMLFormat.test.js +50 -0
- package/{utils → src/utils}/Styles.js +20 -14
- 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/{utils → src/utils}/getPolygonPattern.js +34 -6
- package/src/utils/getPolygonPattern.test.js +61 -0
- package/src/utils/timeUtils.js +52 -0
- package/src/utils/timeUtils.test.js +30 -0
- package/styleguide.config.js +251 -0
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -231
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +0 -7
- package/components/BaseLayerSwitcher/index.js +0 -1
- package/components/BaseLayerSwitcher/index.js.map +0 -7
- package/components/BasicMap/BasicMap.js +0 -278
- package/components/BasicMap/BasicMap.js.map +0 -7
- package/components/BasicMap/index.js +0 -1
- package/components/BasicMap/index.js.map +0 -7
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +0 -7
- package/components/CanvasSaveButton/index.js +0 -1
- package/components/CanvasSaveButton/index.js.map +0 -7
- package/components/Copyright/Copyright.js +0 -55
- package/components/Copyright/Copyright.js.map +0 -7
- package/components/Copyright/index.js +0 -1
- package/components/Copyright/index.js.map +0 -7
- package/components/FeatureExportButton/FeatureExportButton.js +0 -62
- package/components/FeatureExportButton/FeatureExportButton.js.map +0 -7
- package/components/FeatureExportButton/index.js +0 -1
- package/components/FeatureExportButton/index.js.map +0 -7
- package/components/FitExtent/FitExtent.js +0 -32
- package/components/FitExtent/FitExtent.js.map +0 -7
- package/components/FitExtent/index.js +0 -1
- package/components/FitExtent/index.js.map +0 -7
- package/components/Geolocation/Geolocation.js.map +0 -7
- package/components/Geolocation/index.js +0 -1
- package/components/Geolocation/index.js.map +0 -7
- package/components/LayerTree/LayerTree.js +0 -278
- package/components/LayerTree/LayerTree.js.map +0 -7
- package/components/LayerTree/index.js +0 -1
- package/components/LayerTree/index.js.map +0 -7
- package/components/MousePosition/MousePosition.js +0 -110
- package/components/MousePosition/MousePosition.js.map +0 -7
- package/components/MousePosition/index.js +0 -1
- package/components/MousePosition/index.js.map +0 -7
- package/components/NorthArrow/NorthArrow.js +0 -43
- package/components/NorthArrow/NorthArrow.js.map +0 -7
- package/components/NorthArrow/index.js +0 -1
- package/components/NorthArrow/index.js.map +0 -7
- package/components/Overlay/Overlay.js +0 -122
- package/components/Overlay/Overlay.js.map +0 -7
- package/components/Overlay/index.js +0 -1
- package/components/Overlay/index.js.map +0 -7
- package/components/Permalink/Permalink.js +0 -206
- package/components/Permalink/Permalink.js.map +0 -7
- package/components/Permalink/index.js +0 -1
- package/components/Permalink/index.js.map +0 -7
- package/components/Popup/Popup.js.map +0 -7
- package/components/Popup/index.js +0 -1
- package/components/Popup/index.js.map +0 -7
- package/components/ResizeHandler/ResizeHandler.js.map +0 -7
- package/components/ResizeHandler/index.js +0 -1
- package/components/ResizeHandler/index.js.map +0 -7
- package/components/RouteSchedule/RouteSchedule.js +0 -220
- package/components/RouteSchedule/RouteSchedule.js.map +0 -7
- package/components/RouteSchedule/index.js +0 -1
- package/components/RouteSchedule/index.js.map +0 -7
- package/components/ScaleLine/ScaleLine.js +0 -32
- package/components/ScaleLine/ScaleLine.js.map +0 -7
- package/components/ScaleLine/index.js +0 -1
- package/components/ScaleLine/index.js.map +0 -7
- package/components/StopsFinder/StopsFinder.js +0 -210
- package/components/StopsFinder/StopsFinder.js.map +0 -7
- package/components/StopsFinder/StopsFinderOption.js +0 -51
- package/components/StopsFinder/StopsFinderOption.js.map +0 -7
- package/components/StopsFinder/index.js +0 -1
- package/components/StopsFinder/index.js.map +0 -7
- package/components/Zoom/Zoom.js +0 -130
- package/components/Zoom/Zoom.js.map +0 -7
- package/components/Zoom/index.js +0 -1
- package/components/Zoom/index.js.map +0 -7
- package/propTypes.js.map +0 -7
- package/setupTests.js.map +0 -7
- package/utils/GlobalsForOle.js +0 -94
- package/utils/GlobalsForOle.js.map +0 -7
- package/utils/KML.js +0 -412
- package/utils/KML.js.map +0 -7
- package/utils/KMLFormat.js +0 -69
- package/utils/KMLFormat.js.map +0 -7
- package/utils/Styles.js.map +0 -7
- package/utils/getPolygonPattern.js.map +0 -7
- package/utils/timeUtils.js +0 -31
- package/utils/timeUtils.js.map +0 -7
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
- /package/{components → src/components}/BasicMap/BasicMap.md.scss +0 -0
- /package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
- /package/{components → src/components}/Copyright/Copyright.md.scss +0 -0
- /package/{components → src/components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
- /package/{components → src/components}/FitExtent/FitExtent.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.md.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.scss +0 -0
- /package/{components → src/components}/MousePosition/MousePosition.md.scss +0 -0
- /package/{components → src/components}/NorthArrow/NorthArrow.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.md.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.scss +0 -0
- /package/{components → src/components}/Permalink/Permalink.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.md.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.scss +0 -0
- /package/{components → src/components}/ScaleLine/ScaleLine.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.md.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.scss +0 -0
- /package/{images → src/images}/RouteSchedule/firstStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/lastStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/line.png +0 -0
- /package/{images → src/images}/RouteSchedule/station.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.basebright.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.osm.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.travic.png +0 -0
- /package/{images → src/images}/baselayer/open.topo.map.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.hot.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.png +0 -0
- /package/{images → src/images}/favicon.png +0 -0
- /package/{images → src/images}/geops_logo.png +0 -0
- /package/{images → src/images}/geops_logo.svg +0 -0
- /package/{images → src/images}/geops_qr.png +0 -0
- /package/{images → src/images}/mots/bus_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/gondola_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round blue-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-grey-01.svg +0 -0
- /package/{images → src/images}/northArrow.svg +0 -0
- /package/{images → src/images}/northArrow.url.svg +0 -0
- /package/{images → src/images}/northArrowCircle.svg +0 -0
- /package/{images → src/images}/northArrowCircle.url.svg +0 -0
- /package/{themes → src/themes}/README.md +0 -0
- /package/{themes → src/themes}/default/components.scss +0 -0
- /package/{themes → src/themes}/default/examples.scss +0 -0
- /package/{themes → src/themes}/default/index.scss +0 -0
- /package/{themes → src/themes}/default/mixins.scss +0 -0
- /package/{themes → src/themes}/default/variables.scss +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import getPolygonPattern from './getPolygonPattern';
|
|
2
|
+
|
|
3
|
+
describe('getPolygonPattern()', () => {
|
|
4
|
+
test('render pattern with default properties (id=1, color = [235, 0, 0, 1])', () => {
|
|
5
|
+
const color = [235, 0, 0, 1];
|
|
6
|
+
const pattern = getPolygonPattern();
|
|
7
|
+
expect(pattern).toEqual(color);
|
|
8
|
+
expect(pattern.id).toBe();
|
|
9
|
+
expect(pattern.color).toBe();
|
|
10
|
+
expect(pattern.empty).toBe();
|
|
11
|
+
expect(pattern.canvas).toBe();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('render pattern 0 (no fill) color and (light blue) opacity', () => {
|
|
15
|
+
const id = 0;
|
|
16
|
+
const color = [0, 60, 80, 0.41000000000000003];
|
|
17
|
+
const pattern = getPolygonPattern(id, [0, 60, 80, 0.41000000000000003]);
|
|
18
|
+
expect(pattern.id).toBe(id);
|
|
19
|
+
expect(pattern.color).toEqual(color);
|
|
20
|
+
expect(pattern.empty).toBe(true);
|
|
21
|
+
expect(pattern.canvas).toBe();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('render pattern 1 (full by color) color and (light blue) opacity', () => {
|
|
25
|
+
const id = 1;
|
|
26
|
+
const color = [0, 60, 80, 0.41000000000000003];
|
|
27
|
+
const pattern = getPolygonPattern(id, [0, 60, 80, 0.41000000000000003]);
|
|
28
|
+
expect(pattern).toEqual(color);
|
|
29
|
+
expect(pattern.id).toBe();
|
|
30
|
+
expect(pattern.color).toBe();
|
|
31
|
+
expect(pattern.empty).toBe();
|
|
32
|
+
expect(pattern.canvas).toBe();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('render pattern 2 (cross) color and (light blue) opacity', () => {
|
|
36
|
+
const id = 2;
|
|
37
|
+
const color = [0, 60, 80, 0.41000000000000003];
|
|
38
|
+
const pattern = getPolygonPattern(id, [0, 60, 80, 0.41000000000000003]);
|
|
39
|
+
expect(pattern.id).toBe(id);
|
|
40
|
+
expect(pattern.color).toEqual(color);
|
|
41
|
+
expect(pattern.empty).toBe();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('render pattern 3 (diagonal line from bottom-left tot top-right) with color (light blue) and opacity', () => {
|
|
45
|
+
const id = 3;
|
|
46
|
+
const color = [0, 60, 80, 0.41000000000000003];
|
|
47
|
+
const pattern = getPolygonPattern(id, [0, 60, 80, 0.41000000000000003]);
|
|
48
|
+
expect(pattern.id).toBe(id);
|
|
49
|
+
expect(pattern.color).toEqual(color);
|
|
50
|
+
expect(pattern.empty).toBe();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('render pattern 4 (diagonal line from top-left to bottom-right) with color (light blue) and opacity', () => {
|
|
54
|
+
const id = 4;
|
|
55
|
+
const color = [0, 60, 80, 0.41000000000000003];
|
|
56
|
+
const pattern = getPolygonPattern(id, [0, 60, 80, 0.41000000000000003]);
|
|
57
|
+
expect(pattern.id).toBe(id);
|
|
58
|
+
expect(pattern.color).toEqual(color);
|
|
59
|
+
expect(pattern.empty).toBe();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a string representation of a number, with a zero if the number is lower than 10.
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
export const pad = (integer) => {
|
|
6
|
+
return integer < 10 ? `0${integer}` : integer;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a 'hh:mm' string from a time in ms.
|
|
11
|
+
* @param {Number} timeInMs Time in milliseconds.
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
export const getHoursAndMinutes = (timeInMs) => {
|
|
15
|
+
if (!timeInMs || timeInMs <= 0) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const date = new Date(timeInMs);
|
|
19
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns a string representing a delay.
|
|
24
|
+
* @param {Number} timeInMs Delay time in milliseconds.
|
|
25
|
+
* @ignore
|
|
26
|
+
*/
|
|
27
|
+
export const getDelayString = (delayInMs) => {
|
|
28
|
+
let timeInMs = delayInMs;
|
|
29
|
+
if (timeInMs < 0) {
|
|
30
|
+
timeInMs = 0;
|
|
31
|
+
}
|
|
32
|
+
const h = Math.floor(timeInMs / 3600000);
|
|
33
|
+
const m = Math.floor((timeInMs % 3600000) / 60000);
|
|
34
|
+
const s = Math.floor(((timeInMs % 3600000) % 60000) / 1000);
|
|
35
|
+
|
|
36
|
+
if (s === 0 && h === 0 && m === 0) {
|
|
37
|
+
return '0';
|
|
38
|
+
}
|
|
39
|
+
if (s === 0 && h === 0) {
|
|
40
|
+
return `${m}m`;
|
|
41
|
+
}
|
|
42
|
+
if (s === 0) {
|
|
43
|
+
return `${h}h${m}m`;
|
|
44
|
+
}
|
|
45
|
+
if (m === 0 && h === 0) {
|
|
46
|
+
return `${s}s`;
|
|
47
|
+
}
|
|
48
|
+
if (h === 0) {
|
|
49
|
+
return `${m}m${s}s`;
|
|
50
|
+
}
|
|
51
|
+
return `${h}h${m}m${s}s`;
|
|
52
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getHoursAndMinutes, getDelayString } from './timeUtils';
|
|
2
|
+
|
|
3
|
+
const RealDate = Date;
|
|
4
|
+
describe('timeUtils', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
global.Date = jest.fn(() => {
|
|
7
|
+
return {
|
|
8
|
+
getHours: () => {
|
|
9
|
+
return 0;
|
|
10
|
+
},
|
|
11
|
+
getMinutes: () => {
|
|
12
|
+
return 2;
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
Object.assign(Date, RealDate);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
global.Date = RealDate;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('getHoursAndMinutes should be correct.', () => {
|
|
24
|
+
expect(getHoursAndMinutes(123456)).toBe('00:02');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('getDelayString should be correct.', () => {
|
|
28
|
+
expect(getDelayString(123456)).toBe('2m3s');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { version } = require('./package.json');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
version,
|
|
7
|
+
template: {
|
|
8
|
+
favicon: 'images/favicon.png',
|
|
9
|
+
head: {
|
|
10
|
+
links: [
|
|
11
|
+
{
|
|
12
|
+
rel: 'stylesheet',
|
|
13
|
+
href: 'https://fonts.googleapis.com/css?family=Lato:400,700',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
assetsDir: 'src/',
|
|
19
|
+
styleguideDir: 'styleguide-build',
|
|
20
|
+
require: [
|
|
21
|
+
path.join(__dirname, 'src/themes/default/examples.scss'),
|
|
22
|
+
path.join(__dirname, 'src/styleguidist/styleguidist.css'),
|
|
23
|
+
'ol/ol.css',
|
|
24
|
+
],
|
|
25
|
+
moduleAliases: {
|
|
26
|
+
'react-spatial': path.resolve(__dirname, 'src'),
|
|
27
|
+
},
|
|
28
|
+
sections: [
|
|
29
|
+
{
|
|
30
|
+
name: '',
|
|
31
|
+
|
|
32
|
+
content: 'README.md',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Maps',
|
|
36
|
+
description:
|
|
37
|
+
'A collection of React components for spatial web development of map components.',
|
|
38
|
+
components: [
|
|
39
|
+
'src/components/BaseLayerSwitcher/[A-Z]*.js',
|
|
40
|
+
'src/components/BasicMap/[A-Z]*.js',
|
|
41
|
+
'src/components/CanvasSaveButton/[A-Z]*.js',
|
|
42
|
+
'src/components/Copyright/[A-Z]*.js',
|
|
43
|
+
'src/components/FeatureExportButton/[A-Z]*.js',
|
|
44
|
+
'src/components/FitExtent/[A-Z]*.js',
|
|
45
|
+
'src/components/Geolocation/[A-Z]*.js',
|
|
46
|
+
'src/components/LayerTree/[A-Z]*.js',
|
|
47
|
+
'src/components/MousePosition/[A-Z]*.js',
|
|
48
|
+
'src/components/NorthArrow/[A-Z]*.js',
|
|
49
|
+
'src/components/Permalink/[A-Z]*.js',
|
|
50
|
+
'src/components/Popup/[A-Z]*.js',
|
|
51
|
+
'src/components/Overlay/[A-Z]*.js',
|
|
52
|
+
'src/components/ScaleLine/[A-Z]*.js',
|
|
53
|
+
'src/components/Zoom/[A-Z]*.js',
|
|
54
|
+
],
|
|
55
|
+
exampleMode: 'expand', // 'hide' | 'collapse' | 'expand'
|
|
56
|
+
usageMode: 'collapse', // 'hide' | 'collapse' | 'expand'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Realtime',
|
|
60
|
+
description:
|
|
61
|
+
'A collection of React components for spatial web development of realtime components.',
|
|
62
|
+
components: ['src/components/RouteSchedule/[A-Z]*.js'],
|
|
63
|
+
exampleMode: 'expand', // 'hide' | 'collapse' | 'expand'
|
|
64
|
+
usageMode: 'collapse', // 'hide' | 'collapse' | 'expand'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Stops',
|
|
68
|
+
description:
|
|
69
|
+
'A collection of React components for spatial web development of stops components.',
|
|
70
|
+
components: ['src/components/StopsFinder/StopsFinder.js'],
|
|
71
|
+
exampleMode: 'expand', // 'hide' | 'collapse' | 'expand'
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
webpackConfig: {
|
|
75
|
+
optimization: {
|
|
76
|
+
minimize: false, // Terser minification is broken since webpack 5
|
|
77
|
+
minimizer: [
|
|
78
|
+
// new TerserPlugin({
|
|
79
|
+
// test: /build\//,
|
|
80
|
+
// include: /\/build/,
|
|
81
|
+
// }),
|
|
82
|
+
// new TerserPlugin<SwcOptions>({
|
|
83
|
+
// minify: TerserPlugin.swcMinify,
|
|
84
|
+
// terserOptions: {
|
|
85
|
+
// // `swc` options
|
|
86
|
+
// },
|
|
87
|
+
// }),
|
|
88
|
+
// new TerserPlugin<UglifyJSOptions>({
|
|
89
|
+
// minify: TerserPlugin.uglifyJsMinify,
|
|
90
|
+
// terserOptions: {
|
|
91
|
+
// // `uglif-js` options
|
|
92
|
+
// },
|
|
93
|
+
// }),
|
|
94
|
+
new TerserPlugin({
|
|
95
|
+
minify: TerserPlugin.esbuildMinify,
|
|
96
|
+
// test: /Line\.js$/,
|
|
97
|
+
terserOptions: {
|
|
98
|
+
// `esbuild` options
|
|
99
|
+
// loader: '.js=jsx',
|
|
100
|
+
loader: 'jsx',
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
module: {
|
|
106
|
+
rules: [
|
|
107
|
+
// Babel loader, will use your project’s .babelrc
|
|
108
|
+
// Transpile js
|
|
109
|
+
{
|
|
110
|
+
// Match js, jsx, ts & tsx files
|
|
111
|
+
test: /\.[jt]sx?$/,
|
|
112
|
+
loader: 'esbuild-loader',
|
|
113
|
+
options: {
|
|
114
|
+
// JavaScript version to compile to
|
|
115
|
+
target: 'es2015',
|
|
116
|
+
loader: 'jsx',
|
|
117
|
+
minify: true,
|
|
118
|
+
sourcemap: true,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
// Load css and scss files.
|
|
122
|
+
{
|
|
123
|
+
test: /\.s?css$/,
|
|
124
|
+
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
test: /^((?!url).)*\.svg$/,
|
|
128
|
+
exclude: [
|
|
129
|
+
path.resolve(__dirname, 'node_modules', '@geops', 'geops-ui'),
|
|
130
|
+
],
|
|
131
|
+
use: [
|
|
132
|
+
{ loader: 'babel-loader' },
|
|
133
|
+
{
|
|
134
|
+
loader: 'react-svg-loader',
|
|
135
|
+
options: {
|
|
136
|
+
jsx: true, // true outputs JSX tags
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
test: /^((?!url).)*\.svg$/,
|
|
143
|
+
include: [
|
|
144
|
+
path.resolve(__dirname, 'node_modules', '@geops', 'geops-ui'), // Load geops-ui SVGs using file-loader
|
|
145
|
+
],
|
|
146
|
+
use: [
|
|
147
|
+
{
|
|
148
|
+
loader: require.resolve('@svgr/webpack'),
|
|
149
|
+
options: {
|
|
150
|
+
svgoConfig: {
|
|
151
|
+
plugins: [
|
|
152
|
+
{
|
|
153
|
+
removeViewBox: false,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
loader: 'file-loader',
|
|
161
|
+
options: {
|
|
162
|
+
jsx: true,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
test: /\.url\.svg$/,
|
|
169
|
+
loader: 'url-loader',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
test: /\.png$|.ico$/,
|
|
173
|
+
use: [
|
|
174
|
+
{
|
|
175
|
+
loader: 'url-loader',
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
theme: {
|
|
183
|
+
color: {
|
|
184
|
+
links: '#6987a1',
|
|
185
|
+
linkHover: '#76B833',
|
|
186
|
+
},
|
|
187
|
+
fontFamily: {
|
|
188
|
+
base: 'Lato',
|
|
189
|
+
},
|
|
190
|
+
fontSize: {
|
|
191
|
+
base: 16,
|
|
192
|
+
text: 17,
|
|
193
|
+
small: 14,
|
|
194
|
+
h1: 48,
|
|
195
|
+
h2: 36,
|
|
196
|
+
h3: 24,
|
|
197
|
+
h4: 18,
|
|
198
|
+
h5: 16,
|
|
199
|
+
h6: 16,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
styles: {
|
|
203
|
+
StyleGuide: {
|
|
204
|
+
'@global body': {
|
|
205
|
+
overflowY: 'hidden',
|
|
206
|
+
overflowX: 'hidden',
|
|
207
|
+
fontFamily: 'Arial',
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
Playground: {
|
|
211
|
+
preview: {
|
|
212
|
+
fontSize: '18px',
|
|
213
|
+
marginBottom: '24px',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
Heading: {
|
|
217
|
+
heading: {
|
|
218
|
+
fontWeight: 900,
|
|
219
|
+
marginTop: 50,
|
|
220
|
+
},
|
|
221
|
+
heading1: {
|
|
222
|
+
marginTop: 0,
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
Para: {
|
|
226
|
+
para: {
|
|
227
|
+
lineHeight: '2.25rem',
|
|
228
|
+
fontSize: '1.125rem',
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
ComponentsList: {
|
|
232
|
+
isChild: {
|
|
233
|
+
fontSize: 16,
|
|
234
|
+
},
|
|
235
|
+
item: {
|
|
236
|
+
margin: '10px 0',
|
|
237
|
+
fontSize: 18,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
Section: {
|
|
241
|
+
root: {
|
|
242
|
+
marginBottom: '120px',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
showSidebar: true,
|
|
247
|
+
styleguideComponents: {
|
|
248
|
+
ComponentsList: path.join(__dirname, 'src/styleguidist/ComponentsList'),
|
|
249
|
+
StyleGuideRenderer: path.join(__dirname, 'src/styleguidist/StyleGuide'),
|
|
250
|
+
},
|
|
251
|
+
};
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import { FaChevronLeft } from "react-icons/fa";
|
|
4
|
-
import { Layer } from "mobility-toolbox-js/ol";
|
|
5
|
-
import { unByKey } from "ol/Observable";
|
|
6
|
-
const propTypes = {
|
|
7
|
-
layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)).isRequired,
|
|
8
|
-
layerImages: PropTypes.objectOf(PropTypes.string),
|
|
9
|
-
className: PropTypes.string,
|
|
10
|
-
altText: PropTypes.string,
|
|
11
|
-
titles: PropTypes.shape({
|
|
12
|
-
button: PropTypes.string,
|
|
13
|
-
openSwitcher: PropTypes.string,
|
|
14
|
-
closeSwitcher: PropTypes.string
|
|
15
|
-
}),
|
|
16
|
-
closeButtonImage: PropTypes.node,
|
|
17
|
-
t: PropTypes.func
|
|
18
|
-
};
|
|
19
|
-
const defaultProps = {
|
|
20
|
-
className: "rs-base-layer-switcher",
|
|
21
|
-
altText: "Source not found",
|
|
22
|
-
titles: {
|
|
23
|
-
button: "Base layers",
|
|
24
|
-
openSwitcher: "Open Baselayer-Switcher",
|
|
25
|
-
closeSwitcher: "Close Baselayer-Switcher"
|
|
26
|
-
},
|
|
27
|
-
closeButtonImage: /* @__PURE__ */ React.createElement(FaChevronLeft, null),
|
|
28
|
-
layerImages: void 0,
|
|
29
|
-
t: (s) => {
|
|
30
|
-
return s;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const getVisibleLayer = (layers) => {
|
|
34
|
-
return layers.find((layer) => {
|
|
35
|
-
return layer.visible;
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
const getNextImage = (currentLayer, layers, layerImages) => {
|
|
39
|
-
const currentIndex = layers.indexOf(
|
|
40
|
-
layers.find((layer) => {
|
|
41
|
-
return layer === currentLayer;
|
|
42
|
-
})
|
|
43
|
-
);
|
|
44
|
-
const nextIndex = currentIndex + 1 === layers.length ? 0 : currentIndex + 1;
|
|
45
|
-
return layerImages[nextIndex];
|
|
46
|
-
};
|
|
47
|
-
const getImageStyle = (url) => {
|
|
48
|
-
return url ? {
|
|
49
|
-
backgroundImage: `url(${url})`,
|
|
50
|
-
backgroundSize: "cover",
|
|
51
|
-
backgroundRepeat: "no-repeat",
|
|
52
|
-
backgroundPosition: "center"
|
|
53
|
-
} : null;
|
|
54
|
-
};
|
|
55
|
-
function BaseLayerSwitcher({
|
|
56
|
-
layers,
|
|
57
|
-
layerImages,
|
|
58
|
-
className,
|
|
59
|
-
altText,
|
|
60
|
-
titles,
|
|
61
|
-
closeButtonImage,
|
|
62
|
-
t
|
|
63
|
-
}) {
|
|
64
|
-
const [switcherOpen, setSwitcherOpen] = useState(false);
|
|
65
|
-
const [isClosed, setIsClosed] = useState(true);
|
|
66
|
-
const [currentLayer, setCurrentLayer] = useState(
|
|
67
|
-
getVisibleLayer(layers) || layers[0]
|
|
68
|
-
);
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
const olKeys = (layers || []).map((layer) => {
|
|
71
|
-
return layer.on("change:visible", (evt) => {
|
|
72
|
-
if (evt.target.visible && currentLayer !== evt.target) {
|
|
73
|
-
setCurrentLayer(evt.target);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
return () => {
|
|
78
|
-
unByKey(olKeys);
|
|
79
|
-
};
|
|
80
|
-
}, [currentLayer, layers]);
|
|
81
|
-
const images = layerImages ? Object.keys(layerImages).map((layerImage) => {
|
|
82
|
-
return layerImages[layerImage];
|
|
83
|
-
}) : layers.map((layer) => {
|
|
84
|
-
return layer.get("previewImage");
|
|
85
|
-
});
|
|
86
|
-
const openClass = switcherOpen ? " rs-open" : "";
|
|
87
|
-
const hiddenStyle = switcherOpen && !isClosed ? "visible" : "hidden";
|
|
88
|
-
const handleSwitcherClick = () => {
|
|
89
|
-
if (layers.length === 2) {
|
|
90
|
-
const nextLayer = layers.find((layer) => {
|
|
91
|
-
return !layer.visible;
|
|
92
|
-
});
|
|
93
|
-
if (currentLayer.setVisible) {
|
|
94
|
-
currentLayer.setVisible(false);
|
|
95
|
-
} else {
|
|
96
|
-
currentLayer.visible = false;
|
|
97
|
-
}
|
|
98
|
-
setCurrentLayer(nextLayer);
|
|
99
|
-
if (nextLayer.setVisible) {
|
|
100
|
-
nextLayer.setVisible(true);
|
|
101
|
-
} else {
|
|
102
|
-
nextLayer.visible = true;
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
return setSwitcherOpen(true) && setIsClosed(false);
|
|
107
|
-
};
|
|
108
|
-
const onLayerSelect = (layer) => {
|
|
109
|
-
if (!switcherOpen) {
|
|
110
|
-
setSwitcherOpen(true);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
setCurrentLayer(layer);
|
|
114
|
-
if (layer.setVisible) {
|
|
115
|
-
layer.setVisible(true);
|
|
116
|
-
} else {
|
|
117
|
-
layer.visible = true;
|
|
118
|
-
}
|
|
119
|
-
layers.filter((l) => {
|
|
120
|
-
return l !== layer;
|
|
121
|
-
}).forEach((l) => {
|
|
122
|
-
if (l.setVisible) {
|
|
123
|
-
l.setVisible(false);
|
|
124
|
-
} else {
|
|
125
|
-
l.visible = false;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
setSwitcherOpen(false);
|
|
129
|
-
};
|
|
130
|
-
const nextImage = getNextImage(currentLayer, layers, images);
|
|
131
|
-
useEffect(() => {
|
|
132
|
-
if (currentLayer !== getVisibleLayer(layers)) {
|
|
133
|
-
setCurrentLayer(getVisibleLayer(layers) || layers[0]);
|
|
134
|
-
}
|
|
135
|
-
}, [currentLayer, layers]);
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
let timeout;
|
|
138
|
-
if (!switcherOpen) {
|
|
139
|
-
timeout = setTimeout(() => {
|
|
140
|
-
setIsClosed(true);
|
|
141
|
-
}, 200);
|
|
142
|
-
} else {
|
|
143
|
-
timeout = setTimeout(() => {
|
|
144
|
-
setIsClosed(false);
|
|
145
|
-
}, 800);
|
|
146
|
-
}
|
|
147
|
-
return () => {
|
|
148
|
-
return clearTimeout(timeout);
|
|
149
|
-
};
|
|
150
|
-
}, [switcherOpen]);
|
|
151
|
-
if (!layers || layers.length < 2 || !currentLayer) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
const toggleBtn = /* @__PURE__ */ React.createElement("div", {
|
|
155
|
-
className: "rs-base-layer-switcher-btn-wrapper"
|
|
156
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
157
|
-
className: "rs-base-layer-switcher-close-btn",
|
|
158
|
-
role: "button",
|
|
159
|
-
onClick: () => {
|
|
160
|
-
return setSwitcherOpen(false);
|
|
161
|
-
},
|
|
162
|
-
onKeyPress: (e) => {
|
|
163
|
-
return e.which === 13 && setSwitcherOpen(false);
|
|
164
|
-
},
|
|
165
|
-
tabIndex: switcherOpen ? "0" : "-1",
|
|
166
|
-
"aria-label": titles.closeSwitcher,
|
|
167
|
-
title: titles.closeSwitcher
|
|
168
|
-
}, closeButtonImage));
|
|
169
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
170
|
-
className: `${className}${openClass}`
|
|
171
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
172
|
-
className: `rs-base-layer-switcher-button rs-opener${openClass}`,
|
|
173
|
-
role: "button",
|
|
174
|
-
title: titles.openSwitcher,
|
|
175
|
-
"aria-label": titles.openSwitcher,
|
|
176
|
-
onClick: handleSwitcherClick,
|
|
177
|
-
onKeyPress: (e) => {
|
|
178
|
-
if (e.which === 13) {
|
|
179
|
-
handleSwitcherClick();
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
style: getImageStyle(nextImage),
|
|
183
|
-
tabIndex: "0"
|
|
184
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
185
|
-
className: "rs-base-layer-switcher-title"
|
|
186
|
-
}, layers.length !== 2 ? titles.button : layers.find((layer) => {
|
|
187
|
-
return !layer.visible;
|
|
188
|
-
}) && t(
|
|
189
|
-
layers.find((layer) => {
|
|
190
|
-
return !layer.visible;
|
|
191
|
-
}).name
|
|
192
|
-
)), nextImage ? null : /* @__PURE__ */ React.createElement("span", {
|
|
193
|
-
className: "rs-alt-text"
|
|
194
|
-
}, t(altText))), layers.map((layer, idx) => {
|
|
195
|
-
const layerName = layer.name;
|
|
196
|
-
const activeClass = layerName === currentLayer.name ? " rs-active" : "";
|
|
197
|
-
const imageStyle = getImageStyle(
|
|
198
|
-
layerImages ? layerImages[`${layer.key}`] : layer.get("previewImage")
|
|
199
|
-
);
|
|
200
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
201
|
-
key: layer.key,
|
|
202
|
-
className: "rs-base-layer-switcher-btn-wrapper",
|
|
203
|
-
style: {
|
|
204
|
-
overflow: hiddenStyle,
|
|
205
|
-
zIndex: layers.length - idx
|
|
206
|
-
}
|
|
207
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
208
|
-
className: `rs-base-layer-switcher-button${openClass}`,
|
|
209
|
-
role: "button",
|
|
210
|
-
title: t(layerName),
|
|
211
|
-
"aria-label": t(layerName),
|
|
212
|
-
onClick: () => {
|
|
213
|
-
return onLayerSelect(layer);
|
|
214
|
-
},
|
|
215
|
-
onKeyPress: (e) => {
|
|
216
|
-
if (e.which === 13) {
|
|
217
|
-
onLayerSelect(layer);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
style: imageStyle,
|
|
221
|
-
tabIndex: switcherOpen ? "0" : "-1"
|
|
222
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
223
|
-
className: `rs-base-layer-switcher-title${activeClass}`
|
|
224
|
-
}, t(layerName)), imageStyle ? null : /* @__PURE__ */ React.createElement("span", {
|
|
225
|
-
className: "rs-alt-text"
|
|
226
|
-
}, t(altText))));
|
|
227
|
-
}), toggleBtn);
|
|
228
|
-
}
|
|
229
|
-
BaseLayerSwitcher.propTypes = propTypes;
|
|
230
|
-
BaseLayerSwitcher.defaultProps = defaultProps;
|
|
231
|
-
export default BaseLayerSwitcher;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/BaseLayerSwitcher/BaseLayerSwitcher.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable jsx-a11y/interactive-supports-focus */\nimport React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronLeft } from 'react-icons/fa';\nimport { Layer } from 'mobility-toolbox-js/ol';\nimport { unByKey } from 'ol/Observable';\n\nconst propTypes = {\n /**\n * An array of [mobility-toolbox-js layers](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers).\n */\n layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)).isRequired,\n\n /**\n * Object containing relative paths to the base layer images. Object\n * keys need to correspond to layer keys\n */\n layerImages: PropTypes.objectOf(PropTypes.string),\n\n /**\n * CSS class to apply on the container.\n */\n className: PropTypes.string,\n\n /**\n * Alternative text rendered if layer images can't be loaded\n */\n altText: PropTypes.string,\n\n /**\n * Button titles.\n */\n titles: PropTypes.shape({\n button: PropTypes.string,\n openSwitcher: PropTypes.string,\n closeSwitcher: PropTypes.string,\n }),\n\n /**\n * Image (node) rendered in the switcher close button.\n */\n closeButtonImage: PropTypes.node,\n\n /**\n * Translation function.\n * @param {function} Translation function returning the translated string.\n */\n t: PropTypes.func,\n};\n\nconst defaultProps = {\n className: 'rs-base-layer-switcher',\n altText: 'Source not found',\n titles: {\n button: 'Base layers',\n openSwitcher: 'Open Baselayer-Switcher',\n closeSwitcher: 'Close Baselayer-Switcher',\n },\n closeButtonImage: <FaChevronLeft />,\n layerImages: undefined,\n t: (s) => {\n return s;\n },\n};\n\nconst getVisibleLayer = (layers) => {\n return layers.find((layer) => {\n return layer.visible;\n });\n};\n\nconst getNextImage = (currentLayer, layers, layerImages) => {\n const currentIndex = layers.indexOf(\n layers.find((layer) => {\n return layer === currentLayer;\n }),\n );\n const nextIndex = currentIndex + 1 === layers.length ? 0 : currentIndex + 1;\n return layerImages[nextIndex];\n};\n\nconst getImageStyle = (url) => {\n return url\n ? {\n backgroundImage: `url(${url})`,\n backgroundSize: 'cover',\n backgroundRepeat: 'no-repeat',\n backgroundPosition: 'center',\n }\n : null;\n};\n\n/**\n * The BaseLayerSwitcher component renders a button interface for switching the visible\n * [mobility-toolbox-js layer](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers)\n * when defined as base layer.\n */\n\nfunction BaseLayerSwitcher({\n layers,\n layerImages,\n className,\n altText,\n titles,\n closeButtonImage,\n t,\n}) {\n const [switcherOpen, setSwitcherOpen] = useState(false);\n const [isClosed, setIsClosed] = useState(true);\n const [currentLayer, setCurrentLayer] = useState(\n getVisibleLayer(layers) || layers[0],\n );\n\n useEffect(() => {\n // Update the layer selected when a visibility changes.\n const olKeys = (layers || []).map((layer) => {\n return layer.on('change:visible', (evt) => {\n if (evt.target.visible && currentLayer !== evt.target) {\n setCurrentLayer(evt.target);\n }\n });\n });\n return () => {\n unByKey(olKeys);\n };\n }, [currentLayer, layers]);\n\n /* Images are loaded from props if provided, fallback from layer */\n const images = layerImages\n ? Object.keys(layerImages).map((layerImage) => {\n return layerImages[layerImage];\n })\n : layers.map((layer) => {\n return layer.get('previewImage');\n });\n\n const openClass = switcherOpen ? ' rs-open' : '';\n const hiddenStyle = switcherOpen && !isClosed ? 'visible' : 'hidden';\n\n const handleSwitcherClick = () => {\n if (layers.length === 2) {\n /* On only two layer options the opener becomes a layer toggle button */\n const nextLayer = layers.find((layer) => {\n return !layer.visible;\n });\n if (currentLayer.setVisible) {\n currentLayer.setVisible(false);\n } else {\n currentLayer.visible = false;\n }\n setCurrentLayer(nextLayer);\n if (nextLayer.setVisible) {\n nextLayer.setVisible(true);\n } else {\n nextLayer.visible = true;\n }\n return;\n }\n // eslint-disable-next-line consistent-return\n return setSwitcherOpen(true) && setIsClosed(false);\n };\n\n const onLayerSelect = (layer) => {\n if (!switcherOpen) {\n setSwitcherOpen(true);\n return;\n }\n setCurrentLayer(layer);\n if (layer.setVisible) {\n layer.setVisible(true);\n } else {\n // eslint-disable-next-line no-param-reassign\n layer.visible = true;\n }\n layers\n .filter((l) => {\n return l !== layer;\n })\n .forEach((l) => {\n if (l.setVisible) {\n l.setVisible(false);\n } else {\n // eslint-disable-next-line no-param-reassign\n l.visible = false;\n }\n });\n setSwitcherOpen(false);\n };\n\n /* Get next image for closed button */\n const nextImage = getNextImage(currentLayer, layers, images);\n\n useEffect(() => {\n /* Ensure correct layer is active on app load */\n if (currentLayer !== getVisibleLayer(layers)) {\n setCurrentLayer(getVisibleLayer(layers) || layers[0]);\n }\n }, [currentLayer, layers]);\n\n useEffect(() => {\n /* Used for correct layer image render with animation */\n let timeout;\n if (!switcherOpen) {\n timeout = setTimeout(() => {\n setIsClosed(true);\n }, 200);\n } else {\n timeout = setTimeout(() => {\n setIsClosed(false);\n }, 800);\n }\n return () => {\n return clearTimeout(timeout);\n };\n }, [switcherOpen]);\n\n if (!layers || layers.length < 2 || !currentLayer) {\n return null;\n }\n\n const toggleBtn = (\n <div className=\"rs-base-layer-switcher-btn-wrapper\">\n <div\n className=\"rs-base-layer-switcher-close-btn\"\n role=\"button\"\n onClick={() => {\n return setSwitcherOpen(false);\n }}\n onKeyPress={(e) => {\n return e.which === 13 && setSwitcherOpen(false);\n }}\n tabIndex={switcherOpen ? '0' : '-1'}\n aria-label={titles.closeSwitcher}\n title={titles.closeSwitcher}\n >\n {closeButtonImage}\n </div>\n </div>\n );\n\n return (\n <div className={`${className}${openClass}`}>\n <div\n className={`rs-base-layer-switcher-button rs-opener${openClass}`}\n role=\"button\"\n title={titles.openSwitcher}\n aria-label={titles.openSwitcher}\n onClick={handleSwitcherClick}\n onKeyPress={(e) => {\n if (e.which === 13) {\n handleSwitcherClick();\n }\n }}\n style={getImageStyle(nextImage)}\n tabIndex=\"0\"\n >\n <div className=\"rs-base-layer-switcher-title\">\n {layers.length !== 2\n ? titles.button\n : layers.find((layer) => {\n return !layer.visible;\n }) &&\n t(\n layers.find((layer) => {\n return !layer.visible;\n }).name,\n )}\n </div>\n {nextImage ? null : <span className=\"rs-alt-text\">{t(altText)}</span>}\n </div>\n {layers.map((layer, idx) => {\n const layerName = layer.name;\n const activeClass = layerName === currentLayer.name ? ' rs-active' : '';\n const imageStyle = getImageStyle(\n layerImages ? layerImages[`${layer.key}`] : layer.get('previewImage'),\n );\n return (\n <div\n key={layer.key}\n className=\"rs-base-layer-switcher-btn-wrapper\"\n style={{\n /* stylelint-disable-next-line value-keyword-case */\n overflow: hiddenStyle,\n /* stylelint-disable-next-line value-keyword-case */\n zIndex: layers.length - idx,\n }}\n >\n <div\n className={`rs-base-layer-switcher-button${openClass}`}\n role=\"button\"\n title={t(layerName)}\n aria-label={t(layerName)}\n onClick={() => {\n return onLayerSelect(layer);\n }}\n onKeyPress={(e) => {\n if (e.which === 13) {\n onLayerSelect(layer);\n }\n }}\n style={imageStyle}\n tabIndex={switcherOpen ? '0' : '-1'}\n >\n <div className={`rs-base-layer-switcher-title${activeClass}`}>\n {t(layerName)}\n </div>\n {imageStyle ? null : (\n <span className=\"rs-alt-text\">{t(altText)}</span>\n )}\n </div>\n </div>\n );\n })}\n {toggleBtn}\n </div>\n );\n}\n\nBaseLayerSwitcher.propTypes = propTypes;\nBaseLayerSwitcher.defaultProps = defaultProps;\n\nexport default BaseLayerSwitcher;\n"],
|
|
5
|
-
"mappings": "AACA,OAAO,SAAS,UAAU,iBAAiB;AAC3C,OAAO,eAAe;AACtB,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AACtB,SAAS,eAAe;AAExB,MAAM,YAAY;AAAA,EAIhB,QAAQ,UAAU,QAAQ,UAAU,WAAW,KAAK,CAAC,EAAE;AAAA,EAMvD,aAAa,UAAU,SAAS,UAAU,MAAM;AAA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