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,417 @@
|
|
|
1
|
+
import 'jest-canvas-mock';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import renderer from 'react-test-renderer';
|
|
4
|
+
import { configure, mount, shallow } from 'enzyme';
|
|
5
|
+
import Adapter from '@cfaester/enzyme-adapter-react-18';
|
|
6
|
+
import { Layer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
import GPX from 'ol/format/GPX';
|
|
8
|
+
import VectorSource from 'ol/source/Vector';
|
|
9
|
+
import Style from 'ol/style/Style';
|
|
10
|
+
import Icon from 'ol/style/Icon';
|
|
11
|
+
import Text from 'ol/style/Text';
|
|
12
|
+
import Fill from 'ol/style/Fill';
|
|
13
|
+
import Stroke from 'ol/style/Stroke';
|
|
14
|
+
import Circle from 'ol/geom/Circle';
|
|
15
|
+
import Point from 'ol/geom/Point';
|
|
16
|
+
import LineString from 'ol/geom/LineString';
|
|
17
|
+
import Feature from 'ol/Feature';
|
|
18
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
19
|
+
|
|
20
|
+
import FeatureExportButton from '.';
|
|
21
|
+
|
|
22
|
+
configure({ adapter: new Adapter() });
|
|
23
|
+
|
|
24
|
+
const layer = new Layer({
|
|
25
|
+
name: 'Sample layer',
|
|
26
|
+
olLayer: new VectorLayer({
|
|
27
|
+
source: new VectorSource({
|
|
28
|
+
features: [
|
|
29
|
+
new Feature({
|
|
30
|
+
geometry: new Point([819103.972418, 6120013.078324]),
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('FeatureExportButton', () => {
|
|
38
|
+
describe('should match snapshot', () => {
|
|
39
|
+
test('with default attributes.', () => {
|
|
40
|
+
const component = renderer.create(<FeatureExportButton layer={layer} />);
|
|
41
|
+
const tree = component.toJSON();
|
|
42
|
+
expect(tree).toMatchSnapshot();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should match snapshot with cutom attributes.', () => {
|
|
46
|
+
const component = renderer.create(
|
|
47
|
+
<FeatureExportButton
|
|
48
|
+
layer={layer}
|
|
49
|
+
className="foo"
|
|
50
|
+
title="bar"
|
|
51
|
+
// eslint-disable-next-line jsx-a11y/tabindex-no-positive
|
|
52
|
+
tabIndex={2}
|
|
53
|
+
/>,
|
|
54
|
+
);
|
|
55
|
+
const tree = component.toJSON();
|
|
56
|
+
expect(tree).toMatchSnapshot();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should match snapshot with children passed.', () => {
|
|
60
|
+
const component = renderer.create(
|
|
61
|
+
<FeatureExportButton layer={layer}>
|
|
62
|
+
<div>Foo</div>
|
|
63
|
+
</FeatureExportButton>,
|
|
64
|
+
);
|
|
65
|
+
const tree = component.toJSON();
|
|
66
|
+
expect(tree).toMatchSnapshot();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('triggers onClick', () => {
|
|
71
|
+
// Use library 'jest-environment-jsdom-fourteen'
|
|
72
|
+
// to allow jest test of format.writeFeatures(feats).
|
|
73
|
+
const renderLayer = (featNumbers) => {
|
|
74
|
+
const featsArray = [];
|
|
75
|
+
for (let i = 0; i < featNumbers; i += 1) {
|
|
76
|
+
featsArray.push(
|
|
77
|
+
new Feature({
|
|
78
|
+
geometry: new Point([819103.972418, 6120013.078324]),
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return new Layer({
|
|
84
|
+
name: 'ExportLayer',
|
|
85
|
+
olLayer: new VectorLayer({
|
|
86
|
+
source: new VectorSource({
|
|
87
|
+
features: featsArray,
|
|
88
|
+
}),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const iconLayer = renderLayer(1);
|
|
94
|
+
|
|
95
|
+
const textStyle = new Style({
|
|
96
|
+
text: new Text({
|
|
97
|
+
text: 'text name',
|
|
98
|
+
font: 'normal 16px Helvetica',
|
|
99
|
+
stroke: new Stroke({
|
|
100
|
+
color: [255, 255, 255, 1],
|
|
101
|
+
width: 3,
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should be trigger click function.', () => {
|
|
107
|
+
const wrapper = shallow(<FeatureExportButton layer={iconLayer} />);
|
|
108
|
+
const spy = jest.spyOn(FeatureExportButton, 'exportFeatures');
|
|
109
|
+
wrapper.find('.rs-feature-export-button').simulate('click');
|
|
110
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('should use attributes for parsing', () => {
|
|
114
|
+
const wrapper = mount(
|
|
115
|
+
<FeatureExportButton
|
|
116
|
+
format={GPX}
|
|
117
|
+
projection="EPSG:4326"
|
|
118
|
+
layer={iconLayer}
|
|
119
|
+
/>,
|
|
120
|
+
);
|
|
121
|
+
const spy = jest.spyOn(FeatureExportButton, 'exportFeatures');
|
|
122
|
+
wrapper.find('.rs-feature-export-button').simulate('click');
|
|
123
|
+
expect(spy).toHaveBeenCalledWith(iconLayer, 'EPSG:4326', GPX);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('#createFeatureString()', () => {
|
|
127
|
+
describe('using KMLFormat', () => {
|
|
128
|
+
test('should export kml by default.', () => {
|
|
129
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
130
|
+
iconLayer,
|
|
131
|
+
FeatureExportButton.defaultProps.projection,
|
|
132
|
+
FeatureExportButton.defaultProps.format,
|
|
133
|
+
);
|
|
134
|
+
expect(exportString).toMatchSnapshot();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const iconStyle = new Style({
|
|
138
|
+
image: new Icon({
|
|
139
|
+
anchor: [0.5, 46],
|
|
140
|
+
anchorXUnits: 'fraction',
|
|
141
|
+
anchorYUnits: 'pixels',
|
|
142
|
+
src: 'https://openlayers.org/en/latest/examples/data/icon.png',
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
iconLayer.olLayer.getSource().forEachFeature((f) => {
|
|
147
|
+
f.setStyle(iconStyle);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('should export icon style in kml.', () => {
|
|
151
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
152
|
+
iconLayer,
|
|
153
|
+
FeatureExportButton.defaultProps.projection,
|
|
154
|
+
FeatureExportButton.defaultProps.format,
|
|
155
|
+
);
|
|
156
|
+
const expectedString =
|
|
157
|
+
'<Style><IconStyle><scale>2</scale><Icon><href>' +
|
|
158
|
+
'https://openlayers.org/en/latest/examples/data/icon.png' +
|
|
159
|
+
'</href></Icon></IconStyle></Style>';
|
|
160
|
+
expect(exportString.match(/<Style>(.*?)<\/Style>/g)[0]).toBe(
|
|
161
|
+
expectedString,
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('should export with layer name.', () => {
|
|
166
|
+
const namedlayer = renderLayer(1);
|
|
167
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
168
|
+
namedlayer,
|
|
169
|
+
FeatureExportButton.defaultProps.projection,
|
|
170
|
+
FeatureExportButton.defaultProps.format,
|
|
171
|
+
);
|
|
172
|
+
const expectedname = '<name>ExportLayer</name>';
|
|
173
|
+
expect(exportString.match(/<name>(.*?)<\/name>/g)[0]).toBe(
|
|
174
|
+
expectedname,
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('should export without layer name.', () => {
|
|
179
|
+
const unnamedlayer = renderLayer(1);
|
|
180
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
181
|
+
unnamedlayer,
|
|
182
|
+
FeatureExportButton.defaultProps.projection,
|
|
183
|
+
FeatureExportButton.defaultProps.format,
|
|
184
|
+
);
|
|
185
|
+
expect(
|
|
186
|
+
/<document><name>ExportLayer<\/name>/g.test(exportString),
|
|
187
|
+
).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('should export text style in kml.', () => {
|
|
191
|
+
const textlayer = renderLayer(2);
|
|
192
|
+
|
|
193
|
+
textlayer.olLayer.getSource().forEachFeature((f) => {
|
|
194
|
+
f.setStyle(textStyle);
|
|
195
|
+
});
|
|
196
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
197
|
+
textlayer,
|
|
198
|
+
FeatureExportButton.defaultProps.projection,
|
|
199
|
+
FeatureExportButton.defaultProps.format,
|
|
200
|
+
);
|
|
201
|
+
const expectedStyle =
|
|
202
|
+
'<Style><IconStyle><scale>0</scale></IconStyle>' +
|
|
203
|
+
'<LabelStyle><color>ff333333</color></LabelStyle></Style>';
|
|
204
|
+
expect(exportString.match(/<Style>(.*?)<\/Style>/g)[0]).toBe(
|
|
205
|
+
expectedStyle,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('should only export none-empty text style in kml.', () => {
|
|
210
|
+
const textlayer = renderLayer(2);
|
|
211
|
+
|
|
212
|
+
textlayer.olLayer.getSource().forEachFeature((f) => {
|
|
213
|
+
f.setStyle(textStyle);
|
|
214
|
+
});
|
|
215
|
+
const exportString1 = FeatureExportButton.createFeatureString(
|
|
216
|
+
textlayer,
|
|
217
|
+
FeatureExportButton.defaultProps.projection,
|
|
218
|
+
FeatureExportButton.defaultProps.format,
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(
|
|
222
|
+
exportString1.match(/<Placemark>(.*?)<\/Placemark>/g).length,
|
|
223
|
+
).toBe(2);
|
|
224
|
+
|
|
225
|
+
const newStyle = new Style({
|
|
226
|
+
text: new Text({
|
|
227
|
+
text: '',
|
|
228
|
+
font: 'normal 16px Helvetica',
|
|
229
|
+
stroke: new Stroke({
|
|
230
|
+
color: [255, 255, 255, 1],
|
|
231
|
+
width: 3,
|
|
232
|
+
}),
|
|
233
|
+
}),
|
|
234
|
+
});
|
|
235
|
+
// Set empty string as name for first feature
|
|
236
|
+
textlayer.olLayer.getSource().getFeatures()[0].setStyle(newStyle);
|
|
237
|
+
|
|
238
|
+
const exportString2 = FeatureExportButton.createFeatureString(
|
|
239
|
+
textlayer,
|
|
240
|
+
FeatureExportButton.defaultProps.projection,
|
|
241
|
+
FeatureExportButton.defaultProps.format,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
expect(
|
|
245
|
+
exportString2.match(/<Placemark>(.*?)<\/Placemark>/g).length,
|
|
246
|
+
).toBe(1);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("should not export 'Cirle geom' (kml unsupported).", () => {
|
|
250
|
+
const circleLayer = new Layer({
|
|
251
|
+
name: 'ExportLayer',
|
|
252
|
+
olLayer: new VectorLayer({
|
|
253
|
+
source: new VectorSource({
|
|
254
|
+
features: [
|
|
255
|
+
new Feature({
|
|
256
|
+
geometry: new Circle({
|
|
257
|
+
center: [843119.531243, 6111943.000197],
|
|
258
|
+
radius: 1000,
|
|
259
|
+
}),
|
|
260
|
+
}),
|
|
261
|
+
],
|
|
262
|
+
}),
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const circleStyle = new Style({
|
|
267
|
+
stroke: new Stroke({
|
|
268
|
+
color: 'red',
|
|
269
|
+
width: 3,
|
|
270
|
+
}),
|
|
271
|
+
fill: new Fill({
|
|
272
|
+
color: 'rgba(255, 0, 0, 0.1)',
|
|
273
|
+
}),
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
circleLayer.olLayer.getSource().forEachFeature((f) => {
|
|
277
|
+
f.setStyle(circleStyle);
|
|
278
|
+
});
|
|
279
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
280
|
+
circleLayer,
|
|
281
|
+
FeatureExportButton.defaultProps.projection,
|
|
282
|
+
FeatureExportButton.defaultProps.format,
|
|
283
|
+
);
|
|
284
|
+
expect(exportString).toBe(undefined);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('should export extended data.', () => {
|
|
288
|
+
const extendedLayer = renderLayer(1);
|
|
289
|
+
|
|
290
|
+
const style = new Style({
|
|
291
|
+
stroke: new Stroke({
|
|
292
|
+
color: [0, 0, 0, 1],
|
|
293
|
+
lineDash: [40, 40],
|
|
294
|
+
}),
|
|
295
|
+
text: new Text({
|
|
296
|
+
text: 'text name',
|
|
297
|
+
font: 'normal 18px Arial',
|
|
298
|
+
rotation: 0.5,
|
|
299
|
+
backgroundFill: new Fill({
|
|
300
|
+
color: 'rgba(255,255,255,0.01)',
|
|
301
|
+
}),
|
|
302
|
+
}),
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
extendedLayer.olLayer.getSource().forEachFeature((f) => {
|
|
306
|
+
f.setStyle(style);
|
|
307
|
+
});
|
|
308
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
309
|
+
extendedLayer,
|
|
310
|
+
FeatureExportButton.defaultProps.projection,
|
|
311
|
+
FeatureExportButton.defaultProps.format,
|
|
312
|
+
);
|
|
313
|
+
const expectedStyle =
|
|
314
|
+
'<ExtendedData><Data name="lineDash"><value>40,40</value></Data>' +
|
|
315
|
+
'<Data name="textBackgroundFillColor"><value>rgba(255,255,255,0.01)</value></Data>' +
|
|
316
|
+
'<Data name="textFont"><value>normal 18px Arial</value></Data>' +
|
|
317
|
+
'<Data name="textRotation"><value>0.5</value></Data></ExtendedData>';
|
|
318
|
+
expect(
|
|
319
|
+
exportString.match(/<ExtendedData>(.*?)<\/ExtendedData>/g)[0],
|
|
320
|
+
).toBe(expectedStyle);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test('should not export others extended data than style.', () => {
|
|
324
|
+
const extendedLayer = renderLayer(1);
|
|
325
|
+
|
|
326
|
+
const style = new Style({
|
|
327
|
+
stroke: new Stroke({
|
|
328
|
+
color: [0, 0, 0, 1],
|
|
329
|
+
lineDash: [40, 40],
|
|
330
|
+
}),
|
|
331
|
+
text: new Text({
|
|
332
|
+
text: 'text name',
|
|
333
|
+
font: 'normal 18px Arial',
|
|
334
|
+
rotation: 0.5,
|
|
335
|
+
backgroundFill: new Fill({
|
|
336
|
+
color: 'rgba(255,255,255,0.01)',
|
|
337
|
+
}),
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
extendedLayer.olLayer.getSource().forEachFeature((f) => {
|
|
342
|
+
f.setStyle(style);
|
|
343
|
+
f.set('foo', 'bar');
|
|
344
|
+
});
|
|
345
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
346
|
+
extendedLayer,
|
|
347
|
+
FeatureExportButton.defaultProps.projection,
|
|
348
|
+
FeatureExportButton.defaultProps.format,
|
|
349
|
+
);
|
|
350
|
+
const expectedStyle =
|
|
351
|
+
'<ExtendedData><Data name="lineDash"><value>40,40</value></Data>' +
|
|
352
|
+
'<Data name="textBackgroundFillColor"><value>rgba(255,255,255,0.01)</value></Data>' +
|
|
353
|
+
'<Data name="textFont"><value>normal 18px Arial</value></Data>' +
|
|
354
|
+
'<Data name="textRotation"><value>0.5</value></Data></ExtendedData>';
|
|
355
|
+
expect(
|
|
356
|
+
exportString.match(/<ExtendedData>(.*?)<\/ExtendedData>/g)[0],
|
|
357
|
+
).toBe(expectedStyle);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('should export lineStartIcon and lineEndIcon style.', () => {
|
|
361
|
+
const extendedLayer = renderLayer(1);
|
|
362
|
+
const line = new Feature({
|
|
363
|
+
geometry: new LineString([
|
|
364
|
+
[0, 1],
|
|
365
|
+
[2, 3],
|
|
366
|
+
[4, 5],
|
|
367
|
+
]),
|
|
368
|
+
});
|
|
369
|
+
extendedLayer.olLayer.getSource().addFeatures([line]);
|
|
370
|
+
|
|
371
|
+
const style = [
|
|
372
|
+
new Style({
|
|
373
|
+
stroke: new Stroke({
|
|
374
|
+
color: [0, 0, 0, 1],
|
|
375
|
+
lineDash: [40, 40],
|
|
376
|
+
}),
|
|
377
|
+
}),
|
|
378
|
+
new Style({
|
|
379
|
+
geometry: () => {
|
|
380
|
+
return new Point([4, 5]);
|
|
381
|
+
},
|
|
382
|
+
image: new Icon({
|
|
383
|
+
src: 'fooarrowend.png',
|
|
384
|
+
}),
|
|
385
|
+
}),
|
|
386
|
+
new Style({
|
|
387
|
+
geometry: () => {
|
|
388
|
+
return new Point([0, 1]);
|
|
389
|
+
},
|
|
390
|
+
image: new Icon({
|
|
391
|
+
src: 'fooarrowstart.png',
|
|
392
|
+
}),
|
|
393
|
+
}),
|
|
394
|
+
];
|
|
395
|
+
line.setStyle(style);
|
|
396
|
+
|
|
397
|
+
const exportString = FeatureExportButton.createFeatureString(
|
|
398
|
+
extendedLayer,
|
|
399
|
+
FeatureExportButton.defaultProps.projection,
|
|
400
|
+
FeatureExportButton.defaultProps.format,
|
|
401
|
+
);
|
|
402
|
+
const expectedStyle =
|
|
403
|
+
'<ExtendedData><Data name="lineDash"><value>40,40</value></Data>' +
|
|
404
|
+
'<Data name="lineEndIcon">' +
|
|
405
|
+
'<value>{"url":"fooarrowend.png","scale":1,"size":null}</value></Data>' +
|
|
406
|
+
'<Data name="lineStartIcon">' +
|
|
407
|
+
'<value>{"url":"fooarrowstart.png","scale":1,"size":null}</value></Data>' +
|
|
408
|
+
'</ExtendedData>';
|
|
409
|
+
|
|
410
|
+
expect(
|
|
411
|
+
exportString.match(/<ExtendedData>(.*?)<\/ExtendedData>/g)[0],
|
|
412
|
+
).toBe(expectedStyle);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
The following example demonstrates the use of FeatureExportButton.
|
|
3
|
+
|
|
4
|
+
```jsx
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Layer, MapboxLayer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
8
|
+
import VectorSource from 'ol/source/Vector';
|
|
9
|
+
import Feature from 'ol/Feature';
|
|
10
|
+
import Point from 'ol/geom/Point';
|
|
11
|
+
import { Icon, Style } from 'ol/style';
|
|
12
|
+
import GPX from 'ol/format/GPX';
|
|
13
|
+
import { geopsTheme, Header, Footer } from '@geops/geops-ui';
|
|
14
|
+
import { ThemeProvider } from '@material-ui/core/styles';
|
|
15
|
+
import Button from '@material-ui/core/Button';
|
|
16
|
+
import BasicMap from 'react-spatial/components/BasicMap';
|
|
17
|
+
import FeatureExportButton from 'react-spatial/components/FeatureExportButton';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const vectorLayer = new Layer({
|
|
21
|
+
olLayer: new VectorLayer({
|
|
22
|
+
style: new Style({
|
|
23
|
+
image: new Icon({
|
|
24
|
+
anchor: [0.5, 46],
|
|
25
|
+
anchorXUnits: 'fraction',
|
|
26
|
+
anchorYUnits: 'pixels',
|
|
27
|
+
src: 'https://openlayers.org/en/latest/examples/data/icon.png',
|
|
28
|
+
imgSize: [32, 48]
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
source: new VectorSource({
|
|
32
|
+
features: [
|
|
33
|
+
new Feature({
|
|
34
|
+
geometry: new Point([819103.972418, 6120013.078324]),
|
|
35
|
+
}),
|
|
36
|
+
new Feature({
|
|
37
|
+
geometry: new Point([873838.856313, 6106009.575876]),
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const layers = [
|
|
45
|
+
new MapboxLayer({
|
|
46
|
+
url: `https://maps.geops.io/styles/travic_v2/style.json?key=${apiKey}`,
|
|
47
|
+
}),
|
|
48
|
+
vectorLayer,
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
<ThemeProvider theme={geopsTheme}>
|
|
52
|
+
<div className="rs-feature-export-example">
|
|
53
|
+
<BasicMap
|
|
54
|
+
center={[843119.531243, 6111943.000197]}
|
|
55
|
+
zoom={9}
|
|
56
|
+
layers={layers}
|
|
57
|
+
tabIndex={0}
|
|
58
|
+
/>
|
|
59
|
+
<div className="rs-feature-export-example-btns">
|
|
60
|
+
<FeatureExportButton layer={vectorLayer}>
|
|
61
|
+
<Button>
|
|
62
|
+
Export as KML
|
|
63
|
+
</Button>
|
|
64
|
+
</FeatureExportButton>
|
|
65
|
+
<FeatureExportButton
|
|
66
|
+
format={GPX}
|
|
67
|
+
layer={vectorLayer}
|
|
68
|
+
>
|
|
69
|
+
<Button>
|
|
70
|
+
Export as GPX
|
|
71
|
+
</Button>
|
|
72
|
+
</FeatureExportButton>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</ThemeProvider>
|
|
76
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`FeatureExportButton should match snapshot should match snapshot with children passed. 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="rs-feature-export-button"
|
|
6
|
+
onClick={[Function]}
|
|
7
|
+
onKeyPress={[Function]}
|
|
8
|
+
role="button"
|
|
9
|
+
tabIndex={0}
|
|
10
|
+
>
|
|
11
|
+
<div>
|
|
12
|
+
Foo
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`FeatureExportButton should match snapshot should match snapshot with cutom attributes. 1`] = `
|
|
18
|
+
<div
|
|
19
|
+
className="foo"
|
|
20
|
+
onClick={[Function]}
|
|
21
|
+
onKeyPress={[Function]}
|
|
22
|
+
role="button"
|
|
23
|
+
tabIndex={2}
|
|
24
|
+
title="bar"
|
|
25
|
+
/>
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
exports[`FeatureExportButton should match snapshot with default attributes. 1`] = `
|
|
29
|
+
<div
|
|
30
|
+
className="rs-feature-export-button"
|
|
31
|
+
onClick={[Function]}
|
|
32
|
+
onKeyPress={[Function]}
|
|
33
|
+
role="button"
|
|
34
|
+
tabIndex={0}
|
|
35
|
+
/>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`FeatureExportButton triggers onClick #createFeatureString() using KMLFormat should export kml by default. 1`] = `
|
|
39
|
+
<kml xmlns="http://www.opengis.net/kml/2.2"
|
|
40
|
+
xmlns:gx="http://www.google.com/kml/ext/2.2"
|
|
41
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
42
|
+
xsi:schemalocation="http://www.opengis.net/kml/2.2 https://developers.google.com/kml/schema/kml22gx.xsd"
|
|
43
|
+
>
|
|
44
|
+
<Document>
|
|
45
|
+
<name>
|
|
46
|
+
ExportLayer
|
|
47
|
+
</name>
|
|
48
|
+
<Placemark>
|
|
49
|
+
<Style>
|
|
50
|
+
<IconStyle>
|
|
51
|
+
<scale>2
|
|
52
|
+
</scale>
|
|
53
|
+
<Icon>
|
|
54
|
+
<href>https://openlayers.org/en/latest/examples/data/icon.png
|
|
55
|
+
</href>
|
|
56
|
+
</Icon>
|
|
57
|
+
</IconStyle>
|
|
58
|
+
</Style>
|
|
59
|
+
<Point>
|
|
60
|
+
<coordinates>
|
|
61
|
+
7.358136177061042,48.07903229472336
|
|
62
|
+
</coordinates>
|
|
63
|
+
</Point>
|
|
64
|
+
</Placemark>
|
|
65
|
+
</Document>
|
|
66
|
+
</kml>
|
|
67
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './FeatureExportButton';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import OLMap from 'ol/Map';
|
|
4
|
+
|
|
5
|
+
const propTypes = {
|
|
6
|
+
/**
|
|
7
|
+
* An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
8
|
+
*/
|
|
9
|
+
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The extent to be zoomed.
|
|
13
|
+
*/
|
|
14
|
+
extent: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CSS class for the fitExtent button.
|
|
18
|
+
*/
|
|
19
|
+
className: PropTypes.string,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Button content.
|
|
23
|
+
*/
|
|
24
|
+
children: PropTypes.node.isRequired,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const defaultProps = {
|
|
28
|
+
className: 'rs-fit-extent',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The FitExtent component creates a button that updates the current extent of
|
|
33
|
+
* an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
34
|
+
*/
|
|
35
|
+
function FitExtent({ map, extent, className, children, ...other }) {
|
|
36
|
+
const fit = (evt) => {
|
|
37
|
+
if (evt.which && evt.which !== 13) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
map.getView().cancelAnimations();
|
|
41
|
+
map.getView().fit(extent, map.getSize());
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
className={className}
|
|
47
|
+
role="button"
|
|
48
|
+
tabIndex="0"
|
|
49
|
+
onClick={fit}
|
|
50
|
+
onKeyPress={fit}
|
|
51
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
52
|
+
{...other}
|
|
53
|
+
>
|
|
54
|
+
{children}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
FitExtent.propTypes = propTypes;
|
|
60
|
+
FitExtent.defaultProps = defaultProps;
|
|
61
|
+
|
|
62
|
+
export default FitExtent;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
import { configure, shallow } from 'enzyme';
|
|
4
|
+
import Adapter from '@cfaester/enzyme-adapter-react-18';
|
|
5
|
+
import OLView from 'ol/View';
|
|
6
|
+
import OLMap from 'ol/Map';
|
|
7
|
+
import FitExtent from './FitExtent';
|
|
8
|
+
|
|
9
|
+
configure({ adapter: new Adapter() });
|
|
10
|
+
|
|
11
|
+
const extent = [1, 2, 3, 4];
|
|
12
|
+
|
|
13
|
+
test('Button should match snapshot.', () => {
|
|
14
|
+
const map = new OLMap({});
|
|
15
|
+
const component = renderer.create(
|
|
16
|
+
<FitExtent map={map} extent={extent}>
|
|
17
|
+
FitExtent
|
|
18
|
+
</FitExtent>,
|
|
19
|
+
);
|
|
20
|
+
const tree = component.toJSON();
|
|
21
|
+
expect(tree).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Should fit the extent.', () => {
|
|
25
|
+
const map = new OLMap({ view: new OLView({ zoom: 7, center: [0, 0] }) });
|
|
26
|
+
const wrapper = shallow(
|
|
27
|
+
<FitExtent map={map} extent={extent} className="fit-ext">
|
|
28
|
+
FitExtent
|
|
29
|
+
</FitExtent>,
|
|
30
|
+
);
|
|
31
|
+
wrapper.find('.fit-ext').first().simulate('click', {});
|
|
32
|
+
const calculatedExtent = map.getView().calculateExtent(map.getSize());
|
|
33
|
+
|
|
34
|
+
expect(calculatedExtent).toStrictEqual([1, 2, 3, 4]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('Should fit the extent on return.', () => {
|
|
38
|
+
const map = new OLMap({ view: new OLView({ zoom: 7, center: [0, 0] }) });
|
|
39
|
+
const wrapper = shallow(
|
|
40
|
+
<FitExtent map={map} extent={extent} className="fit-ext">
|
|
41
|
+
FitExtent
|
|
42
|
+
</FitExtent>,
|
|
43
|
+
);
|
|
44
|
+
wrapper.find('.fit-ext').first().simulate('click', { which: 13 });
|
|
45
|
+
const calculatedExtent = map.getView().calculateExtent(map.getSize());
|
|
46
|
+
|
|
47
|
+
expect(calculatedExtent).toStrictEqual([1, 2, 3, 4]);
|
|
48
|
+
});
|