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
|
@@ -0,0 +1,231 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
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,CA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AClB,wBAAc,KAAK;AAAA,QACrB;AAAA,MACF;AAAA,MACA,OAAO;AAAA,MACP,UAAU,eAAe,MAAM;AAAA,OAE/B,oCAAC;AAAA,MAAI,WAAW,+BAA+B;AAAA,OAC5C,EAAE,SAAS,CACd,GACC,aAAa,OACZ,oCAAC;AAAA,MAAK,WAAU;AAAA,OAAe,EAAE,OAAO,CAAE,CAE9C,CACF;AAAA,EAEJ,CAAC,GACA,SACH;AAEJ;AAEA,kBAAkB,YAAY;AAC9B,kBAAkB,eAAe;AAEjC,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./BaseLayerSwitcher";
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import React, { PureComponent } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { defaults as defaultInteractions } from "ol/interaction";
|
|
4
|
+
import { equals } from "ol/extent";
|
|
5
|
+
import OLMap from "ol/Map";
|
|
6
|
+
import OLCollection from "ol/Collection";
|
|
7
|
+
import View from "ol/View";
|
|
8
|
+
import { unByKey } from "ol/Observable";
|
|
9
|
+
import Interaction from "ol/interaction/Interaction";
|
|
10
|
+
import { Layer } from "mobility-toolbox-js/ol";
|
|
11
|
+
import ResizeHandler from "../ResizeHandler";
|
|
12
|
+
const propTypes = {
|
|
13
|
+
animationOptions: PropTypes.shape({
|
|
14
|
+
center: PropTypes.arrayOf(PropTypes.number),
|
|
15
|
+
resolution: PropTypes.number,
|
|
16
|
+
zoom: PropTypes.number
|
|
17
|
+
}),
|
|
18
|
+
center: PropTypes.arrayOf(PropTypes.number),
|
|
19
|
+
className: PropTypes.string,
|
|
20
|
+
extent: PropTypes.arrayOf(PropTypes.number),
|
|
21
|
+
fitOptions: PropTypes.object,
|
|
22
|
+
interactions: PropTypes.oneOfType([
|
|
23
|
+
PropTypes.arrayOf(PropTypes.instanceOf(Interaction)),
|
|
24
|
+
PropTypes.instanceOf(OLCollection)
|
|
25
|
+
]),
|
|
26
|
+
layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
|
|
27
|
+
map: PropTypes.instanceOf(OLMap),
|
|
28
|
+
onFeaturesClick: PropTypes.func,
|
|
29
|
+
featuresClickOptions: PropTypes.shape({
|
|
30
|
+
layerFilter: PropTypes.func,
|
|
31
|
+
hitTolerance: PropTypes.number,
|
|
32
|
+
checkWrapped: PropTypes.bool
|
|
33
|
+
}),
|
|
34
|
+
onFeaturesHover: PropTypes.func,
|
|
35
|
+
onMapMoved: PropTypes.func,
|
|
36
|
+
resolution: PropTypes.number,
|
|
37
|
+
tabIndex: PropTypes.number,
|
|
38
|
+
style: PropTypes.object,
|
|
39
|
+
ariaLabel: PropTypes.string,
|
|
40
|
+
viewOptions: PropTypes.shape({
|
|
41
|
+
minZoom: PropTypes.number,
|
|
42
|
+
maxZoom: PropTypes.number,
|
|
43
|
+
extent: PropTypes.array,
|
|
44
|
+
projection: PropTypes.string
|
|
45
|
+
}),
|
|
46
|
+
zoom: PropTypes.number
|
|
47
|
+
};
|
|
48
|
+
const defaultProps = {
|
|
49
|
+
animationOptions: void 0,
|
|
50
|
+
center: [0, 0],
|
|
51
|
+
className: "rs-map",
|
|
52
|
+
extent: void 0,
|
|
53
|
+
fitOptions: {
|
|
54
|
+
duration: 1e3,
|
|
55
|
+
padding: [20, 20, 20, 20],
|
|
56
|
+
maxZoom: 23
|
|
57
|
+
},
|
|
58
|
+
style: void 0,
|
|
59
|
+
interactions: null,
|
|
60
|
+
layers: [],
|
|
61
|
+
map: null,
|
|
62
|
+
onFeaturesClick: void 0,
|
|
63
|
+
featuresClickOptions: {
|
|
64
|
+
hitTolerance: 0
|
|
65
|
+
},
|
|
66
|
+
onFeaturesHover: void 0,
|
|
67
|
+
onMapMoved: void 0,
|
|
68
|
+
resolution: void 0,
|
|
69
|
+
tabIndex: void 0,
|
|
70
|
+
ariaLabel: "map",
|
|
71
|
+
viewOptions: {
|
|
72
|
+
minZoom: 0,
|
|
73
|
+
maxZoom: 22,
|
|
74
|
+
extent: void 0,
|
|
75
|
+
projection: "EPSG:3857"
|
|
76
|
+
},
|
|
77
|
+
zoom: 1
|
|
78
|
+
};
|
|
79
|
+
class BasicMap extends PureComponent {
|
|
80
|
+
constructor(props) {
|
|
81
|
+
super(props);
|
|
82
|
+
const { map, interactions } = this.props;
|
|
83
|
+
this.map = map || new OLMap({
|
|
84
|
+
controls: [],
|
|
85
|
+
interactions: interactions || defaultInteractions({
|
|
86
|
+
altShiftDragRotate: false,
|
|
87
|
+
pinchRotate: false
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
this.state = {
|
|
91
|
+
node: null
|
|
92
|
+
};
|
|
93
|
+
this.layers = [];
|
|
94
|
+
this.moveEndRef = null;
|
|
95
|
+
this.singleClickRef = null;
|
|
96
|
+
this.pointerMoveRef = null;
|
|
97
|
+
this.setNode = this.setNode.bind(this);
|
|
98
|
+
}
|
|
99
|
+
componentDidMount() {
|
|
100
|
+
const { layers, extent, viewOptions, center, zoom, resolution } = this.props;
|
|
101
|
+
const { node } = this.state;
|
|
102
|
+
this.map.setTarget(node);
|
|
103
|
+
this.map.setView(new View({ ...viewOptions, center, zoom, resolution }));
|
|
104
|
+
const viewPort = this.map.getViewport();
|
|
105
|
+
viewPort.style.touchAction = "none";
|
|
106
|
+
viewPort.style.msTouchAction = "none";
|
|
107
|
+
viewPort.setAttribute("touch-action", "none");
|
|
108
|
+
if (this.map.getSize() && extent) {
|
|
109
|
+
this.map.getView().fit(extent);
|
|
110
|
+
}
|
|
111
|
+
this.setLayers(layers);
|
|
112
|
+
this.listenMoveEnd();
|
|
113
|
+
this.listenSingleClick();
|
|
114
|
+
this.listenPointerMove();
|
|
115
|
+
}
|
|
116
|
+
componentDidUpdate(prevProps, prevState) {
|
|
117
|
+
const {
|
|
118
|
+
animationOptions,
|
|
119
|
+
center,
|
|
120
|
+
extent,
|
|
121
|
+
fitOptions,
|
|
122
|
+
layers,
|
|
123
|
+
resolution,
|
|
124
|
+
viewOptions,
|
|
125
|
+
zoom,
|
|
126
|
+
onMapMoved,
|
|
127
|
+
onFeaturesClick,
|
|
128
|
+
onFeaturesHover
|
|
129
|
+
} = this.props;
|
|
130
|
+
const { node } = this.state;
|
|
131
|
+
if (prevState.node !== node) {
|
|
132
|
+
this.map.setTarget(node);
|
|
133
|
+
if (!prevState.node && node && extent) {
|
|
134
|
+
this.map.getView().fit(extent);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (prevProps.layers !== layers) {
|
|
138
|
+
this.setLayers(layers, prevProps.layers);
|
|
139
|
+
}
|
|
140
|
+
if (viewOptions && JSON.stringify(viewOptions) !== JSON.stringify(prevProps.viewOptions)) {
|
|
141
|
+
this.map.setView(
|
|
142
|
+
new View({
|
|
143
|
+
...viewOptions,
|
|
144
|
+
center,
|
|
145
|
+
resolution,
|
|
146
|
+
zoom
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const view = this.map.getView();
|
|
151
|
+
if (animationOptions && prevProps.animationOptions !== animationOptions) {
|
|
152
|
+
view.animate(animationOptions);
|
|
153
|
+
}
|
|
154
|
+
if (prevProps.center !== center) {
|
|
155
|
+
view.setCenter(center);
|
|
156
|
+
}
|
|
157
|
+
if (zoom !== prevProps.zoom) {
|
|
158
|
+
view.setZoom(zoom);
|
|
159
|
+
}
|
|
160
|
+
if (resolution !== prevProps.resolution) {
|
|
161
|
+
view.setResolution(resolution);
|
|
162
|
+
}
|
|
163
|
+
if (extent && !equals(extent, prevProps.extent || [])) {
|
|
164
|
+
view.fit(extent, fitOptions);
|
|
165
|
+
}
|
|
166
|
+
if (onMapMoved !== prevProps.onMapMoved) {
|
|
167
|
+
this.listenMoveEnd();
|
|
168
|
+
}
|
|
169
|
+
if (onFeaturesClick !== prevProps.onFeaturesClick) {
|
|
170
|
+
this.listenSingleClick();
|
|
171
|
+
}
|
|
172
|
+
if (onFeaturesHover !== prevProps.onFeaturesHover) {
|
|
173
|
+
this.listenPointerMove();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
componentWillUnmount() {
|
|
177
|
+
unByKey([this.moveEndRef, this.singleClickRef, this.pointerMoveRef]);
|
|
178
|
+
}
|
|
179
|
+
setNode(node) {
|
|
180
|
+
this.setState({ node });
|
|
181
|
+
}
|
|
182
|
+
setLayers(layers = [], prevLayers = []) {
|
|
183
|
+
for (let i = 0; i < prevLayers.length; i += 1) {
|
|
184
|
+
this.terminateLayer(prevLayers[i]);
|
|
185
|
+
}
|
|
186
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
187
|
+
this.initLayer(layers[i]);
|
|
188
|
+
}
|
|
189
|
+
this.layers = layers;
|
|
190
|
+
}
|
|
191
|
+
initLayer(layer) {
|
|
192
|
+
if (layer.attachToMap) {
|
|
193
|
+
layer.attachToMap(this.map);
|
|
194
|
+
}
|
|
195
|
+
if (layer.init) {
|
|
196
|
+
layer.init(this.map);
|
|
197
|
+
}
|
|
198
|
+
if (layer.olLayer && this.map.getLayers() && !this.map.getLayers().getArray().includes(layer.olLayer)) {
|
|
199
|
+
this.map.addLayer(layer.olLayer);
|
|
200
|
+
}
|
|
201
|
+
const layers = layer.children || [];
|
|
202
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
203
|
+
this.initLayer(layers[i]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
terminateLayer(layer) {
|
|
207
|
+
const layers = layer.children || [];
|
|
208
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
209
|
+
this.terminateLayer(layers[i]);
|
|
210
|
+
}
|
|
211
|
+
if (layer.olLayer && this.map.getLayers() && this.map.getLayers().getArray().includes(layer.olLayer)) {
|
|
212
|
+
this.map.removeLayer(layer.olLayer);
|
|
213
|
+
}
|
|
214
|
+
if (layer.terminate) {
|
|
215
|
+
layer.terminate(this.map);
|
|
216
|
+
}
|
|
217
|
+
if (layer.detachFromMap) {
|
|
218
|
+
layer.detachFromMap(this.map);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
listenMoveEnd() {
|
|
222
|
+
const { onMapMoved } = this.props;
|
|
223
|
+
unByKey(this.moveEndRef);
|
|
224
|
+
if (!onMapMoved) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.moveEndRef = this.map.on("moveend", (evt) => {
|
|
228
|
+
return onMapMoved(evt);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
listenSingleClick() {
|
|
232
|
+
const { onFeaturesClick, featuresClickOptions } = this.props;
|
|
233
|
+
unByKey(this.singleClickRef);
|
|
234
|
+
if (!onFeaturesClick) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.singleClickRef = this.map.on("singleclick", (evt) => {
|
|
238
|
+
const features = evt.map.getFeaturesAtPixel(
|
|
239
|
+
evt.pixel,
|
|
240
|
+
featuresClickOptions
|
|
241
|
+
);
|
|
242
|
+
onFeaturesClick(features || [], evt);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
listenPointerMove() {
|
|
246
|
+
const { onFeaturesHover } = this.props;
|
|
247
|
+
unByKey(this.pointerMoveRef);
|
|
248
|
+
if (!onFeaturesHover) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.pointerMoveRef = this.map.on("pointermove", (evt) => {
|
|
252
|
+
const features = evt.map.getFeaturesAtPixel(evt.pixel);
|
|
253
|
+
onFeaturesHover(features || [], evt);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
render() {
|
|
257
|
+
const { className, tabIndex, ariaLabel, style } = this.props;
|
|
258
|
+
const { node } = this.state;
|
|
259
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
260
|
+
className,
|
|
261
|
+
ref: this.setNode,
|
|
262
|
+
role: "presentation",
|
|
263
|
+
"aria-label": ariaLabel,
|
|
264
|
+
tabIndex,
|
|
265
|
+
style
|
|
266
|
+
}, /* @__PURE__ */ React.createElement(ResizeHandler, {
|
|
267
|
+
maxHeightBrkpts: null,
|
|
268
|
+
maxWidthBrkpts: null,
|
|
269
|
+
observe: node,
|
|
270
|
+
onResize: () => {
|
|
271
|
+
this.map.updateSize();
|
|
272
|
+
}
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
BasicMap.propTypes = propTypes;
|
|
277
|
+
BasicMap.defaultProps = defaultProps;
|
|
278
|
+
export default BasicMap;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/BasicMap/BasicMap.js"],
|
|
4
|
+
"sourcesContent": ["import React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport { defaults as defaultInteractions } from 'ol/interaction';\nimport { equals } from 'ol/extent';\nimport OLMap from 'ol/Map';\nimport OLCollection from 'ol/Collection';\nimport View from 'ol/View';\nimport { unByKey } from 'ol/Observable';\nimport Interaction from 'ol/interaction/Interaction';\nimport { Layer } from 'mobility-toolbox-js/ol';\nimport ResizeHandler from '../ResizeHandler';\n\nconst propTypes = {\n /** Map animation options */\n animationOptions: PropTypes.shape({\n center: PropTypes.arrayOf(PropTypes.number),\n resolution: PropTypes.number,\n zoom: PropTypes.number,\n }),\n\n /** Center of the [ol/View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html). */\n center: PropTypes.arrayOf(PropTypes.number),\n\n /** Class name of the map container */\n className: PropTypes.string,\n\n /** Map extent */\n extent: PropTypes.arrayOf(PropTypes.number),\n\n /** Openlayers [fit options](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html#fit) when extent is updated */\n fitOptions: PropTypes.object,\n\n /** Array of [ol/interaction](https://openlayers.org/en/latest/apidoc/module-ol_interaction_Interaction-Interaction.html). */\n interactions: PropTypes.oneOfType([\n PropTypes.arrayOf(PropTypes.instanceOf(Interaction)),\n PropTypes.instanceOf(OLCollection),\n ]),\n\n /** Array of [mobility-toolbox-js layers](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers) to display. */\n layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),\n\n /** An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html). */\n map: PropTypes.instanceOf(OLMap),\n\n /**\n * Callback when a [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html) is clicked.\n * @param {OLFeature[]} features An array of [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).\n * @param {ol.MapBrowserEvent} event The singleclick [ol/MapBrowserEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:singleclick).\n */\n onFeaturesClick: PropTypes.func,\n\n /**\n * Optional options to pass on feature click. Passed to ol's 'getFeaturesAtPixel' method.\n * https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html#getFeaturesAtPixel\n */\n featuresClickOptions: PropTypes.shape({\n layerFilter: PropTypes.func,\n hitTolerance: PropTypes.number,\n checkWrapped: PropTypes.bool,\n }),\n\n /**\n * Callback when a [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html) is hovered.\n * @param {OLFeature[]} features An array of [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).\n * @param {ol.MapBrowserEvent} event The pointermove [ol/MapBrowserEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:pointermove).\n */\n onFeaturesHover: PropTypes.func,\n\n /**\n * Callback when the map was moved.\n * @param {ol.MapEvent} event The movend [ol/MapEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:moveend).\n */\n onMapMoved: PropTypes.func,\n\n /** Map resolution */\n resolution: PropTypes.number,\n\n /** The tabIndex of the map. */\n tabIndex: PropTypes.number,\n\n /** The style of the map. */\n style: PropTypes.object,\n\n /** HTML aria-label. */\n ariaLabel: PropTypes.string,\n\n /** [ol/View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html) constructor options */\n viewOptions: PropTypes.shape({\n minZoom: PropTypes.number,\n maxZoom: PropTypes.number,\n extent: PropTypes.array,\n projection: PropTypes.string,\n }),\n\n /** Map zoom level */\n zoom: PropTypes.number,\n};\n\nconst defaultProps = {\n animationOptions: undefined,\n center: [0, 0],\n className: 'rs-map',\n extent: undefined,\n fitOptions: {\n duration: 1000,\n padding: [20, 20, 20, 20],\n maxZoom: 23,\n },\n style: undefined,\n interactions: null,\n layers: [],\n map: null,\n onFeaturesClick: undefined,\n featuresClickOptions: {\n hitTolerance: 0,\n },\n onFeaturesHover: undefined,\n onMapMoved: undefined,\n resolution: undefined,\n tabIndex: undefined,\n ariaLabel: 'map',\n viewOptions: {\n minZoom: 0,\n maxZoom: 22,\n extent: undefined,\n projection: 'EPSG:3857',\n },\n zoom: 1,\n};\n\n/**\n * The BasicMap component renders an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n *\n * The map's view is created with the following parameters for the view:\n * - projection: 'EPSG:3857'\n * - zoom: 0\n * - minZoom: 0\n * - maxZoom: 22\n *\n * These options can be overridden using the viewOptions property.\n */\nclass BasicMap extends PureComponent {\n constructor(props) {\n super(props);\n const { map, interactions } = this.props;\n\n this.map =\n map ||\n new OLMap({\n controls: [],\n interactions:\n interactions ||\n defaultInteractions({\n altShiftDragRotate: false,\n pinchRotate: false,\n }),\n });\n\n this.state = {\n node: null,\n };\n\n this.layers = [];\n this.moveEndRef = null;\n this.singleClickRef = null;\n this.pointerMoveRef = null;\n this.setNode = this.setNode.bind(this);\n }\n\n componentDidMount() {\n const { layers, extent, viewOptions, center, zoom, resolution } =\n this.props;\n const { node } = this.state;\n this.map.setTarget(node);\n\n // We set the view here otherwise the map is not correctly zoomed.\n this.map.setView(new View({ ...viewOptions, center, zoom, resolution }));\n\n // // Since ol 6.1.0 touch-action is set to auto and creates a bad navigation experience on mobile,\n // // so we have to force it to none for mobile.\n // // https://github.com/openlayers/openlayers/pull/10187/files\n const viewPort = this.map.getViewport();\n viewPort.style.touchAction = 'none';\n viewPort.style.msTouchAction = 'none';\n viewPort.setAttribute('touch-action', 'none');\n\n // Fit only work if the map has a size.\n if (this.map.getSize() && extent) {\n this.map.getView().fit(extent);\n }\n\n this.setLayers(layers);\n this.listenMoveEnd();\n this.listenSingleClick();\n this.listenPointerMove();\n }\n\n componentDidUpdate(prevProps, prevState) {\n const {\n animationOptions,\n center,\n extent,\n fitOptions,\n layers,\n resolution,\n viewOptions,\n zoom,\n onMapMoved,\n onFeaturesClick,\n onFeaturesHover,\n } = this.props;\n const { node } = this.state;\n\n if (prevState.node !== node) {\n this.map.setTarget(node);\n\n // When the node is set we reinitialize the extent with the extent property.\n if (!prevState.node && node && extent) {\n this.map.getView().fit(extent);\n }\n }\n\n if (prevProps.layers !== layers) {\n this.setLayers(layers, prevProps.layers);\n }\n\n // Creates a new view if necessary before updating the others prop.\n if (\n viewOptions &&\n JSON.stringify(viewOptions) !== JSON.stringify(prevProps.viewOptions)\n ) {\n // Re-create a view, ol doesn't provide any method to setExtent of view.\n this.map.setView(\n new View({\n ...viewOptions,\n center,\n resolution,\n zoom,\n }),\n );\n }\n\n const view = this.map.getView();\n\n if (animationOptions && prevProps.animationOptions !== animationOptions) {\n view.animate(animationOptions);\n }\n\n if (prevProps.center !== center) {\n view.setCenter(center);\n }\n\n if (zoom !== prevProps.zoom) {\n view.setZoom(zoom);\n }\n\n if (resolution !== prevProps.resolution) {\n view.setResolution(resolution);\n }\n\n if (extent && !equals(extent, prevProps.extent || [])) {\n view.fit(extent, fitOptions);\n }\n\n if (onMapMoved !== prevProps.onMapMoved) {\n this.listenMoveEnd();\n }\n\n if (onFeaturesClick !== prevProps.onFeaturesClick) {\n this.listenSingleClick();\n }\n\n if (onFeaturesHover !== prevProps.onFeaturesHover) {\n this.listenPointerMove();\n }\n }\n\n componentWillUnmount() {\n unByKey([this.moveEndRef, this.singleClickRef, this.pointerMoveRef]);\n }\n\n setNode(node) {\n this.setState({ node });\n }\n\n setLayers(layers = [], prevLayers = []) {\n for (let i = 0; i < prevLayers.length; i += 1) {\n this.terminateLayer(prevLayers[i]);\n }\n for (let i = 0; i < layers.length; i += 1) {\n this.initLayer(layers[i]);\n }\n this.layers = layers;\n }\n\n initLayer(layer) {\n if (layer.attachToMap) {\n layer.attachToMap(this.map);\n }\n\n if (layer.init) {\n layer.init(this.map);\n }\n\n if (\n layer.olLayer &&\n this.map.getLayers() &&\n !this.map.getLayers().getArray().includes(layer.olLayer)\n ) {\n this.map.addLayer(layer.olLayer);\n }\n const layers = layer.children || [];\n for (let i = 0; i < layers.length; i += 1) {\n this.initLayer(layers[i]);\n }\n }\n\n terminateLayer(layer) {\n const layers = layer.children || [];\n for (let i = 0; i < layers.length; i += 1) {\n this.terminateLayer(layers[i]);\n }\n\n if (\n layer.olLayer &&\n this.map.getLayers() &&\n this.map.getLayers().getArray().includes(layer.olLayer)\n ) {\n this.map.removeLayer(layer.olLayer);\n }\n\n if (layer.terminate) {\n layer.terminate(this.map);\n }\n\n if (layer.detachFromMap) {\n layer.detachFromMap(this.map);\n }\n }\n\n listenMoveEnd() {\n const { onMapMoved } = this.props;\n unByKey(this.moveEndRef);\n\n if (!onMapMoved) {\n return;\n }\n\n this.moveEndRef = this.map.on('moveend', (evt) => {\n return onMapMoved(evt);\n });\n }\n\n listenSingleClick() {\n const { onFeaturesClick, featuresClickOptions } = this.props;\n unByKey(this.singleClickRef);\n\n if (!onFeaturesClick) {\n return;\n }\n\n this.singleClickRef = this.map.on('singleclick', (evt) => {\n const features = evt.map.getFeaturesAtPixel(\n evt.pixel,\n featuresClickOptions,\n );\n onFeaturesClick(features || [], evt);\n });\n }\n\n listenPointerMove() {\n const { onFeaturesHover } = this.props;\n unByKey(this.pointerMoveRef);\n\n if (!onFeaturesHover) {\n return;\n }\n\n this.pointerMoveRef = this.map.on('pointermove', (evt) => {\n const features = evt.map.getFeaturesAtPixel(evt.pixel);\n onFeaturesHover(features || [], evt);\n });\n }\n\n render() {\n const { className, tabIndex, ariaLabel, style } = this.props;\n const { node } = this.state;\n return (\n <div\n className={className}\n ref={this.setNode}\n role=\"presentation\"\n aria-label={ariaLabel}\n tabIndex={tabIndex}\n style={style}\n >\n <ResizeHandler\n maxHeightBrkpts={null}\n maxWidthBrkpts={null}\n observe={node}\n onResize={() => {\n this.map.updateSize();\n }}\n />\n </div>\n );\n }\n}\n\nBasicMap.propTypes = propTypes;\nBasicMap.defaultProps = defaultProps;\n\nexport default BasicMap;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,qBAAqB;AACrC,OAAO,eAAe;AACtB,SAAS,YAAY,2BAA2B;AAChD,SAAS,cAAc;AACvB,OAAO,WAAW;AAClB,OAAO,kBAAkB;AACzB,OAAO,UAAU;AACjB,SAAS,eAAe;AACxB,OAAO,iBAAiB;AACxB,SAAS,aAAa;AACtB,OAAO,mBAAmB;AAE1B,MAAM,YAAY;AAAA,EAEhB,kBAAkB,UAAU,MAAM;AAAA,IAChC,QAAQ,UAAU,QAAQ,UAAU,MAAM;AAAA,IAC1C,YAAY,UAAU;AAAA,IACtB,MAAM,UAAU;AAAA,EAClB,CAAC;AAAA,EAGD,QAAQ,UAAU,QAAQ,UAAU,MAAM;AAAA,EAG1C,WAAW,UAAU;AAAA,EAGrB,QAAQ,UAAU,QAAQ,UAAU,MAAM;AAAA,EAG1C,YAAY,UAAU;AAAA,EAGtB,cAAc,UAAU,UAAU;AAAA,IAChC,UAAU,QAAQ,UAAU,WAAW,WAAW,CAAC;AAAA,IACnD,UAAU,WAAW,YAAY;AAAA,EACnC,CAAC;AAAA,EAGD,QAAQ,UAAU,QAAQ,UAAU,WAAW,KAAK,CAAC;AAAA,EAGrD,KAAK,UAAU,WAAW,KAAK;AAAA,EAO/B,iBAAiB,UAAU;AAAA,EAM3B,sBAAsB,UAAU,MAAM;AAAA,IACpC,aAAa,UAAU;AAAA,IACvB,cAAc,UAAU;AAAA,IACxB,cAAc,UAAU;AAAA,EAC1B,CAAC;AAAA,EA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