@mapcomponents/react-maplibre 0.1.17 → 0.1.21
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 +29 -7
- package/coverage/clover.xml +218 -203
- package/coverage/coverage-final.json +6 -6
- package/coverage/lcov-report/index.html +44 -44
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +1 -1
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +57 -15
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +15 -15
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
- package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
- package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +261 -111
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +9 -9
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
- 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/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 +50 -14
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +15 -15
- 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 +35 -89
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +17 -17
- 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 +12 -12
- package/coverage/lcov-report/src/hooks/useMap.js.html +40 -28
- package/coverage/lcov-report/src/hooks/useMapState.js.html +34 -34
- 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 +396 -357
- package/dist/index.esm.js +103 -70
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/build-catalogue-markdown-docs.js +5 -3
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.js +26 -21
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.test.js +3 -3
- package/src/components/MlCreatePdfButton/MlCreatePdfButton.doc.de.md +2 -2
- package/src/components/MlCreatePdfButton/MlCreatePdfButton.doc.en.md +3 -0
- package/src/components/MlFeatureEditor/MlFeatureEditor.test.js +2 -2
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js +21 -7
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +22 -7
- package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.js +10 -1
- package/src/components/MlNavigationCompass/MlNavigationCompass.test.js +2 -2
- package/src/components/MlShareMapState/MlShareMapState.js +138 -88
- package/src/components/MlShareMapState/MlShareMapState.stories.js +79 -29
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +18 -6
- package/src/components/MlWmsLayer/MlWmsLayer.js +16 -34
- package/src/hooks/useMap.js +4 -0
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import React, { useState} from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import MlShareMapState from "./MlShareMapState";
|
|
4
4
|
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
5
|
-
import
|
|
5
|
+
import useMapState from "../../hooks/useMapState";
|
|
6
|
+
import useMap from "../../hooks/useMap";
|
|
7
|
+
import Sidebar from "../../ui_components/Sidebar";
|
|
8
|
+
import ListItem from "@mui/material/ListItem";
|
|
9
|
+
import IconButton from "@mui/material/IconButton";
|
|
10
|
+
import VisibilityIcon from "@mui/icons-material/Visibility";
|
|
11
|
+
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
|
|
12
|
+
import ListItemText from "@mui/material/ListItemText";
|
|
13
|
+
import sample_geojson_1 from "../MlGeoJsonLayer/assets/sample_1.json";
|
|
14
|
+
import sample_geojson_2 from "../MlGeoJsonLayer/assets/sample_2.json";
|
|
15
|
+
import List from "@mui/material/List";
|
|
16
|
+
import MlGeoJsonLayer from "../MlGeoJsonLayer/MlGeoJsonLayer";
|
|
17
|
+
import { ToggleButton } from "@mui/material";
|
|
18
|
+
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
|
|
19
|
+
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
|
|
6
20
|
|
|
7
21
|
const storyoptions = {
|
|
8
22
|
title: "MapComponents/MlShareMapState",
|
|
@@ -12,37 +26,73 @@ const storyoptions = {
|
|
|
12
26
|
};
|
|
13
27
|
export default storyoptions;
|
|
14
28
|
|
|
15
|
-
const Template = (
|
|
16
|
-
const [
|
|
17
|
-
const [
|
|
29
|
+
const Template = () => {
|
|
30
|
+
const geoJsonArray = [sample_geojson_1, sample_geojson_2];
|
|
31
|
+
const [watchState, setWatchState] = useState(true);
|
|
32
|
+
const mapHook = useMap({ mapId: "map_1" });
|
|
33
|
+
const mapState = useMapState({
|
|
34
|
+
mapId: "map_1",
|
|
35
|
+
watch: {
|
|
36
|
+
viewport: false,
|
|
37
|
+
layers: true,
|
|
38
|
+
sources: false,
|
|
39
|
+
},
|
|
40
|
+
filter: {
|
|
41
|
+
includeBaseLayers: false,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
18
44
|
|
|
19
45
|
return (
|
|
20
46
|
<>
|
|
21
|
-
<button
|
|
22
|
-
style={{ zIndex: "1000", position: "absolute" }}
|
|
23
|
-
onClick={() => setWatchState(!watchState)}
|
|
24
|
-
>
|
|
25
|
-
watch map state {watchState ? 1 : 0}
|
|
26
|
-
</button>
|
|
27
|
-
<button
|
|
28
|
-
style={{ zIndex: "1000", position: "absolute" }}
|
|
29
|
-
onClick={() => setTestLayerVisible(!testLayerVisible)}
|
|
30
|
-
>
|
|
31
|
-
visibility {testLayerVisible ? 1 : 0}
|
|
32
|
-
</button>
|
|
33
47
|
<MlShareMapState active={watchState} />
|
|
34
|
-
|
|
35
|
-
layerId={"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
{geoJsonArray.map((el, i) => (
|
|
49
|
+
<MlGeoJsonLayer layerId={"GeoJson_" + i} type="line" geojson={el} key={"GeoJson_" + i} />
|
|
50
|
+
))}
|
|
51
|
+
<Sidebar sx={{ wordBreak: "break-word" }}>
|
|
52
|
+
<ToggleButton
|
|
53
|
+
size="small"
|
|
54
|
+
selected={watchState}
|
|
55
|
+
value={watchState}
|
|
56
|
+
onChange={() => {
|
|
57
|
+
setWatchState(!watchState);
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{watchState ? <CheckCircleOutlineIcon /> : <ErrorOutlineIcon />}
|
|
61
|
+
|
|
62
|
+
{watchState ? "active" : "inactive"}
|
|
63
|
+
</ToggleButton>
|
|
64
|
+
<List dense key="layers">
|
|
65
|
+
{mapState.layers?.map((el) => (
|
|
66
|
+
<ListItem
|
|
67
|
+
key={el.id}
|
|
68
|
+
secondaryAction={
|
|
69
|
+
<IconButton
|
|
70
|
+
edge="end"
|
|
71
|
+
aria-label="toggle visibility"
|
|
72
|
+
onClick={() => {
|
|
73
|
+
let currentVisibility = mapHook.map
|
|
74
|
+
?.getLayer?.(el.id)
|
|
75
|
+
?.getLayoutProperty("visibility");
|
|
76
|
+
mapHook.map
|
|
77
|
+
?.getLayer?.(el.id)
|
|
78
|
+
?.setLayoutProperty(
|
|
79
|
+
"visibility",
|
|
80
|
+
currentVisibility === "none" ? "visible" : "none"
|
|
81
|
+
);
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
mapHook.map._render();
|
|
84
|
+
}, 100);
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
{el.visible ? <VisibilityIcon /> : <VisibilityOffIcon />}
|
|
88
|
+
</IconButton>
|
|
89
|
+
}
|
|
90
|
+
>
|
|
91
|
+
<ListItemText primary={el.id} secondary={""} />
|
|
92
|
+
</ListItem>
|
|
93
|
+
))}
|
|
94
|
+
</List>
|
|
95
|
+
</Sidebar>
|
|
46
96
|
</>
|
|
47
97
|
);
|
|
48
98
|
};
|
|
@@ -48,7 +48,7 @@ const MlVectorTileLayer = (props) => {
|
|
|
48
48
|
tiles: [props.url],
|
|
49
49
|
tileSize: 512,
|
|
50
50
|
attribution: "",
|
|
51
|
-
|
|
51
|
+
...props.sourceOptions,
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
for (let key in props.layers) {
|
|
@@ -100,11 +100,19 @@ const MlVectorTileLayer = (props) => {
|
|
|
100
100
|
useEffect(() => {
|
|
101
101
|
if (!mapRef.current) return;
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
for (var key in props.layers) {
|
|
104
|
+
if (mapRef.current.getLayer(layerIdsRef.current[key])) {
|
|
105
|
+
// toggle layer visibility by changing the layout object's visibility property
|
|
106
|
+
if (props.visible) {
|
|
107
|
+
mapContext
|
|
108
|
+
.getMap(props.mapId)
|
|
109
|
+
.setLayoutProperty(layerIdsRef.current[key], "visibility", "visible");
|
|
110
|
+
} else {
|
|
111
|
+
mapContext
|
|
112
|
+
.getMap(props.mapId)
|
|
113
|
+
.setLayoutProperty(layerIdsRef.current[key], "visibility", "none");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
108
116
|
}
|
|
109
117
|
}, [props.visible]);
|
|
110
118
|
|
|
@@ -124,6 +132,10 @@ MlVectorTileLayer.propTypes = {
|
|
|
124
132
|
* Object that hold layers
|
|
125
133
|
*/
|
|
126
134
|
layers: PropTypes.object,
|
|
135
|
+
/**
|
|
136
|
+
* Boolean value to control the visibility of this layer
|
|
137
|
+
*/
|
|
138
|
+
visible: PropTypes.bool,
|
|
127
139
|
/**
|
|
128
140
|
* String of the URL of a wms layer
|
|
129
141
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
|
+
import useMap from "../../hooks/useMap";
|
|
3
3
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import { v4 as uuidv4 } from "uuid";
|
|
@@ -45,31 +45,13 @@ const defaultProps = {
|
|
|
45
45
|
* @component
|
|
46
46
|
*/
|
|
47
47
|
const MlWmsLayer = (props) => {
|
|
48
|
-
const
|
|
48
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
49
49
|
|
|
50
|
-
const componentId = useRef(props.layerId || ("MlWmsLayer-" + uuidv4()));
|
|
51
|
-
const mapRef = useRef(null);
|
|
52
50
|
const initializedRef = useRef(false);
|
|
53
|
-
const layerId = useRef(props.layerId || componentId
|
|
51
|
+
const layerId = useRef(props.layerId || "MlWmsLayer-" + mapHook.componentId);
|
|
54
52
|
|
|
55
53
|
useEffect(() => {
|
|
56
|
-
|
|
57
|
-
return () => {
|
|
58
|
-
// This is the cleanup function, it is called when this react component is removed from react-dom
|
|
59
|
-
if (mapRef.current) {
|
|
60
|
-
mapRef.current.cleanup(_componentId);
|
|
61
|
-
|
|
62
|
-
mapRef.current = null;
|
|
63
|
-
}
|
|
64
|
-
initializedRef.current = false;
|
|
65
|
-
};
|
|
66
|
-
}, []);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
|
|
70
|
-
|
|
71
|
-
mapRef.current = mapContext.getMap(props.mapId);
|
|
72
|
-
if (!mapRef.current) return;
|
|
54
|
+
if (!mapHook.map || initializedRef.current) return;
|
|
73
55
|
|
|
74
56
|
initializedRef.current = true;
|
|
75
57
|
|
|
@@ -90,7 +72,7 @@ const MlWmsLayer = (props) => {
|
|
|
90
72
|
let urlParamsStr =
|
|
91
73
|
decodeURIComponent(urlParams.toString()) + "".replace(/%2F/g, "/").replace(/%3A/g, ":");
|
|
92
74
|
|
|
93
|
-
|
|
75
|
+
mapHook.map.addSource(
|
|
94
76
|
layerId.current,
|
|
95
77
|
{
|
|
96
78
|
type: "raster",
|
|
@@ -99,35 +81,35 @@ const MlWmsLayer = (props) => {
|
|
|
99
81
|
attribution: props.attribution,
|
|
100
82
|
...props.sourceOptions,
|
|
101
83
|
},
|
|
102
|
-
componentId
|
|
84
|
+
mapHook.componentId
|
|
103
85
|
);
|
|
104
86
|
|
|
105
|
-
|
|
87
|
+
mapHook.map.addLayer(
|
|
106
88
|
{
|
|
107
89
|
id: layerId.current,
|
|
108
90
|
type: "raster",
|
|
109
|
-
source:
|
|
91
|
+
source: layerId.current,
|
|
110
92
|
...props.layerOptions,
|
|
111
93
|
},
|
|
112
94
|
props.insertBeforeLayer,
|
|
113
|
-
componentId
|
|
95
|
+
mapHook.componentId
|
|
114
96
|
);
|
|
115
97
|
|
|
116
98
|
if (!props.visible) {
|
|
117
|
-
|
|
99
|
+
mapHook.map.setLayoutProperty(layerId.current, "visibility", "none");
|
|
118
100
|
}
|
|
119
|
-
}, [
|
|
101
|
+
}, [mapHook.map, props]);
|
|
120
102
|
|
|
121
103
|
useEffect(() => {
|
|
122
|
-
if (!
|
|
104
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
123
105
|
|
|
124
106
|
// toggle layer visibility by changing the layout object's visibility property
|
|
125
107
|
if (props.visible) {
|
|
126
|
-
|
|
108
|
+
mapHook.map.setLayoutProperty(layerId.current, "visibility", "visible");
|
|
127
109
|
} else {
|
|
128
|
-
|
|
110
|
+
mapHook.map.setLayoutProperty(layerId.current, "visibility", "none");
|
|
129
111
|
}
|
|
130
|
-
}, [props.visible]);
|
|
112
|
+
}, [props.visible, mapHook.map]);
|
|
131
113
|
|
|
132
114
|
return <></>;
|
|
133
115
|
};
|
package/src/hooks/useMap.js
CHANGED
|
@@ -25,8 +25,12 @@ function useMap(props) {
|
|
|
25
25
|
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
let _componentId = componentId.current;
|
|
28
|
+
console.log("initialize maphook");
|
|
28
29
|
|
|
29
30
|
return () => {
|
|
31
|
+
console.log("cleanup maphook");
|
|
32
|
+
console.log(typeof mapRef.current);
|
|
33
|
+
console.log(JSON.stringify(mapRef.current.style._order));
|
|
30
34
|
if (mapRef.current) {
|
|
31
35
|
mapRef.current.cleanup(_componentId);
|
|
32
36
|
mapRef.current = undefined;
|