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,413 @@
|
|
|
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
|
+
|
|
13
|
+
const propTypes = {
|
|
14
|
+
/** Map animation options */
|
|
15
|
+
animationOptions: PropTypes.shape({
|
|
16
|
+
center: PropTypes.arrayOf(PropTypes.number),
|
|
17
|
+
resolution: PropTypes.number,
|
|
18
|
+
zoom: PropTypes.number,
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
/** Center of the [ol/View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html). */
|
|
22
|
+
center: PropTypes.arrayOf(PropTypes.number),
|
|
23
|
+
|
|
24
|
+
/** Class name of the map container */
|
|
25
|
+
className: PropTypes.string,
|
|
26
|
+
|
|
27
|
+
/** Map extent */
|
|
28
|
+
extent: PropTypes.arrayOf(PropTypes.number),
|
|
29
|
+
|
|
30
|
+
/** Openlayers [fit options](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html#fit) when extent is updated */
|
|
31
|
+
fitOptions: PropTypes.object,
|
|
32
|
+
|
|
33
|
+
/** Array of [ol/interaction](https://openlayers.org/en/latest/apidoc/module-ol_interaction_Interaction-Interaction.html). */
|
|
34
|
+
interactions: PropTypes.oneOfType([
|
|
35
|
+
PropTypes.arrayOf(PropTypes.instanceOf(Interaction)),
|
|
36
|
+
PropTypes.instanceOf(OLCollection),
|
|
37
|
+
]),
|
|
38
|
+
|
|
39
|
+
/** Array of [mobility-toolbox-js layers](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers) to display. */
|
|
40
|
+
layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
|
|
41
|
+
|
|
42
|
+
/** An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html). */
|
|
43
|
+
map: PropTypes.instanceOf(OLMap),
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Callback when a [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html) is clicked.
|
|
47
|
+
* @param {OLFeature[]} features An array of [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).
|
|
48
|
+
* @param {ol.MapBrowserEvent} event The singleclick [ol/MapBrowserEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:singleclick).
|
|
49
|
+
*/
|
|
50
|
+
onFeaturesClick: PropTypes.func,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional options to pass on feature click. Passed to ol's 'getFeaturesAtPixel' method.
|
|
54
|
+
* https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html#getFeaturesAtPixel
|
|
55
|
+
*/
|
|
56
|
+
featuresClickOptions: PropTypes.shape({
|
|
57
|
+
layerFilter: PropTypes.func,
|
|
58
|
+
hitTolerance: PropTypes.number,
|
|
59
|
+
checkWrapped: PropTypes.bool,
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Callback when a [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html) is hovered.
|
|
64
|
+
* @param {OLFeature[]} features An array of [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).
|
|
65
|
+
* @param {ol.MapBrowserEvent} event The pointermove [ol/MapBrowserEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:pointermove).
|
|
66
|
+
*/
|
|
67
|
+
onFeaturesHover: PropTypes.func,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Callback when the map was moved.
|
|
71
|
+
* @param {ol.MapEvent} event The movend [ol/MapEvent](https://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html#event:moveend).
|
|
72
|
+
*/
|
|
73
|
+
onMapMoved: PropTypes.func,
|
|
74
|
+
|
|
75
|
+
/** Map resolution */
|
|
76
|
+
resolution: PropTypes.number,
|
|
77
|
+
|
|
78
|
+
/** The tabIndex of the map. */
|
|
79
|
+
tabIndex: PropTypes.number,
|
|
80
|
+
|
|
81
|
+
/** The style of the map. */
|
|
82
|
+
style: PropTypes.object,
|
|
83
|
+
|
|
84
|
+
/** HTML aria-label. */
|
|
85
|
+
ariaLabel: PropTypes.string,
|
|
86
|
+
|
|
87
|
+
/** [ol/View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html) constructor options */
|
|
88
|
+
viewOptions: PropTypes.shape({
|
|
89
|
+
minZoom: PropTypes.number,
|
|
90
|
+
maxZoom: PropTypes.number,
|
|
91
|
+
extent: PropTypes.array,
|
|
92
|
+
projection: PropTypes.string,
|
|
93
|
+
}),
|
|
94
|
+
|
|
95
|
+
/** Map zoom level */
|
|
96
|
+
zoom: PropTypes.number,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const defaultProps = {
|
|
100
|
+
animationOptions: undefined,
|
|
101
|
+
center: [0, 0],
|
|
102
|
+
className: 'rs-map',
|
|
103
|
+
extent: undefined,
|
|
104
|
+
fitOptions: {
|
|
105
|
+
duration: 1000,
|
|
106
|
+
padding: [20, 20, 20, 20],
|
|
107
|
+
maxZoom: 23,
|
|
108
|
+
},
|
|
109
|
+
style: undefined,
|
|
110
|
+
interactions: null,
|
|
111
|
+
layers: [],
|
|
112
|
+
map: null,
|
|
113
|
+
onFeaturesClick: undefined,
|
|
114
|
+
featuresClickOptions: {
|
|
115
|
+
hitTolerance: 0,
|
|
116
|
+
},
|
|
117
|
+
onFeaturesHover: undefined,
|
|
118
|
+
onMapMoved: undefined,
|
|
119
|
+
resolution: undefined,
|
|
120
|
+
tabIndex: undefined,
|
|
121
|
+
ariaLabel: 'map',
|
|
122
|
+
viewOptions: {
|
|
123
|
+
minZoom: 0,
|
|
124
|
+
maxZoom: 22,
|
|
125
|
+
extent: undefined,
|
|
126
|
+
projection: 'EPSG:3857',
|
|
127
|
+
},
|
|
128
|
+
zoom: 1,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The BasicMap component renders an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
133
|
+
*
|
|
134
|
+
* The map's view is created with the following parameters for the view:
|
|
135
|
+
* - projection: 'EPSG:3857'
|
|
136
|
+
* - zoom: 0
|
|
137
|
+
* - minZoom: 0
|
|
138
|
+
* - maxZoom: 22
|
|
139
|
+
*
|
|
140
|
+
* These options can be overridden using the viewOptions property.
|
|
141
|
+
*/
|
|
142
|
+
class BasicMap extends PureComponent {
|
|
143
|
+
constructor(props) {
|
|
144
|
+
super(props);
|
|
145
|
+
const { map, interactions } = this.props;
|
|
146
|
+
|
|
147
|
+
this.map =
|
|
148
|
+
map ||
|
|
149
|
+
new OLMap({
|
|
150
|
+
controls: [],
|
|
151
|
+
interactions:
|
|
152
|
+
interactions ||
|
|
153
|
+
defaultInteractions({
|
|
154
|
+
altShiftDragRotate: false,
|
|
155
|
+
pinchRotate: false,
|
|
156
|
+
}),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this.state = {
|
|
160
|
+
node: null,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
this.layers = [];
|
|
164
|
+
this.moveEndRef = null;
|
|
165
|
+
this.singleClickRef = null;
|
|
166
|
+
this.pointerMoveRef = null;
|
|
167
|
+
this.setNode = this.setNode.bind(this);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
componentDidMount() {
|
|
171
|
+
const { layers, extent, viewOptions, center, zoom, resolution } =
|
|
172
|
+
this.props;
|
|
173
|
+
const { node } = this.state;
|
|
174
|
+
this.map.setTarget(node);
|
|
175
|
+
|
|
176
|
+
// We set the view here otherwise the map is not correctly zoomed.
|
|
177
|
+
this.map.setView(new View({ ...viewOptions, center, zoom, resolution }));
|
|
178
|
+
|
|
179
|
+
// // Since ol 6.1.0 touch-action is set to auto and creates a bad navigation experience on mobile,
|
|
180
|
+
// // so we have to force it to none for mobile.
|
|
181
|
+
// // https://github.com/openlayers/openlayers/pull/10187/files
|
|
182
|
+
const viewPort = this.map.getViewport();
|
|
183
|
+
viewPort.style.touchAction = 'none';
|
|
184
|
+
viewPort.style.msTouchAction = 'none';
|
|
185
|
+
viewPort.setAttribute('touch-action', 'none');
|
|
186
|
+
|
|
187
|
+
// Fit only work if the map has a size.
|
|
188
|
+
if (this.map.getSize() && extent) {
|
|
189
|
+
this.map.getView().fit(extent);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.setLayers(layers);
|
|
193
|
+
this.listenMoveEnd();
|
|
194
|
+
this.listenSingleClick();
|
|
195
|
+
this.listenPointerMove();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
componentDidUpdate(prevProps, prevState) {
|
|
199
|
+
const {
|
|
200
|
+
animationOptions,
|
|
201
|
+
center,
|
|
202
|
+
extent,
|
|
203
|
+
fitOptions,
|
|
204
|
+
layers,
|
|
205
|
+
resolution,
|
|
206
|
+
viewOptions,
|
|
207
|
+
zoom,
|
|
208
|
+
onMapMoved,
|
|
209
|
+
onFeaturesClick,
|
|
210
|
+
onFeaturesHover,
|
|
211
|
+
} = this.props;
|
|
212
|
+
const { node } = this.state;
|
|
213
|
+
|
|
214
|
+
if (prevState.node !== node) {
|
|
215
|
+
this.map.setTarget(node);
|
|
216
|
+
|
|
217
|
+
// When the node is set we reinitialize the extent with the extent property.
|
|
218
|
+
if (!prevState.node && node && extent) {
|
|
219
|
+
this.map.getView().fit(extent);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (prevProps.layers !== layers) {
|
|
224
|
+
this.setLayers(layers, prevProps.layers);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Creates a new view if necessary before updating the others prop.
|
|
228
|
+
if (
|
|
229
|
+
viewOptions &&
|
|
230
|
+
JSON.stringify(viewOptions) !== JSON.stringify(prevProps.viewOptions)
|
|
231
|
+
) {
|
|
232
|
+
// Re-create a view, ol doesn't provide any method to setExtent of view.
|
|
233
|
+
this.map.setView(
|
|
234
|
+
new View({
|
|
235
|
+
...viewOptions,
|
|
236
|
+
center,
|
|
237
|
+
resolution,
|
|
238
|
+
zoom,
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const view = this.map.getView();
|
|
244
|
+
|
|
245
|
+
if (animationOptions && prevProps.animationOptions !== animationOptions) {
|
|
246
|
+
view.animate(animationOptions);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (prevProps.center !== center) {
|
|
250
|
+
view.setCenter(center);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (zoom !== prevProps.zoom) {
|
|
254
|
+
view.setZoom(zoom);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (resolution !== prevProps.resolution) {
|
|
258
|
+
view.setResolution(resolution);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (extent && !equals(extent, prevProps.extent || [])) {
|
|
262
|
+
view.fit(extent, fitOptions);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (onMapMoved !== prevProps.onMapMoved) {
|
|
266
|
+
this.listenMoveEnd();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (onFeaturesClick !== prevProps.onFeaturesClick) {
|
|
270
|
+
this.listenSingleClick();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (onFeaturesHover !== prevProps.onFeaturesHover) {
|
|
274
|
+
this.listenPointerMove();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
componentWillUnmount() {
|
|
279
|
+
unByKey([this.moveEndRef, this.singleClickRef, this.pointerMoveRef]);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
setNode(node) {
|
|
283
|
+
this.setState({ node });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
setLayers(layers = [], prevLayers = []) {
|
|
287
|
+
for (let i = 0; i < prevLayers.length; i += 1) {
|
|
288
|
+
this.terminateLayer(prevLayers[i]);
|
|
289
|
+
}
|
|
290
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
291
|
+
this.initLayer(layers[i]);
|
|
292
|
+
}
|
|
293
|
+
this.layers = layers;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
initLayer(layer) {
|
|
297
|
+
if (layer.attachToMap) {
|
|
298
|
+
layer.attachToMap(this.map);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (layer.init) {
|
|
302
|
+
layer.init(this.map);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (
|
|
306
|
+
layer.olLayer &&
|
|
307
|
+
this.map.getLayers() &&
|
|
308
|
+
!this.map.getLayers().getArray().includes(layer.olLayer)
|
|
309
|
+
) {
|
|
310
|
+
this.map.addLayer(layer.olLayer);
|
|
311
|
+
}
|
|
312
|
+
const layers = layer.children || [];
|
|
313
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
314
|
+
this.initLayer(layers[i]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
terminateLayer(layer) {
|
|
319
|
+
const layers = layer.children || [];
|
|
320
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
321
|
+
this.terminateLayer(layers[i]);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (
|
|
325
|
+
layer.olLayer &&
|
|
326
|
+
this.map.getLayers() &&
|
|
327
|
+
this.map.getLayers().getArray().includes(layer.olLayer)
|
|
328
|
+
) {
|
|
329
|
+
this.map.removeLayer(layer.olLayer);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (layer.terminate) {
|
|
333
|
+
layer.terminate(this.map);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (layer.detachFromMap) {
|
|
337
|
+
layer.detachFromMap(this.map);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
listenMoveEnd() {
|
|
342
|
+
const { onMapMoved } = this.props;
|
|
343
|
+
unByKey(this.moveEndRef);
|
|
344
|
+
|
|
345
|
+
if (!onMapMoved) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
this.moveEndRef = this.map.on('moveend', (evt) => {
|
|
350
|
+
return onMapMoved(evt);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
listenSingleClick() {
|
|
355
|
+
const { onFeaturesClick, featuresClickOptions } = this.props;
|
|
356
|
+
unByKey(this.singleClickRef);
|
|
357
|
+
|
|
358
|
+
if (!onFeaturesClick) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this.singleClickRef = this.map.on('singleclick', (evt) => {
|
|
363
|
+
const features = evt.map.getFeaturesAtPixel(
|
|
364
|
+
evt.pixel,
|
|
365
|
+
featuresClickOptions,
|
|
366
|
+
);
|
|
367
|
+
onFeaturesClick(features || [], evt);
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
listenPointerMove() {
|
|
372
|
+
const { onFeaturesHover } = this.props;
|
|
373
|
+
unByKey(this.pointerMoveRef);
|
|
374
|
+
|
|
375
|
+
if (!onFeaturesHover) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
this.pointerMoveRef = this.map.on('pointermove', (evt) => {
|
|
380
|
+
const features = evt.map.getFeaturesAtPixel(evt.pixel);
|
|
381
|
+
onFeaturesHover(features || [], evt);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
render() {
|
|
386
|
+
const { className, tabIndex, ariaLabel, style } = this.props;
|
|
387
|
+
const { node } = this.state;
|
|
388
|
+
return (
|
|
389
|
+
<div
|
|
390
|
+
className={className}
|
|
391
|
+
ref={this.setNode}
|
|
392
|
+
role="presentation"
|
|
393
|
+
aria-label={ariaLabel}
|
|
394
|
+
tabIndex={tabIndex}
|
|
395
|
+
style={style}
|
|
396
|
+
>
|
|
397
|
+
<ResizeHandler
|
|
398
|
+
maxHeightBrkpts={null}
|
|
399
|
+
maxWidthBrkpts={null}
|
|
400
|
+
observe={node}
|
|
401
|
+
onResize={() => {
|
|
402
|
+
this.map.updateSize();
|
|
403
|
+
}}
|
|
404
|
+
/>
|
|
405
|
+
</div>
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
BasicMap.propTypes = propTypes;
|
|
411
|
+
BasicMap.defaultProps = defaultProps;
|
|
412
|
+
|
|
413
|
+
export default BasicMap;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import 'jest-canvas-mock';
|
|
2
|
+
import proj4 from 'proj4';
|
|
3
|
+
import { register } from 'ol/proj/proj4';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import ResizeObserver from 'resize-observer-polyfill';
|
|
6
|
+
import { Layer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
import MapEvent from 'ol/MapEvent';
|
|
8
|
+
import OLLayer from 'ol/layer/Vector';
|
|
9
|
+
import OLMap from 'ol/Map';
|
|
10
|
+
import OLView from 'ol/View';
|
|
11
|
+
import { render } from '@testing-library/react';
|
|
12
|
+
import BasicMap from './BasicMap';
|
|
13
|
+
|
|
14
|
+
proj4.defs(
|
|
15
|
+
'EPSG:21781',
|
|
16
|
+
'+proj=somerc +lat_0=46.95240555555556 ' +
|
|
17
|
+
'+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
|
|
18
|
+
'+towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs',
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
register(proj4);
|
|
22
|
+
|
|
23
|
+
const extent = [0, 0, 1000, 1000];
|
|
24
|
+
const olLayers = [
|
|
25
|
+
new Layer({
|
|
26
|
+
name: 'foo',
|
|
27
|
+
olLayer: new OLLayer({}),
|
|
28
|
+
visible: true,
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
describe('BasicMap', () => {
|
|
33
|
+
let olMap;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
const olView = new OLView();
|
|
36
|
+
olMap = new OLMap({ view: olView });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should be rendered', () => {
|
|
40
|
+
const setTarget = jest.spyOn(olMap, 'setTarget');
|
|
41
|
+
render(<BasicMap map={olMap} />);
|
|
42
|
+
expect(setTarget).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should be rendered with touchAction to none', () => {
|
|
46
|
+
render(<BasicMap map={olMap} />);
|
|
47
|
+
expect(olMap.getViewport().style.touchAction).toBe('none');
|
|
48
|
+
expect(olMap.getViewport().style.msTouchAction).toBe('none');
|
|
49
|
+
expect(olMap.getViewport().getAttribute('touch-action')).toBe('none');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('uses onMapMoved function', () => {
|
|
53
|
+
const spy = jest.fn(() => {});
|
|
54
|
+
const spy2 = jest.fn();
|
|
55
|
+
const evt = new MapEvent('moveend', olMap);
|
|
56
|
+
|
|
57
|
+
// Test componentDidMount
|
|
58
|
+
const { rerender } = render(<BasicMap map={olMap} onMapMoved={spy} />);
|
|
59
|
+
olMap.dispatchEvent(evt);
|
|
60
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
61
|
+
expect(spy).toHaveBeenCalledWith(evt);
|
|
62
|
+
|
|
63
|
+
// Test componentDidUpdate
|
|
64
|
+
rerender(<BasicMap map={olMap} onMapMoved={spy2} />);
|
|
65
|
+
olMap.dispatchEvent(evt);
|
|
66
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(spy2).toHaveBeenCalledWith(evt);
|
|
69
|
+
|
|
70
|
+
// Test componentDidUpdate
|
|
71
|
+
rerender(<BasicMap map={olMap} onMapMoved={null} />);
|
|
72
|
+
olMap.dispatchEvent(evt);
|
|
73
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('uses onFeaturesClick function', () => {
|
|
78
|
+
const spy = jest.fn();
|
|
79
|
+
const spy2 = jest.fn();
|
|
80
|
+
const evt = new MapEvent('singleclick', olMap);
|
|
81
|
+
|
|
82
|
+
// Test componentDidMount
|
|
83
|
+
const { rerender } = render(<BasicMap map={olMap} onFeaturesClick={spy} />);
|
|
84
|
+
olMap.dispatchEvent(evt);
|
|
85
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
86
|
+
expect(spy).toHaveBeenCalledWith([], evt);
|
|
87
|
+
|
|
88
|
+
// Test componentDidUpdate
|
|
89
|
+
rerender(<BasicMap map={olMap} onFeaturesClick={spy2} />);
|
|
90
|
+
olMap.dispatchEvent(evt);
|
|
91
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
92
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(spy2).toHaveBeenCalledWith([], evt);
|
|
94
|
+
|
|
95
|
+
// Test componentDidUpdate
|
|
96
|
+
rerender(<BasicMap map={olMap} onFeaturesClick={null} />);
|
|
97
|
+
olMap.dispatchEvent(evt);
|
|
98
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('uses onFeaturesHover function', () => {
|
|
103
|
+
const spy = jest.fn();
|
|
104
|
+
const spy2 = jest.fn();
|
|
105
|
+
const evt = new MapEvent('pointermove', olMap);
|
|
106
|
+
|
|
107
|
+
// Test componentDidMount
|
|
108
|
+
const { rerender } = render(
|
|
109
|
+
<BasicMap map={olMap} onFeaturesHover={spy} />,
|
|
110
|
+
{
|
|
111
|
+
lifecycleExperimental: true,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
olMap.dispatchEvent(evt);
|
|
115
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
116
|
+
expect(spy).toHaveBeenCalledWith([], evt);
|
|
117
|
+
|
|
118
|
+
// Test componentDidUpdate
|
|
119
|
+
rerender(<BasicMap map={olMap} onFeaturesHover={spy2} />);
|
|
120
|
+
olMap.dispatchEvent(evt);
|
|
121
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
122
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
123
|
+
expect(spy2).toHaveBeenCalledWith([], evt);
|
|
124
|
+
|
|
125
|
+
// Test componentDidUpdate
|
|
126
|
+
rerender(<BasicMap map={olMap} onFeaturesHover={null} />);
|
|
127
|
+
olMap.dispatchEvent(evt);
|
|
128
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
129
|
+
expect(spy2).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('should be rendered with a default map', () => {
|
|
133
|
+
const { container } = render(<BasicMap />);
|
|
134
|
+
expect(!!container.querySelector('.ol-viewport')).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('should be rendered with layers and an extent', () => {
|
|
138
|
+
render(
|
|
139
|
+
<BasicMap
|
|
140
|
+
map={olMap}
|
|
141
|
+
layers={olLayers}
|
|
142
|
+
extent={extent}
|
|
143
|
+
viewOptions={{
|
|
144
|
+
minZoom: 16,
|
|
145
|
+
maxZoom: 22,
|
|
146
|
+
projection: 'EPSG:21781',
|
|
147
|
+
}}
|
|
148
|
+
/>,
|
|
149
|
+
);
|
|
150
|
+
expect(olMap.getLayers().getLength()).toBe(1);
|
|
151
|
+
expect(olMap.getView().calculateExtent()).toEqual([
|
|
152
|
+
380.70084231351245, 380.70084231351245, 619.2991576864875,
|
|
153
|
+
619.2991576864875,
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('center shoud be set', () => {
|
|
158
|
+
const { rerender } = render(<BasicMap map={olMap} />);
|
|
159
|
+
const setCenter = jest.spyOn(olMap.getView(), 'setCenter');
|
|
160
|
+
rerender(<BasicMap map={olMap} center={[0, 0]} />);
|
|
161
|
+
expect(setCenter).toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('zoom shoud be set', () => {
|
|
165
|
+
const { rerender } = render(<BasicMap map={olMap} zoom={5} />);
|
|
166
|
+
expect(olMap.getView().getZoom()).toBe(5);
|
|
167
|
+
rerender(<BasicMap map={olMap} zoom={2} />);
|
|
168
|
+
expect(olMap.getView().getZoom()).toBe(2);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('resolution shoud be set', () => {
|
|
172
|
+
const { rerender } = render(<BasicMap map={olMap} resolution={100} />);
|
|
173
|
+
expect(olMap.getView().getResolution()).toBe(100);
|
|
174
|
+
rerender(<BasicMap map={olMap} resolution={5} />);
|
|
175
|
+
expect(olMap.getView().getResolution()).toBe(5);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('animation shoud be set', () => {
|
|
179
|
+
const obj = {
|
|
180
|
+
zoom: 4,
|
|
181
|
+
};
|
|
182
|
+
const { rerender } = render(<BasicMap map={olMap} />);
|
|
183
|
+
const spy = jest.spyOn(olMap.getView(), 'animate');
|
|
184
|
+
rerender(<BasicMap map={olMap} animationOptions={obj} />);
|
|
185
|
+
expect(spy).toHaveBeenCalledWith(obj);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('layers shoud be updated', () => {
|
|
189
|
+
const addLayer = jest.spyOn(olMap, 'addLayer');
|
|
190
|
+
const { rerender } = render(<BasicMap map={olMap} />);
|
|
191
|
+
const layer = new Layer({ name: 'test', olLayer: new OLLayer() });
|
|
192
|
+
rerender(<BasicMap map={olMap} layers={[layer]} />);
|
|
193
|
+
expect(addLayer).toHaveBeenCalled();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('should be fitted if extent is updated', () => {
|
|
197
|
+
const fitExtent = jest.spyOn(OLView.prototype, 'fit');
|
|
198
|
+
const { rerender } = render(<BasicMap map={olMap} />);
|
|
199
|
+
rerender(<BasicMap map={olMap} extent={[1, 2, 3, 4]} />);
|
|
200
|
+
expect(fitExtent).toHaveBeenCalled();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('should be zoomed if zoom is updated', () => {
|
|
204
|
+
const setZoom = jest.spyOn(OLView.prototype, 'setZoom');
|
|
205
|
+
const { rerender } = render(<BasicMap map={olMap} />);
|
|
206
|
+
rerender(<BasicMap map={olMap} zoom={15} />);
|
|
207
|
+
expect(setZoom).toHaveBeenCalledWith(15);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('should be observed by ResizeHandler', () => {
|
|
211
|
+
const spy = jest.spyOn(ResizeObserver.prototype, 'observe');
|
|
212
|
+
render(<BasicMap map={olMap} />);
|
|
213
|
+
expect(spy).toHaveBeenCalledWith(olMap.getTargetElement());
|
|
214
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('size is updated when div is resized', () => {
|
|
218
|
+
const spy = jest.spyOn(olMap, 'updateSize');
|
|
219
|
+
render(<BasicMap map={olMap} />);
|
|
220
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
221
|
+
// The mock class set the onResize property, we just have to run it to
|
|
222
|
+
// simulate a resize
|
|
223
|
+
ResizeObserver.onResize([
|
|
224
|
+
{
|
|
225
|
+
target: olMap.getTargetElement(),
|
|
226
|
+
contentRect: {
|
|
227
|
+
width: 20,
|
|
228
|
+
height: 20,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
expect(spy).toHaveBeenCalledTimes(3);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('#setLayers()', () => {
|
|
236
|
+
test('init all layers and terminate al previous layer.', () => {
|
|
237
|
+
const layer0 = new Layer({ key: 'test1' });
|
|
238
|
+
const spyInit0 = jest.spyOn(layer0, 'attachToMap');
|
|
239
|
+
const spyTerminate0 = jest.spyOn(layer0, 'detachFromMap');
|
|
240
|
+
const layer1 = new Layer({ key: 'test1' });
|
|
241
|
+
const spyInit1 = jest.spyOn(layer1, 'attachToMap');
|
|
242
|
+
const spyTerminate1 = jest.spyOn(layer1, 'detachFromMap');
|
|
243
|
+
const layer2 = new Layer({ key: 'test2' });
|
|
244
|
+
const spyInit2 = jest.spyOn(layer2, 'attachToMap');
|
|
245
|
+
const spyTerminate2 = jest.spyOn(layer2, 'detachFromMap');
|
|
246
|
+
const layer3 = new Layer({ key: 'test3' });
|
|
247
|
+
const spyInit3 = jest.spyOn(layer3, 'attachToMap');
|
|
248
|
+
const spyTerminate3 = jest.spyOn(layer3, 'detachFromMap');
|
|
249
|
+
const layer4 = new Layer({ key: 'test4' });
|
|
250
|
+
const spyInit4 = jest.spyOn(layer4, 'attachToMap');
|
|
251
|
+
const spyTerminate4 = jest.spyOn(layer4, 'detachFromMap');
|
|
252
|
+
const startLayers = [layer1, layer3];
|
|
253
|
+
const { rerender } = render(
|
|
254
|
+
<BasicMap map={olMap} layers={startLayers} />,
|
|
255
|
+
);
|
|
256
|
+
expect(spyInit0).toHaveBeenCalledTimes(0);
|
|
257
|
+
expect(spyInit1).toHaveBeenCalledTimes(1);
|
|
258
|
+
expect(spyInit2).toHaveBeenCalledTimes(0);
|
|
259
|
+
expect(spyInit3).toHaveBeenCalledTimes(1);
|
|
260
|
+
expect(spyInit4).toHaveBeenCalledTimes(0);
|
|
261
|
+
expect(spyTerminate0).toHaveBeenCalledTimes(0);
|
|
262
|
+
expect(spyTerminate1).toHaveBeenCalledTimes(1);
|
|
263
|
+
expect(spyTerminate2).toHaveBeenCalledTimes(0);
|
|
264
|
+
expect(spyTerminate3).toHaveBeenCalledTimes(1);
|
|
265
|
+
expect(spyTerminate4).toHaveBeenCalledTimes(0);
|
|
266
|
+
|
|
267
|
+
const layers = [layer0, layer2, layer3, layer4];
|
|
268
|
+
rerender(<BasicMap map={olMap} layers={layers} />);
|
|
269
|
+
expect(spyInit0).toHaveBeenCalledTimes(1);
|
|
270
|
+
expect(spyInit1).toHaveBeenCalledTimes(1);
|
|
271
|
+
expect(spyInit2).toHaveBeenCalledTimes(1);
|
|
272
|
+
expect(spyInit3).toHaveBeenCalledTimes(2);
|
|
273
|
+
expect(spyInit4).toHaveBeenCalledTimes(1);
|
|
274
|
+
expect(spyTerminate0).toHaveBeenCalledTimes(1);
|
|
275
|
+
expect(spyTerminate1).toHaveBeenCalledTimes(2);
|
|
276
|
+
expect(spyTerminate2).toHaveBeenCalledTimes(1);
|
|
277
|
+
expect(spyTerminate3).toHaveBeenCalledTimes(3);
|
|
278
|
+
expect(spyTerminate4).toHaveBeenCalledTimes(1);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
The following example demonstrates the use of BasicMap.
|
|
3
|
+
|
|
4
|
+
```jsx
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { MapboxLayer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
import Tile from 'ol/layer/Tile';
|
|
8
|
+
import OSM from 'ol/source/OSM';
|
|
9
|
+
import BasicMap from 'react-spatial/components/BasicMap';
|
|
10
|
+
|
|
11
|
+
const layers = [
|
|
12
|
+
new MapboxLayer({
|
|
13
|
+
url: `https://maps.geops.io/styles/travic_v2/style.json?key=${apiKey}`,
|
|
14
|
+
})
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
<BasicMap layers={layers} tabIndex={0} />;
|
|
18
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './BasicMap';
|