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,337 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { configure, mount } from 'enzyme';
|
|
4
|
+
import Adapter from '@cfaester/enzyme-adapter-react-18';
|
|
5
|
+
import 'jest-canvas-mock';
|
|
6
|
+
import renderer from 'react-test-renderer';
|
|
7
|
+
import { Layer } from 'mobility-toolbox-js/ol';
|
|
8
|
+
import LayerTree from './LayerTree';
|
|
9
|
+
|
|
10
|
+
configure({ adapter: new Adapter() });
|
|
11
|
+
|
|
12
|
+
const mountLayerTree = (layers) => {
|
|
13
|
+
return mount(<LayerTree layers={layers} />);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const renderLayerTree = (layers, props) => {
|
|
17
|
+
const component = renderer.create(
|
|
18
|
+
<LayerTree layers={layers} {...(props || {})} />,
|
|
19
|
+
);
|
|
20
|
+
const tree = component.toJSON();
|
|
21
|
+
expect(tree).toMatchSnapshot();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const classItem = '.rs-layer-tree-item';
|
|
25
|
+
const toggleItem = '.rs-layer-tree-toggle';
|
|
26
|
+
|
|
27
|
+
describe('LayerTree', () => {
|
|
28
|
+
let layers;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
layers = [
|
|
32
|
+
new Layer({
|
|
33
|
+
name: 'root',
|
|
34
|
+
}),
|
|
35
|
+
new Layer({
|
|
36
|
+
name: '1',
|
|
37
|
+
children: [
|
|
38
|
+
new Layer({
|
|
39
|
+
name: '1-1',
|
|
40
|
+
group: 'radio',
|
|
41
|
+
properties: {
|
|
42
|
+
radioGroup: 'radio',
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
new Layer({
|
|
46
|
+
name: '1-2',
|
|
47
|
+
group: 'radio',
|
|
48
|
+
properties: {
|
|
49
|
+
radioGroup: 'radio',
|
|
50
|
+
},
|
|
51
|
+
visible: false,
|
|
52
|
+
children: [
|
|
53
|
+
new Layer({
|
|
54
|
+
name: '1-2-1',
|
|
55
|
+
visible: false,
|
|
56
|
+
}),
|
|
57
|
+
new Layer({
|
|
58
|
+
name: '1-2-2',
|
|
59
|
+
visible: false,
|
|
60
|
+
}),
|
|
61
|
+
new Layer({
|
|
62
|
+
name: '2',
|
|
63
|
+
visible: false,
|
|
64
|
+
}),
|
|
65
|
+
],
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
}),
|
|
69
|
+
];
|
|
70
|
+
});
|
|
71
|
+
describe('matches snapshots', () => {
|
|
72
|
+
test('using default properties.', () => {
|
|
73
|
+
renderLayerTree(layers);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('when no layers.', () => {
|
|
77
|
+
const component = renderer.create(<LayerTree layers={[]} />);
|
|
78
|
+
const tree = component.toJSON();
|
|
79
|
+
expect(tree).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('when renderItem is used.', () => {
|
|
83
|
+
renderLayerTree(layers, {
|
|
84
|
+
renderItem: (item) => {
|
|
85
|
+
const { name } = item;
|
|
86
|
+
return <div key={name}>{name}</div>;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('when classNames are used.', () => {
|
|
92
|
+
renderLayerTree(layers, { className: 'foo' });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('when an item is hidden.', () => {
|
|
96
|
+
renderLayerTree(layers, {
|
|
97
|
+
isItemHidden: (item) => {
|
|
98
|
+
return !!item.children.length;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('when an item is hidden (different layer tree levels)', () => {
|
|
104
|
+
renderLayerTree(layers, {
|
|
105
|
+
isItemHidden: (item) => {
|
|
106
|
+
return item.isBaseLayer || item.get('hideInLegend');
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('when an item use renderBeforeItem.', () => {
|
|
112
|
+
renderLayerTree(layers, {
|
|
113
|
+
renderBeforeItem: (layer, level) => {
|
|
114
|
+
const { name } = layer;
|
|
115
|
+
return (
|
|
116
|
+
<div>
|
|
117
|
+
Render name before item: {name}, level: {level}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('when an item use renderAfterItem.', () => {
|
|
125
|
+
renderLayerTree(layers, {
|
|
126
|
+
renderAfterItem: (layer, level) => {
|
|
127
|
+
const { name } = layer;
|
|
128
|
+
return (
|
|
129
|
+
<div>
|
|
130
|
+
Render name after item: {name}, level: {level}
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('when expandChildren is true.', () => {
|
|
138
|
+
renderLayerTree(layers, {
|
|
139
|
+
expandChildren: true,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('when expandChildren is a function.', () => {
|
|
144
|
+
renderLayerTree(layers, {
|
|
145
|
+
expandChildren: (lyrs) => {
|
|
146
|
+
return lyrs.length === 3;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('when items are always expanded', () => {
|
|
152
|
+
const newLayers = [
|
|
153
|
+
new Layer({
|
|
154
|
+
name: 'Expanded layer 1 (because of level 1)',
|
|
155
|
+
visible: true,
|
|
156
|
+
children: [
|
|
157
|
+
new Layer({
|
|
158
|
+
name: 'Expanded layer 1.1 (because of isAlwaysExpanded=true)',
|
|
159
|
+
visible: true,
|
|
160
|
+
properties: {
|
|
161
|
+
isAlwaysExpanded: true,
|
|
162
|
+
},
|
|
163
|
+
children: [
|
|
164
|
+
new Layer({
|
|
165
|
+
name: 'Expanded layer 1.1.1 (because of isAlwaysExpanded=true)',
|
|
166
|
+
visible: true,
|
|
167
|
+
properties: {
|
|
168
|
+
isAlwaysExpanded: true,
|
|
169
|
+
},
|
|
170
|
+
children: [
|
|
171
|
+
new Layer({
|
|
172
|
+
name: 'Visible layer 1.1.1.1 (as parent is expanded)',
|
|
173
|
+
visible: true,
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
}),
|
|
177
|
+
new Layer({
|
|
178
|
+
name: 'Hidden layer 1.1.1 (because of hidden=true)',
|
|
179
|
+
visible: true,
|
|
180
|
+
properties: {
|
|
181
|
+
hideInLegend: true,
|
|
182
|
+
},
|
|
183
|
+
children: [
|
|
184
|
+
new Layer({
|
|
185
|
+
name: 'Invisible layer 1.1.1.1 (as parent is hidden)',
|
|
186
|
+
visible: true,
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
}),
|
|
190
|
+
],
|
|
191
|
+
}),
|
|
192
|
+
new Layer({
|
|
193
|
+
name: 'Expanded layer 1.2 (because of isAlwaysExpanded=true)',
|
|
194
|
+
visible: true,
|
|
195
|
+
properties: {
|
|
196
|
+
isAlwaysExpanded: true,
|
|
197
|
+
},
|
|
198
|
+
children: [
|
|
199
|
+
new Layer({
|
|
200
|
+
name: 'Visible layer 1.2.1 (as parent is expanded)',
|
|
201
|
+
visible: true,
|
|
202
|
+
children: [
|
|
203
|
+
new Layer({
|
|
204
|
+
name: 'Invisible layer 1.2.1.1 (as parent isAlwaysExpanded=false)',
|
|
205
|
+
visible: true,
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
}),
|
|
209
|
+
],
|
|
210
|
+
}),
|
|
211
|
+
],
|
|
212
|
+
}),
|
|
213
|
+
new Layer({
|
|
214
|
+
name: 'Expanded layer 2 (because of level 1)',
|
|
215
|
+
visible: true,
|
|
216
|
+
children: [
|
|
217
|
+
new Layer({
|
|
218
|
+
name: 'Visible layer 2.1 (as parent is expanded)',
|
|
219
|
+
visible: true,
|
|
220
|
+
children: [
|
|
221
|
+
new Layer({
|
|
222
|
+
name: 'Invisible layer 2.1.1 (as parent isAlwaysExpanded=false)',
|
|
223
|
+
visible: true,
|
|
224
|
+
properties: {
|
|
225
|
+
isAlwaysExpanded: true,
|
|
226
|
+
},
|
|
227
|
+
children: [
|
|
228
|
+
new Layer({
|
|
229
|
+
name: 'Invisible layer 2.1.1.1 (as parent is not visible)',
|
|
230
|
+
visible: true,
|
|
231
|
+
}),
|
|
232
|
+
],
|
|
233
|
+
}),
|
|
234
|
+
],
|
|
235
|
+
}),
|
|
236
|
+
new Layer({
|
|
237
|
+
name: 'Visible layer 2.2 (as parent is expanded)',
|
|
238
|
+
visible: true,
|
|
239
|
+
children: [
|
|
240
|
+
new Layer({
|
|
241
|
+
name: 'Invisible layer 2.2.1 (as parent isAlwaysExpanded=false)',
|
|
242
|
+
visible: true,
|
|
243
|
+
children: [
|
|
244
|
+
new Layer({
|
|
245
|
+
name: 'Invisible layer 2.2.1.1 (as parent is not visible)',
|
|
246
|
+
visible: true,
|
|
247
|
+
}),
|
|
248
|
+
],
|
|
249
|
+
}),
|
|
250
|
+
],
|
|
251
|
+
}),
|
|
252
|
+
],
|
|
253
|
+
}),
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
renderLayerTree(newLayers, {
|
|
257
|
+
isItemHidden: (item) => {
|
|
258
|
+
return item.get('hideInLegend');
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('triggers onInputClick', () => {
|
|
265
|
+
let wrapper;
|
|
266
|
+
let spy;
|
|
267
|
+
let spy2;
|
|
268
|
+
const newLayers = [
|
|
269
|
+
new Layer({
|
|
270
|
+
name: 'foo',
|
|
271
|
+
}),
|
|
272
|
+
];
|
|
273
|
+
const expectCalled = () => {
|
|
274
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
275
|
+
expect(spy2).toHaveBeenCalledTimes(0);
|
|
276
|
+
expect(spy.mock.calls[0][0].name).toBe('foo');
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
beforeEach(() => {
|
|
280
|
+
spy = jest.spyOn(LayerTree.prototype, 'onInputClick');
|
|
281
|
+
spy2 = jest.spyOn(LayerTree.prototype, 'onToggle');
|
|
282
|
+
wrapper = mountLayerTree(newLayers);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
afterEach(() => {
|
|
286
|
+
spy.mockRestore();
|
|
287
|
+
spy2.mockRestore();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('when we press enter with keyboard on the label element.', () => {
|
|
291
|
+
wrapper.find('label').at(0).simulate('keypress', { which: 13 });
|
|
292
|
+
expectCalled();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('when we click on input.', () => {
|
|
296
|
+
wrapper.find('input').at(0).simulate('click');
|
|
297
|
+
expectCalled();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('when we click on toggle button (label+arrow) of an item without children.', () => {
|
|
301
|
+
wrapper.find(classItem).first().childAt(1).simulate('click');
|
|
302
|
+
expectCalled();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('triggers onToggle', () => {
|
|
307
|
+
let wrapper;
|
|
308
|
+
let spy;
|
|
309
|
+
const newLayers = [
|
|
310
|
+
new Layer({
|
|
311
|
+
name: '1',
|
|
312
|
+
children: [
|
|
313
|
+
new Layer({
|
|
314
|
+
name: '1-1',
|
|
315
|
+
}),
|
|
316
|
+
new Layer({
|
|
317
|
+
name: '1-1-1',
|
|
318
|
+
}),
|
|
319
|
+
],
|
|
320
|
+
}),
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
const expectCalled = () => {
|
|
324
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
beforeEach(() => {
|
|
328
|
+
spy = jest.spyOn(LayerTree.prototype, 'onToggle');
|
|
329
|
+
wrapper = mountLayerTree(newLayers);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('when we click on toggle button (label+arrow) of an item with children', () => {
|
|
333
|
+
wrapper.find(toggleItem).first().simulate('click');
|
|
334
|
+
expectCalled();
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
The following example demonstrates the use of LayerTree.
|
|
2
|
+
|
|
3
|
+
```jsx
|
|
4
|
+
import React, { useEffect } from 'react';
|
|
5
|
+
import { MapboxLayer, MapboxStyleLayer, Layer } from 'mobility-toolbox-js/ol';
|
|
6
|
+
import { Style, Circle, Stroke, Fill } from 'ol/style';
|
|
7
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
8
|
+
import VectorSource from 'ol/source/Vector';
|
|
9
|
+
import GeoJSONFormat from 'ol/format/GeoJSON';
|
|
10
|
+
import LayerTree from 'react-spatial/components/LayerTree';
|
|
11
|
+
import BasicMap from 'react-spatial/components/BasicMap';
|
|
12
|
+
|
|
13
|
+
const baseBright = new MapboxLayer({
|
|
14
|
+
name: 'Base - Bright',
|
|
15
|
+
group: 'baseLayer',
|
|
16
|
+
url: `https://maps.geops.io/styles/base_bright_v2/style.json?key=${apiKey}`,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const railLines = new MapboxStyleLayer({
|
|
20
|
+
name: 'Railways routes',
|
|
21
|
+
mapboxLayer: baseBright,
|
|
22
|
+
styleLayer: {
|
|
23
|
+
id: 'rail',
|
|
24
|
+
type: 'line',
|
|
25
|
+
source: 'base',
|
|
26
|
+
'source-layer': 'osm_edges',
|
|
27
|
+
filter: ['==', 'vehicle_type_prior', 'Zug'],
|
|
28
|
+
paint: {
|
|
29
|
+
'line-color': 'rgba(255, 0, 0, 1)',
|
|
30
|
+
'line-width': 2,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const passengerFrequencies = new MapboxStyleLayer({
|
|
36
|
+
name: 'Passenger frequencies',
|
|
37
|
+
mapboxLayer: baseBright,
|
|
38
|
+
styleLayer: {
|
|
39
|
+
id: 'passagierfrequenzen',
|
|
40
|
+
type: 'circle',
|
|
41
|
+
source: 'base',
|
|
42
|
+
'source-layer': 'osm_points',
|
|
43
|
+
filter: ['has', 'dwv'],
|
|
44
|
+
paint: {
|
|
45
|
+
'circle-radius': ['*', ['sqrt', ['/', ['get', 'dwv'], Math.PI]], 0.2],
|
|
46
|
+
'circle-color': 'rgb(254, 160, 0)',
|
|
47
|
+
'circle-stroke-width': 2,
|
|
48
|
+
'circle-stroke-color': 'rgb(254, 160, 0)',
|
|
49
|
+
'circle-opacity': [
|
|
50
|
+
'case',
|
|
51
|
+
['boolean', ['feature-state', 'hover'], false],
|
|
52
|
+
1,
|
|
53
|
+
0.7,
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
baseBright.children = [passengerFrequencies, railLines];
|
|
60
|
+
|
|
61
|
+
const baseDark = new MapboxLayer({
|
|
62
|
+
name: 'Base - Dark',
|
|
63
|
+
group: 'baseLayer',
|
|
64
|
+
visible: false,
|
|
65
|
+
url: `https://maps.geops.io/styles/base_dark_v2/style.json?key=${apiKey}`,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const baseTravic = new MapboxLayer({
|
|
69
|
+
url: `https://maps.geops.io/styles/travic_v2/style.json?key=${apiKey}`,
|
|
70
|
+
group: 'baseLayer',
|
|
71
|
+
visible: false,
|
|
72
|
+
properties: {
|
|
73
|
+
hidden: true,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const layers = [baseDark, baseTravic, baseBright];
|
|
78
|
+
|
|
79
|
+
<div className="rs-layer-tree-example">
|
|
80
|
+
<BasicMap
|
|
81
|
+
layers={layers}
|
|
82
|
+
center={[876887.69, 5928515.41]}
|
|
83
|
+
zoom={8}
|
|
84
|
+
tabIndex={0}
|
|
85
|
+
/>
|
|
86
|
+
<LayerTree
|
|
87
|
+
layers={layers}
|
|
88
|
+
isItemHidden={(layer) => layer.get('hidden')}
|
|
89
|
+
expandChildren
|
|
90
|
+
/>
|
|
91
|
+
</div>;
|
|
92
|
+
```
|