@mapcomponents/react-maplibre 0.1.26 → 0.1.30
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/CHANGELOG.md +31 -0
- package/coverage/clover.xml +456 -479
- package/coverage/coverage-final.json +21 -20
- package/coverage/lcov-report/index.html +94 -79
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +22 -22
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +11 -11
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +11 -11
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.js.html +1 -1
- package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +4 -4
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +212 -26
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +19 -19
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +129 -165
- package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +8 -8
- package/coverage/lcov-report/src/components/MlGPXViewer/index.html +20 -20
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +45 -297
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +19 -19
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +2 -2
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +2 -2
- package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +4 -4
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +3 -3
- package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
- package/coverage/lcov-report/src/components/MlMarker/MlMarker.js.html +1 -1
- package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.js.html +38 -104
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +19 -19
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +40 -139
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +15 -15
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +32 -155
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +19 -19
- package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +39 -198
- package/coverage/lcov-report/src/components/MlScaleReference/index.html +9 -9
- package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +4 -4
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
- package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.js.html +580 -0
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +116 -0
- package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
- package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
- package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.js.html +3 -3
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.js.html +8 -11
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.js.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
- package/coverage/lcov-report/src/hooks/index.html +6 -6
- package/coverage/lcov-report/src/hooks/useMap.js.html +38 -26
- package/coverage/lcov-report/src/hooks/useMapState.js.html +47 -38
- package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
- package/coverage/lcov-report/src/i18n.js.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/translations/english.js.html +1 -1
- package/coverage/lcov-report/src/translations/german.js.html +1 -1
- package/coverage/lcov-report/src/translations/index.html +1 -1
- package/coverage/lcov.info +813 -858
- package/dist/index.esm.js +210 -425
- package/dist/index.esm.js.map +1 -1
- package/jsdoc.json +3 -3
- package/package.json +19 -13
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.js +6 -2
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.test.js +3 -3
- package/src/components/MlFeatureEditor/MlFeatureEditor.test.js +2 -2
- package/src/components/MlFollowGps/MlFollowGps.js +74 -12
- package/src/components/MlGPXViewer/MlGPXViewer.js +69 -81
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js +6 -90
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +4 -22
- package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.js +2 -2
- package/src/components/MlNavigationCompass/MlNavigationCompass.js +17 -39
- package/src/components/MlNavigationCompass/MlNavigationCompass.test.js +3 -3
- package/src/components/MlNavigationTools/MlNavigationTools.js +30 -63
- package/src/components/MlOsmLayer/MlOsmLayer.js +15 -56
- package/src/components/MlOsmLayer/MlOsmLayer.stories.js +21 -10
- package/src/components/MlOsmLayer/MlOsmLayer.test.js +4 -4
- package/src/components/MlScaleReference/MlScaleReference.js +29 -82
- package/src/components/MlShareMapState/MlShareMapState.stories.js +1 -3
- package/src/components/MlThreeJsLayer/lib/GLTFLoader.js +2369 -2591
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.doc.de.md +3 -0
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.js +165 -0
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.meta.json +15 -0
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.stories.js +52 -0
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.test.js +20 -0
- package/src/components/MlTransitionGeoJsonLayer/assets/sample_1.json +26 -0
- package/src/components/MlTransitionGeoJsonLayer/assets/sample_2.json +22 -0
- package/src/components/MlTransitionGeoJsonLayer/assets/sample_polygon_1.json +33 -0
- package/src/components/{MlGeoJsonLayer → MlTransitionGeoJsonLayer}/util/transitionFunctions.js +63 -97
- package/src/components/MlWmsLayer/MlWmsLayer.js +1 -2
- package/src/decorators/MapContextDecorator.js +5 -0
- package/src/decorators/MultiMapContextDecorator.js +6 -0
- package/src/hooks/useMap.js +8 -4
- package/src/hooks/useMapState.js +4 -1
- package/src/decorators/EmptyMapContextDecorator.js +0 -25
- package/src/decorators/MapContext3DDecorator.js +0 -39
- package/src/decorators/MapContextDashboardDecorator.js +0 -19
- package/src/decorators/MapContextKlokantechBasicDecorator.js +0 -39
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
|
|
4
|
+
import * as turf from "@turf/turf";
|
|
5
|
+
|
|
6
|
+
import useMap from "../../hooks/useMap";
|
|
7
|
+
|
|
8
|
+
import { _transitionToGeojson } from "./util/transitionFunctions";
|
|
9
|
+
import { MlGeoJsonLayer } from "../..";
|
|
10
|
+
|
|
11
|
+
const msPerStep = 50;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
|
|
15
|
+
*
|
|
16
|
+
* @component
|
|
17
|
+
*/
|
|
18
|
+
const MlTransitionGeoJsonLayer = (props) => {
|
|
19
|
+
const { geojson, ...restProps } = props;
|
|
20
|
+
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
21
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
22
|
+
const initializedRef = useRef(false);
|
|
23
|
+
|
|
24
|
+
// transition effect variables
|
|
25
|
+
const oldGeojsonRef = useRef(null);
|
|
26
|
+
const transitionInProgressRef = useRef(false);
|
|
27
|
+
const transitionTimeoutRef = useRef(undefined);
|
|
28
|
+
const currentTransitionStepRef = useRef(false);
|
|
29
|
+
const transitionGeojsonDataRef = useRef([]);
|
|
30
|
+
const transitionGeojsonCommonDataRef = useRef([]);
|
|
31
|
+
const [displayGeojson, setDisplayGeojson] = useState(turf.featureCollection([]));
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
return () => {
|
|
35
|
+
// This is the cleanup function, it is called when this react component is removed from react-dom
|
|
36
|
+
if (transitionTimeoutRef.current) {
|
|
37
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
const transitionToGeojson = useCallback(() => {
|
|
43
|
+
_transitionToGeojson(
|
|
44
|
+
props,
|
|
45
|
+
transitionGeojsonCommonDataRef,
|
|
46
|
+
transitionGeojsonDataRef,
|
|
47
|
+
transitionInProgressRef,
|
|
48
|
+
oldGeojsonRef,
|
|
49
|
+
msPerStep,
|
|
50
|
+
currentTransitionStepRef,
|
|
51
|
+
mapHook.map,
|
|
52
|
+
transitionTimeoutRef,
|
|
53
|
+
setDisplayGeojson
|
|
54
|
+
);
|
|
55
|
+
}, [props, mapHook.map]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
typeof props.transitionTime !== "undefined" &&
|
|
62
|
+
props.type === "line" &&
|
|
63
|
+
oldGeojsonRef.current
|
|
64
|
+
) {
|
|
65
|
+
transitionInProgressRef.current = false;
|
|
66
|
+
currentTransitionStepRef.current = false;
|
|
67
|
+
transitionGeojsonDataRef.current = [];
|
|
68
|
+
transitionGeojsonCommonDataRef.current = [];
|
|
69
|
+
transitionToGeojson();
|
|
70
|
+
}
|
|
71
|
+
oldGeojsonRef.current = props.geojson;
|
|
72
|
+
}, [mapHook.map, transitionToGeojson, props]);
|
|
73
|
+
|
|
74
|
+
const startTransition = useCallback(() => {
|
|
75
|
+
if (
|
|
76
|
+
props.type === "line" &&
|
|
77
|
+
typeof props.transitionTime !== "undefined" &&
|
|
78
|
+
props.transitionTime &&
|
|
79
|
+
typeof props.geojson.geometry !== "undefined" &&
|
|
80
|
+
JSON.stringify(oldGeojsonRef.current) !== JSON.stringify(props.geojson)
|
|
81
|
+
) {
|
|
82
|
+
transitionToGeojson(props.geojson);
|
|
83
|
+
oldGeojsonRef.current = props.geojson;
|
|
84
|
+
}
|
|
85
|
+
}, [props, transitionToGeojson]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!mapHook.mapIsReady || !props.geojson) return;
|
|
89
|
+
|
|
90
|
+
initializedRef.current = true;
|
|
91
|
+
|
|
92
|
+
startTransition();
|
|
93
|
+
}, [mapHook.mapIsReady, startTransition, props]);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
<MlGeoJsonLayer {...restProps} geojson={displayGeojson} />
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
MlTransitionGeoJsonLayer.propTypes = {
|
|
103
|
+
/**
|
|
104
|
+
* Id of the target MapLibre instance in mapContext
|
|
105
|
+
*/
|
|
106
|
+
mapId: PropTypes.string,
|
|
107
|
+
/**
|
|
108
|
+
* Type of the layer that will be added to the MapLibre instance.
|
|
109
|
+
* Possible values: "line", "circle", "fill"
|
|
110
|
+
*/
|
|
111
|
+
type: PropTypes.string,
|
|
112
|
+
/**
|
|
113
|
+
* Layout property object, that is passed to the addLayer call.
|
|
114
|
+
* Possible props depend on the layer type.
|
|
115
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
|
|
116
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
117
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
118
|
+
*/
|
|
119
|
+
layout: PropTypes.object,
|
|
120
|
+
/**
|
|
121
|
+
* Paint property object, that is passed to the addLayer call.
|
|
122
|
+
* Possible props depend on the layer type.
|
|
123
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
|
|
124
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
125
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
126
|
+
*/
|
|
127
|
+
paint: PropTypes.object,
|
|
128
|
+
/**
|
|
129
|
+
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
130
|
+
*/
|
|
131
|
+
defaultPaintOverrides: PropTypes.object,
|
|
132
|
+
/**
|
|
133
|
+
* Javascript object that is spread into the addLayer commands first parameter.
|
|
134
|
+
*/
|
|
135
|
+
options: PropTypes.object,
|
|
136
|
+
/**
|
|
137
|
+
* GeoJSON data that is supposed to be rendered by this component.
|
|
138
|
+
*/
|
|
139
|
+
geojson: PropTypes.object,
|
|
140
|
+
/**
|
|
141
|
+
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
142
|
+
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
143
|
+
*/
|
|
144
|
+
insertBeforeLayer: PropTypes.string,
|
|
145
|
+
/**
|
|
146
|
+
* Click event handler that is executed whenever a geometry rendered by this component is clicked.
|
|
147
|
+
*/
|
|
148
|
+
onClick: PropTypes.func,
|
|
149
|
+
/**
|
|
150
|
+
* Hover event handler that is executed whenever a geometry rendered by this component is hovered.
|
|
151
|
+
*/
|
|
152
|
+
onHover: PropTypes.func,
|
|
153
|
+
/**
|
|
154
|
+
* Leave event handler that is executed whenever a geometry rendered by this component is
|
|
155
|
+
* left/unhovered.
|
|
156
|
+
*/
|
|
157
|
+
onLeave: PropTypes.func,
|
|
158
|
+
/**
|
|
159
|
+
* Creates transition animation whenever the geojson prop changes.
|
|
160
|
+
* Only works with layer type "line" and LineString GeoJSON data.
|
|
161
|
+
*/
|
|
162
|
+
transitionTime: PropTypes.number,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export default MlTransitionGeoJsonLayer;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useState, useContext, useRef, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import MlTransitionGeoJsonLayer from "./MlTransitionGeoJsonLayer";
|
|
4
|
+
|
|
5
|
+
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
6
|
+
import { MapContext } from "@mapcomponents/react-core";
|
|
7
|
+
|
|
8
|
+
import sample_geojson_1 from "./assets/sample_1.json";
|
|
9
|
+
import sample_geojson_2 from "./assets/sample_2.json";
|
|
10
|
+
import sample_polygon_geojson_1 from "./assets/sample_polygon_1.json";
|
|
11
|
+
|
|
12
|
+
console.log(sample_polygon_geojson_1);
|
|
13
|
+
const storyoptions = {
|
|
14
|
+
title: "MapComponents/MlTransitionGeoJsonLayer",
|
|
15
|
+
component: MlTransitionGeoJsonLayer,
|
|
16
|
+
argTypes: {
|
|
17
|
+
url: {},
|
|
18
|
+
layer: {},
|
|
19
|
+
},
|
|
20
|
+
decorators: mapContextDecorator,
|
|
21
|
+
};
|
|
22
|
+
export default storyoptions;
|
|
23
|
+
|
|
24
|
+
const LinestringTransitionTemplate = (props) => {
|
|
25
|
+
const mapContext = useContext(MapContext);
|
|
26
|
+
const [geojson, setGeojson] = useState(sample_geojson_1);
|
|
27
|
+
const initializedRef = useRef(false);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!mapContext.getMap() || initializedRef.current) return;
|
|
31
|
+
|
|
32
|
+
initializedRef.current = true;
|
|
33
|
+
mapContext.getMap().setCenter({ lng: 7.137609868988648, lat: 50.74746799549129 });
|
|
34
|
+
mapContext.getMap().setZoom(9.5);
|
|
35
|
+
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
setGeojson(sample_geojson_2);
|
|
38
|
+
}, 4000);
|
|
39
|
+
}, [geojson, mapContext]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<MlTransitionGeoJsonLayer type="line" geojson={geojson} transitionTime={2000} {...props} />
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Linestring = LinestringTransitionTemplate.bind({});
|
|
49
|
+
Linestring.parameters = {};
|
|
50
|
+
Linestring.args = {
|
|
51
|
+
paint: { "line-color": "red", "line-width": 4 },
|
|
52
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { layerRemovalTest, sourceRemovalTest } from "../../util";
|
|
2
|
+
|
|
3
|
+
import MlTransitionGeoJsonLayer from "./MlTransitionGeoJsonLayer";
|
|
4
|
+
import geojson from "./assets/sample_1.json";
|
|
5
|
+
import { uuid_regex } from "../../setupTests";
|
|
6
|
+
|
|
7
|
+
const testComponent = <MlTransitionGeoJsonLayer type="line" geojson={geojson} />;
|
|
8
|
+
|
|
9
|
+
layerRemovalTest(
|
|
10
|
+
"<MlTransitionGeoJsonLayer />",
|
|
11
|
+
testComponent,
|
|
12
|
+
new RegExp('^.*"MlGeoJsonLayer-' + uuid_regex + '".*$'),
|
|
13
|
+
"MlTransitionGeoJsonLayer-{uuid}"
|
|
14
|
+
);
|
|
15
|
+
sourceRemovalTest(
|
|
16
|
+
"<MlTransitionGeoJsonLayer />",
|
|
17
|
+
testComponent,
|
|
18
|
+
new RegExp('^.*"MlGeoJsonLayer-' + uuid_regex + '".*$'),
|
|
19
|
+
"MlTransitionGeoJsonLayer-{uuid}"
|
|
20
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "Feature",
|
|
3
|
+
"properties": {},
|
|
4
|
+
"geometry": {
|
|
5
|
+
"type": "LineString",
|
|
6
|
+
"coordinates": [
|
|
7
|
+
[7.1074676513671875, 50.74340774029213],
|
|
8
|
+
[7.0992279052734375, 50.756441089372665],
|
|
9
|
+
[7.079315185546874, 50.764693667025014],
|
|
10
|
+
[7.045669555664062, 50.77945780529241],
|
|
11
|
+
[7.030563354492187, 50.79161300845443],
|
|
12
|
+
[7.0291900634765625, 50.80940599750376],
|
|
13
|
+
[7.0236968994140625, 50.820685846099174],
|
|
14
|
+
[7.0085906982421875, 50.825891011253546],
|
|
15
|
+
[6.9879913330078125, 50.826758482363275],
|
|
16
|
+
[6.97906494140625, 50.835432306955276],
|
|
17
|
+
[6.9824981689453125, 50.84583876895451],
|
|
18
|
+
[6.9962310791015625, 50.85147463352982],
|
|
19
|
+
[7.012023925781249, 50.85710981721644],
|
|
20
|
+
[7.021636962890625, 50.86664473085768],
|
|
21
|
+
[7.0367431640625, 50.872278081520406],
|
|
22
|
+
[7.0477294921875, 50.877044231111014],
|
|
23
|
+
[7.052536010742187, 50.88397594225127]
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "Feature",
|
|
3
|
+
"properties": {},
|
|
4
|
+
"geometry": {
|
|
5
|
+
"type": "LineString",
|
|
6
|
+
"coordinates": [
|
|
7
|
+
[7.0635223388671875, 50.71385204707258],
|
|
8
|
+
[7.06146240234375, 50.709721458354075],
|
|
9
|
+
[7.063865661621094, 50.70298129536074],
|
|
10
|
+
[7.064552307128906, 50.69906720767511],
|
|
11
|
+
[7.059059143066406, 50.69428287906098],
|
|
12
|
+
[7.05596923828125, 50.68797551838366],
|
|
13
|
+
[7.0580291748046875, 50.680797145321655],
|
|
14
|
+
[7.062835693359375, 50.67514068397085],
|
|
15
|
+
[7.060432434082031, 50.6686131506577],
|
|
16
|
+
[7.051849365234375, 50.659255436656736],
|
|
17
|
+
[7.044639587402344, 50.6512019574539],
|
|
18
|
+
[7.0484161376953125, 50.64271166020676],
|
|
19
|
+
[7.0566558837890625, 50.63748609931014]
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "FeatureCollection",
|
|
3
|
+
"features": [
|
|
4
|
+
{
|
|
5
|
+
"type": "Feature",
|
|
6
|
+
"properties": {},
|
|
7
|
+
"geometry": {
|
|
8
|
+
"coordinates": [
|
|
9
|
+
[
|
|
10
|
+
[7.08646747303149, 50.74485058672653],
|
|
11
|
+
[7.084287513691095, 50.74371917250187],
|
|
12
|
+
[7.084437772332876, 50.743610683782215],
|
|
13
|
+
[7.084640903561933, 50.743721758552354],
|
|
14
|
+
[7.085805654941254, 50.74293993704128],
|
|
15
|
+
[7.087023278906713, 50.74218320888983],
|
|
16
|
+
[7.087791368229503, 50.74258090834434],
|
|
17
|
+
[7.088796806075749, 50.743261830692745],
|
|
18
|
+
[7.089275088452752, 50.743701110992674],
|
|
19
|
+
[7.088087117762917, 50.74409411011173],
|
|
20
|
+
[7.087662548338368, 50.743784963165815],
|
|
21
|
+
[7.087184330538875, 50.7440368518605],
|
|
22
|
+
[7.087233860417484, 50.744077781245316],
|
|
23
|
+
[7.08714938625954, 50.744122118772154],
|
|
24
|
+
[7.087057544749172, 50.74427276821896],
|
|
25
|
+
[7.087104984084277, 50.744509715654885],
|
|
26
|
+
[7.08646747303149, 50.74485058672653]
|
|
27
|
+
]
|
|
28
|
+
],
|
|
29
|
+
"type": "Polygon"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
package/src/components/{MlGeoJsonLayer → MlTransitionGeoJsonLayer}/util/transitionFunctions.js
RENAMED
|
@@ -2,41 +2,28 @@ import * as turf from "@turf/turf";
|
|
|
2
2
|
|
|
3
3
|
const _showNextTransitionSegment = function (
|
|
4
4
|
props,
|
|
5
|
-
layerId,
|
|
6
5
|
map,
|
|
7
6
|
transitionInProgressRef,
|
|
8
7
|
transitionGeojsonDataRef,
|
|
9
8
|
transitionGeojsonCommonDataRef,
|
|
10
9
|
currentTransitionStepRef,
|
|
11
10
|
msPerStep,
|
|
12
|
-
transitionTimeoutRef
|
|
11
|
+
transitionTimeoutRef,
|
|
12
|
+
setDisplayGeojson
|
|
13
13
|
) {
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
) {
|
|
18
|
-
transitionTimeoutRef.current = setTimeout(() => _showNextTransitionSegment(...arguments), msPerStep);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (
|
|
22
|
-
typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !==
|
|
23
|
-
"undefined"
|
|
24
|
-
) {
|
|
14
|
+
if (typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !== "undefined") {
|
|
15
|
+
// if at last transition step set to target geojson
|
|
16
|
+
// else to an assembled LineString from common geometry and the current transition step geometry
|
|
25
17
|
let newData =
|
|
26
|
-
currentTransitionStepRef.current + 1 ===
|
|
27
|
-
transitionGeojsonDataRef.current.length
|
|
18
|
+
currentTransitionStepRef.current + 1 === transitionGeojsonDataRef.current.length
|
|
28
19
|
? props.geojson
|
|
29
20
|
: turf.lineString([
|
|
30
21
|
...transitionGeojsonCommonDataRef.current,
|
|
31
|
-
...transitionGeojsonDataRef.current[currentTransitionStepRef.current]
|
|
32
|
-
.
|
|
22
|
+
...transitionGeojsonDataRef.current[currentTransitionStepRef.current].geometry
|
|
23
|
+
.coordinates,
|
|
33
24
|
]);
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
map.getSource(layerId).setData(newData);
|
|
26
|
+
setDisplayGeojson(newData);
|
|
40
27
|
|
|
41
28
|
if (typeof props.onTransitionFrame === "function") {
|
|
42
29
|
props.onTransitionFrame(newData);
|
|
@@ -47,7 +34,10 @@ const _showNextTransitionSegment = function (
|
|
|
47
34
|
transitionInProgressRef.current &&
|
|
48
35
|
currentTransitionStepRef.current < transitionGeojsonDataRef.current.length
|
|
49
36
|
) {
|
|
50
|
-
transitionTimeoutRef.current = setTimeout(
|
|
37
|
+
transitionTimeoutRef.current = setTimeout(
|
|
38
|
+
() => _showNextTransitionSegment(...arguments),
|
|
39
|
+
msPerStep
|
|
40
|
+
);
|
|
51
41
|
} else {
|
|
52
42
|
if (typeof props.onTransitionEnd === "function") {
|
|
53
43
|
props.onTransitionEnd(props.geojson);
|
|
@@ -58,7 +48,6 @@ const _showNextTransitionSegment = function (
|
|
|
58
48
|
};
|
|
59
49
|
|
|
60
50
|
const _transitionToGeojson = (
|
|
61
|
-
newGeojson,
|
|
62
51
|
props,
|
|
63
52
|
transitionGeojsonCommonDataRef,
|
|
64
53
|
transitionGeojsonDataRef,
|
|
@@ -67,8 +56,8 @@ const _transitionToGeojson = (
|
|
|
67
56
|
msPerStep,
|
|
68
57
|
currentTransitionStepRef,
|
|
69
58
|
map,
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
transitionTimeoutRef,
|
|
60
|
+
setDisplayGeojson
|
|
72
61
|
) => {
|
|
73
62
|
// create the transition geojson between oldGeojsonRef.current and props.geojson
|
|
74
63
|
|
|
@@ -87,7 +76,7 @@ const _transitionToGeojson = (
|
|
|
87
76
|
type: "Feature",
|
|
88
77
|
};
|
|
89
78
|
|
|
90
|
-
let targetGeojson =
|
|
79
|
+
let targetGeojson = props.geojson;
|
|
91
80
|
|
|
92
81
|
let longerGeojson = targetGeojson;
|
|
93
82
|
let shorterGeojson = sourceGeojson;
|
|
@@ -112,10 +101,7 @@ const _transitionToGeojson = (
|
|
|
112
101
|
return;
|
|
113
102
|
}
|
|
114
103
|
|
|
115
|
-
if (
|
|
116
|
-
longerGeojson.geometry.coordinates.length <
|
|
117
|
-
shorterGeojson.geometry.coordinates.length
|
|
118
|
-
) {
|
|
104
|
+
if (longerGeojson.geometry.coordinates.length < shorterGeojson.geometry.coordinates.length) {
|
|
119
105
|
longerGeojson = sourceGeojson;
|
|
120
106
|
shorterGeojson = targetGeojson;
|
|
121
107
|
reverseOrder = true;
|
|
@@ -125,15 +111,11 @@ const _transitionToGeojson = (
|
|
|
125
111
|
for (var i = 0, len = longerGeojson.geometry.coordinates.length; i < len; i++) {
|
|
126
112
|
if (
|
|
127
113
|
typeof shorterGeojson.geometry.coordinates[i] !== "undefined" &&
|
|
128
|
-
longerGeojson.geometry.coordinates[i][0] ===
|
|
129
|
-
|
|
130
|
-
longerGeojson.geometry.coordinates[i][1] ===
|
|
131
|
-
shorterGeojson.geometry.coordinates[i][1]
|
|
114
|
+
longerGeojson.geometry.coordinates[i][0] === shorterGeojson.geometry.coordinates[i][0] &&
|
|
115
|
+
longerGeojson.geometry.coordinates[i][1] === shorterGeojson.geometry.coordinates[i][1]
|
|
132
116
|
) {
|
|
133
117
|
// if coordinates are equal
|
|
134
|
-
transitionGeojsonCommonDataRef.current.push(
|
|
135
|
-
longerGeojson.geometry.coordinates[i]
|
|
136
|
-
);
|
|
118
|
+
transitionGeojsonCommonDataRef.current.push(longerGeojson.geometry.coordinates[i]);
|
|
137
119
|
} else {
|
|
138
120
|
if (typeof longerGeojson.geometry.coordinates[i] !== "undefined") {
|
|
139
121
|
transitionCoordinatesLong.push(longerGeojson.geometry.coordinates[i]);
|
|
@@ -158,80 +140,42 @@ const _transitionToGeojson = (
|
|
|
158
140
|
|
|
159
141
|
let transitionSteps = props.transitionTime / msPerStep;
|
|
160
142
|
let srcCoordinatesDistance =
|
|
161
|
-
srcCoordinates.length > 1
|
|
162
|
-
? Math.round(turf.length(turf.lineString(srcCoordinates)))
|
|
163
|
-
: 0;
|
|
143
|
+
srcCoordinates.length > 1 ? Math.round(turf.length(turf.lineString(srcCoordinates))) : 0;
|
|
164
144
|
let targetCoordinatesDistance =
|
|
165
|
-
targetCoordinates.length > 1
|
|
166
|
-
? Math.round(turf.length(turf.lineString(targetCoordinates)))
|
|
167
|
-
: 0;
|
|
145
|
+
targetCoordinates.length > 1 ? Math.round(turf.length(turf.lineString(targetCoordinates))) : 0;
|
|
168
146
|
let transitionDistance = targetCoordinatesDistance + srcCoordinatesDistance;
|
|
169
147
|
|
|
170
148
|
let srcCoordinatesShare = srcCoordinatesDistance / transitionDistance;
|
|
171
149
|
let srcTransitionSteps = Math.round(transitionSteps * srcCoordinatesShare);
|
|
172
|
-
let srcPerStepDistance =
|
|
173
|
-
Math.round((srcCoordinatesDistance / srcTransitionSteps) * 100) / 100;
|
|
150
|
+
let srcPerStepDistance = Math.round((srcCoordinatesDistance / srcTransitionSteps) * 100) / 100;
|
|
174
151
|
|
|
175
152
|
let targetCoordinatesShare = targetCoordinatesDistance / transitionDistance;
|
|
176
153
|
let targetTransitionSteps = Math.round(transitionSteps * targetCoordinatesShare);
|
|
177
154
|
let targetPerStepDistance =
|
|
178
155
|
Math.round((targetCoordinatesDistance / targetTransitionSteps) * 100) / 100;
|
|
179
156
|
|
|
180
|
-
transitionGeojsonDataRef.current = [];
|
|
181
|
-
|
|
182
157
|
// use srcPerStepDistance as src coordinates are always animated backwards
|
|
183
158
|
let loopStepDistance = srcCoordinatesDistance;
|
|
184
159
|
if (loopStepDistance <= 0) {
|
|
185
160
|
loopStepDistance = 0.1;
|
|
186
161
|
}
|
|
187
|
-
let tmpLinestring = {};
|
|
188
|
-
let tmpChunks = {};
|
|
189
|
-
|
|
190
|
-
if (srcCoordinates.length > 1) {
|
|
191
|
-
tmpChunks = turf.lineChunk(
|
|
192
|
-
turf.lineString(srcCoordinates),
|
|
193
|
-
srcPerStepDistance
|
|
194
|
-
//{reverse:true}
|
|
195
|
-
);
|
|
196
|
-
// for some reason turf.lineChunk returns the full lineString as element 0, chunks start at 1
|
|
197
|
-
tmpLinestring = tmpChunks.features[1];
|
|
198
|
-
for (i = 0; i < srcTransitionSteps; i++) {
|
|
199
|
-
transitionGeojsonDataRef.current.push(tmpLinestring);
|
|
200
|
-
if (typeof tmpChunks.features[i] !== "undefined") {
|
|
201
|
-
tmpLinestring = turf.lineString([
|
|
202
|
-
...tmpLinestring.geometry.coordinates,
|
|
203
|
-
...tmpChunks.features[i].geometry.coordinates,
|
|
204
|
-
]);
|
|
205
|
-
} else {
|
|
206
|
-
transitionGeojsonDataRef.current.push(tmpLinestring);
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
transitionGeojsonDataRef.current.reverse();
|
|
211
|
-
}
|
|
212
162
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
transitionGeojsonDataRef.current.push(tmpLinestring);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
transitionGeojsonDataRef.current.push(props.geojson);
|
|
163
|
+
// create transition step data as an array of all required FeatureCollection states until the transition is complete
|
|
164
|
+
let transitionStepData;
|
|
165
|
+
|
|
166
|
+
transitionStepData = [
|
|
167
|
+
...createTransitionSteps(srcCoordinates, srcPerStepDistance, srcTransitionSteps),
|
|
168
|
+
];
|
|
169
|
+
transitionStepData.reverse();
|
|
170
|
+
|
|
171
|
+
transitionStepData = [
|
|
172
|
+
...transitionStepData,
|
|
173
|
+
...createTransitionSteps(targetCoordinates, targetPerStepDistance, targetTransitionSteps),
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
transitionStepData.push(targetGeojson);
|
|
177
|
+
|
|
178
|
+
transitionGeojsonDataRef.current = transitionStepData;
|
|
235
179
|
|
|
236
180
|
currentTransitionStepRef.current = 1;
|
|
237
181
|
transitionInProgressRef.current = true;
|
|
@@ -239,17 +183,39 @@ const _transitionToGeojson = (
|
|
|
239
183
|
() =>
|
|
240
184
|
_showNextTransitionSegment(
|
|
241
185
|
props,
|
|
242
|
-
layerId,
|
|
243
186
|
map,
|
|
244
187
|
transitionInProgressRef,
|
|
245
188
|
transitionGeojsonDataRef,
|
|
246
189
|
transitionGeojsonCommonDataRef,
|
|
247
190
|
currentTransitionStepRef,
|
|
248
191
|
msPerStep,
|
|
249
|
-
transitionTimeoutRef
|
|
192
|
+
transitionTimeoutRef,
|
|
193
|
+
setDisplayGeojson
|
|
250
194
|
),
|
|
251
195
|
msPerStep
|
|
252
196
|
);
|
|
253
197
|
};
|
|
254
198
|
|
|
199
|
+
let createTransitionSteps = (linestringCoordinates, perStepDistance, stepCnt) => {
|
|
200
|
+
let transitionSteps = [];
|
|
201
|
+
|
|
202
|
+
if (linestringCoordinates.length > 1) {
|
|
203
|
+
let tmpChunks = turf.lineChunk(turf.lineString(linestringCoordinates), perStepDistance);
|
|
204
|
+
// tmpLineString contains all coordinates of all previous plus current loop iteration
|
|
205
|
+
let tmpLinestring = tmpChunks.features[0];
|
|
206
|
+
for (let i = 0; i < stepCnt; i++) {
|
|
207
|
+
transitionSteps.push(tmpLinestring);
|
|
208
|
+
if (typeof tmpChunks.features[i] !== "undefined") {
|
|
209
|
+
tmpLinestring = turf.lineString([
|
|
210
|
+
...tmpLinestring.geometry.coordinates,
|
|
211
|
+
...tmpChunks.features[i].geometry.coordinates,
|
|
212
|
+
]);
|
|
213
|
+
} else {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return transitionSteps;
|
|
219
|
+
};
|
|
220
|
+
|
|
255
221
|
export { _showNextTransitionSegment, _transitionToGeojson };
|
|
@@ -2,7 +2,6 @@ import React, { useRef, useEffect } from "react";
|
|
|
2
2
|
import useMap from "../../hooks/useMap";
|
|
3
3
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
|
-
import { v4 as uuidv4 } from "uuid";
|
|
6
5
|
|
|
7
6
|
const defaultProps = {
|
|
8
7
|
visible: true,
|
|
@@ -98,7 +97,7 @@ const MlWmsLayer = (props) => {
|
|
|
98
97
|
if (!props.visible) {
|
|
99
98
|
mapHook.map.setLayoutProperty(layerId.current, "visibility", "none");
|
|
100
99
|
}
|
|
101
|
-
}, [mapHook
|
|
100
|
+
}, [mapHook, props]);
|
|
102
101
|
|
|
103
102
|
useEffect(() => {
|
|
104
103
|
if (!mapHook.map || !initializedRef.current) return;
|
|
@@ -4,6 +4,7 @@ import { MapComponentsProvider } from "@mapcomponents/react-core";
|
|
|
4
4
|
import MapLibreMap from "../components/MapLibreMap/MapLibreMap";
|
|
5
5
|
import "./style.css";
|
|
6
6
|
import { createTheme, ThemeProvider } from "@mui/material/styles";
|
|
7
|
+
import MlNavgiationTools from "../components/MlNavigationTools/MlNavigationTools";
|
|
7
8
|
|
|
8
9
|
const theme = createTheme({});
|
|
9
10
|
|
|
@@ -21,6 +22,10 @@ const decorators = [
|
|
|
21
22
|
}}
|
|
22
23
|
mapId="map_1"
|
|
23
24
|
/>
|
|
25
|
+
<MlNavgiationTools
|
|
26
|
+
mapId="map_1">
|
|
27
|
+
|
|
28
|
+
</MlNavgiationTools>
|
|
24
29
|
</MapComponentsProvider>
|
|
25
30
|
</ThemeProvider>
|
|
26
31
|
</div>
|
|
@@ -7,6 +7,7 @@ import MapLibreMap from "../components/MapLibreMap/MapLibreMap";
|
|
|
7
7
|
|
|
8
8
|
import "./style.css";
|
|
9
9
|
import { createTheme, ThemeProvider } from "@mui/material/styles";
|
|
10
|
+
import MlNavgiationTools from "../components/MlNavigationTools/MlNavigationTools";
|
|
10
11
|
|
|
11
12
|
const theme = createTheme({});
|
|
12
13
|
|
|
@@ -64,6 +65,11 @@ const decorators = [
|
|
|
64
65
|
//],
|
|
65
66
|
}}
|
|
66
67
|
/>
|
|
68
|
+
|
|
69
|
+
<MlNavgiationTools
|
|
70
|
+
mapId="map_1">
|
|
71
|
+
|
|
72
|
+
</MlNavgiationTools>
|
|
67
73
|
</div>
|
|
68
74
|
</div>
|
|
69
75
|
</MapComponentsProvider>
|