@mapcomponents/react-maplibre 0.1.21 → 0.1.25
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/coverage/clover.xml +113 -135
- package/coverage/coverage-final.json +4 -4
- package/coverage/lcov-report/index.html +33 -33
- 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 +30 -93
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +18 -18
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
- 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 +88 -154
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +17 -17
- 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 +1 -1
- 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 +12 -12
- package/coverage/lcov-report/src/hooks/useMap.js.html +29 -41
- 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 +191 -233
- package/dist/index.esm.js +53 -104
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/MlFollowGps/MlFollowGps.js +18 -39
- package/src/components/MlFollowGps/MlFollowGps.test.js +1 -1
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +64 -86
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.test.js +6 -6
- package/src/hooks/useMap.js +1 -5
package/package.json
CHANGED
|
@@ -24,20 +24,10 @@ const MlFollowGps = (props) => {
|
|
|
24
24
|
|
|
25
25
|
const [isFollowed, setIsFollowed] = useState(false);
|
|
26
26
|
const [geoJson, setGeoJson] = useState(undefined);
|
|
27
|
-
const watchIdRef = useRef(undefined);
|
|
28
27
|
const [locationAccessDenied, setLocationAccessDenied] = useState(false);
|
|
29
28
|
|
|
30
29
|
const [accuracyGeoJson, setAccuracyGeoJson] = useState();
|
|
31
30
|
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
return () => {
|
|
34
|
-
if (watchIdRef.current) {
|
|
35
|
-
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
36
|
-
watchIdRef.current = undefined;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
31
|
const getLocationSuccess = useCallback(
|
|
42
32
|
(pos) => {
|
|
43
33
|
if (!mapHook.map) return;
|
|
@@ -59,12 +49,11 @@ const MlFollowGps = (props) => {
|
|
|
59
49
|
if (!mapHook.map) return;
|
|
60
50
|
|
|
61
51
|
if (isFollowed) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
52
|
+
let _watchId = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
navigator.geolocation.clearWatch(_watchId);
|
|
56
|
+
};
|
|
68
57
|
}
|
|
69
58
|
}, [isFollowed, getLocationSuccess]);
|
|
70
59
|
|
|
@@ -79,26 +68,20 @@ const MlFollowGps = (props) => {
|
|
|
79
68
|
"fill-opacity": 0.5,
|
|
80
69
|
...props.accuracyPaint,
|
|
81
70
|
}}
|
|
82
|
-
insertBeforeLayer={
|
|
71
|
+
insertBeforeLayer={props.insertBeforeLayer}
|
|
83
72
|
/>
|
|
84
73
|
)}
|
|
85
74
|
|
|
86
75
|
{isFollowed && geoJson && (
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
layout: {
|
|
96
|
-
"icon-size": 0.1,
|
|
97
|
-
"icon-offset": [0, -340],
|
|
98
|
-
...props.markerLayout,
|
|
99
|
-
},
|
|
76
|
+
<MlGeoJsonLayer
|
|
77
|
+
geojson={geoJson}
|
|
78
|
+
type={"circle"}
|
|
79
|
+
paint={{
|
|
80
|
+
"circle-color": "#ee9900",
|
|
81
|
+
"circle-radius": 5,
|
|
82
|
+
...props.circlePaint,
|
|
100
83
|
}}
|
|
101
|
-
|
|
84
|
+
insertBeforeLayer={props.insertBeforeLayer}
|
|
102
85
|
/>
|
|
103
86
|
)}
|
|
104
87
|
|
|
@@ -160,14 +143,10 @@ MlFollowGps.propTypes = {
|
|
|
160
143
|
*/
|
|
161
144
|
accuracyPaint: PropTypes.object,
|
|
162
145
|
/**
|
|
163
|
-
*
|
|
164
|
-
* Use any available
|
|
165
|
-
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#
|
|
166
|
-
*/
|
|
167
|
-
markerLayout: PropTypes.object,
|
|
168
|
-
/**
|
|
169
|
-
* Replace the default marker image with a custom one.
|
|
146
|
+
* position circle paint property object, that is passed to the MlGeoJsonLayer responsible for drawing the accuracy circle.
|
|
147
|
+
* Use any available paint prop from layer type "fill".
|
|
148
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
170
149
|
*/
|
|
171
|
-
|
|
150
|
+
circlePaint: PropTypes.object,
|
|
172
151
|
};
|
|
173
152
|
export default MlFollowGps;
|
|
@@ -58,6 +58,6 @@ describe("<MlFollowGps>", () => {
|
|
|
58
58
|
wrapper.find("MlFollowGps button").simulate("click");
|
|
59
59
|
//wrapper.find(".toggle_layer_visible").simulate("click");
|
|
60
60
|
|
|
61
|
-
await waitFor(() => expect(mockGeolocation.clearWatch).toHaveBeenCalledTimes(
|
|
61
|
+
await waitFor(() => expect(mockGeolocation.clearWatch).toHaveBeenCalledTimes(1));
|
|
62
62
|
});
|
|
63
63
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
|
+
import useMap from "../../hooks/useMap";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -9,112 +9,94 @@ import PropTypes from "prop-types";
|
|
|
9
9
|
* @component
|
|
10
10
|
*/
|
|
11
11
|
const MlVectorTileLayer = (props) => {
|
|
12
|
-
const
|
|
12
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
13
13
|
|
|
14
|
-
const layerName = "vector-tile-layer-";
|
|
15
|
-
const sourceName = "vector-tile-source-";
|
|
16
|
-
const idSuffixRef = useRef(new Date().getTime());
|
|
17
14
|
const layerIdsRef = useRef({});
|
|
15
|
+
const layerId = useRef(props.layerId || "MlVectorTileLayer-" + mapHook.componentId);
|
|
18
16
|
const layerPaintConfsRef = useRef({});
|
|
17
|
+
const layerLayoutConfsRef = useRef({});
|
|
19
18
|
const initializedRef = useRef(false);
|
|
20
|
-
const mapRef = useRef(null);
|
|
21
|
-
|
|
22
|
-
const cleanup = () => {
|
|
23
|
-
if (mapRef.current && mapRef.current.style) {
|
|
24
|
-
for (let key in layerIdsRef.current) {
|
|
25
|
-
if (mapRef.current.getLayer(layerIdsRef.current[key])) {
|
|
26
|
-
mapRef.current.removeLayer(layerIdsRef.current[key]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (mapRef.current.getSource(sourceName + idSuffixRef.current)) {
|
|
30
|
-
mapRef.current.removeSource(sourceName + idSuffixRef.current);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
19
|
|
|
35
20
|
useEffect(() => {
|
|
36
|
-
return
|
|
37
|
-
}, []);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
|
|
21
|
+
if (!mapHook.map || initializedRef.current) return;
|
|
41
22
|
|
|
42
23
|
initializedRef.current = true;
|
|
43
|
-
mapRef.current = mapContext.getMap(props.mapId);
|
|
44
24
|
|
|
45
25
|
// Add the new layer to the openlayers instance once it is available
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
mapHook.map.addSource(
|
|
27
|
+
layerId.current,
|
|
28
|
+
{
|
|
29
|
+
type: "vector",
|
|
30
|
+
tiles: [props.url],
|
|
31
|
+
tileSize: 512,
|
|
32
|
+
attribution: "",
|
|
33
|
+
...props.sourceOptions,
|
|
34
|
+
},
|
|
35
|
+
mapHook.componentId
|
|
36
|
+
);
|
|
53
37
|
|
|
54
38
|
for (let key in props.layers) {
|
|
55
|
-
let
|
|
56
|
-
layerIdsRef.current[key] =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
39
|
+
let _layerId = layerId.current + "_" + key;
|
|
40
|
+
layerIdsRef.current[key] = _layerId;
|
|
41
|
+
|
|
42
|
+
mapHook.map.addLayer(
|
|
43
|
+
{
|
|
44
|
+
id: _layerId,
|
|
45
|
+
source: layerId.current,
|
|
46
|
+
type: "line",
|
|
47
|
+
minzoom: 0,
|
|
48
|
+
maxzoom: 22,
|
|
49
|
+
layout: {},
|
|
50
|
+
paint: {
|
|
51
|
+
"line-opacity": 0.5,
|
|
52
|
+
"line-color": "rgb(80, 80, 80)",
|
|
53
|
+
"line-width": 2,
|
|
54
|
+
},
|
|
55
|
+
...props.layers[key],
|
|
69
56
|
},
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
props.insertBeforeLayer,
|
|
58
|
+
mapHook.componentId
|
|
59
|
+
);
|
|
72
60
|
layerPaintConfsRef.current[key] = JSON.stringify(props.layers[key].paint);
|
|
61
|
+
layerLayoutConfsRef.current[key] = JSON.stringify(props.layers[key].layout);
|
|
73
62
|
}
|
|
74
|
-
}, [
|
|
63
|
+
}, [mapHook.map, props]);
|
|
75
64
|
|
|
76
65
|
useEffect(() => {
|
|
77
|
-
if (!
|
|
78
|
-
// the MapLibre-gl instance (mapContext.map) is accessible here
|
|
66
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
79
67
|
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
80
68
|
for (var key in props.layers) {
|
|
81
|
-
if (
|
|
82
|
-
|
|
69
|
+
if (mapHook.map.getLayer(layerIdsRef.current[key])) {
|
|
70
|
+
// update changed paint property
|
|
71
|
+
let layerPaintConfString = JSON.stringify(props.layers[key].paint);
|
|
83
72
|
|
|
84
|
-
if (
|
|
73
|
+
if (layerPaintConfString !== layerPaintConfsRef.current[key]) {
|
|
85
74
|
for (let paintKey in props.layers[key].paint) {
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
props.layers[key].paint[paintKey]
|
|
92
|
-
);
|
|
75
|
+
mapHook.map.setPaintProperty(
|
|
76
|
+
layerIdsRef.current[key],
|
|
77
|
+
paintKey,
|
|
78
|
+
props.layers[key].paint[paintKey]
|
|
79
|
+
);
|
|
93
80
|
}
|
|
94
81
|
}
|
|
95
|
-
layerPaintConfsRef.current[key] =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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");
|
|
82
|
+
layerPaintConfsRef.current[key] = layerPaintConfString;
|
|
83
|
+
|
|
84
|
+
// update changed layout property
|
|
85
|
+
let layerLayoutConfString = JSON.stringify(props.layers[key].layout);
|
|
86
|
+
|
|
87
|
+
if (layerLayoutConfString !== layerLayoutConfsRef.current[key]) {
|
|
88
|
+
for (let layoutKey in props.layers[key].layout) {
|
|
89
|
+
mapHook.map.setLayoutProperty(
|
|
90
|
+
layerIdsRef.current[key],
|
|
91
|
+
layoutKey,
|
|
92
|
+
props.layers[key].layout[layoutKey]
|
|
93
|
+
);
|
|
94
|
+
}
|
|
114
95
|
}
|
|
96
|
+
layerLayoutConfsRef.current[key] = layerLayoutConfString;
|
|
115
97
|
}
|
|
116
98
|
}
|
|
117
|
-
}, [props.
|
|
99
|
+
}, [props.layers, mapHook.map]);
|
|
118
100
|
|
|
119
101
|
return <></>;
|
|
120
102
|
};
|
|
@@ -132,10 +114,6 @@ MlVectorTileLayer.propTypes = {
|
|
|
132
114
|
* Object that hold layers
|
|
133
115
|
*/
|
|
134
116
|
layers: PropTypes.object,
|
|
135
|
-
/**
|
|
136
|
-
* Boolean value to control the visibility of this layer
|
|
137
|
-
*/
|
|
138
|
-
visible: PropTypes.bool,
|
|
139
117
|
/**
|
|
140
118
|
* String of the URL of a wms layer
|
|
141
119
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { layerRemovalTest, sourceRemovalTest } from "../../util";
|
|
2
2
|
|
|
3
3
|
import MlVectorTileLayer from "./MlVectorTileLayer";
|
|
4
|
+
import { uuid_regex } from "../../setupTests";
|
|
4
5
|
|
|
5
6
|
const testComponent = (
|
|
6
7
|
<MlVectorTileLayer
|
|
7
8
|
{...{
|
|
8
|
-
url:
|
|
9
|
-
"https://wms.wheregroup.com/tileserver/tile/tileserver.php?/europe-0-14/index.json?/europe-0-14/{z}/{x}/{y}.pbf",
|
|
9
|
+
url: "https://wms.wheregroup.com/tileserver/tile/tileserver.php?/europe-0-14/index.json?/europe-0-14/{z}/{x}/{y}.pbf",
|
|
10
10
|
layers: {
|
|
11
11
|
landuseLine: {
|
|
12
12
|
"source-layer": "landuse",
|
|
@@ -28,12 +28,12 @@ const testComponent = (
|
|
|
28
28
|
layerRemovalTest(
|
|
29
29
|
"<MlVectorTileLayer />",
|
|
30
30
|
testComponent,
|
|
31
|
-
|
|
32
|
-
"
|
|
31
|
+
new RegExp('^.*"MlVectorTileLayer-' + uuid_regex + '_landuseLine".*$'),
|
|
32
|
+
"MlVectorTileLayer-{uuid}_landuseLine"
|
|
33
33
|
);
|
|
34
34
|
sourceRemovalTest(
|
|
35
35
|
"<MlVectorTileLayer />",
|
|
36
36
|
testComponent,
|
|
37
|
-
|
|
38
|
-
"
|
|
37
|
+
new RegExp('^.*"MlVectorTileLayer-' + uuid_regex + '".*$'),
|
|
38
|
+
"MlVectorTileLayer-{uuid}"
|
|
39
39
|
);
|
package/src/hooks/useMap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, useState, useEffect, useRef } from "react";
|
|
1
|
+
import React, { useContext, useState, useEffect, useRef } from "react";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import { MapContext } from "@mapcomponents/react-core";
|
|
4
4
|
import useMapState from "./useMapState";
|
|
@@ -25,12 +25,8 @@ function useMap(props) {
|
|
|
25
25
|
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
let _componentId = componentId.current;
|
|
28
|
-
console.log("initialize maphook");
|
|
29
28
|
|
|
30
29
|
return () => {
|
|
31
|
-
console.log("cleanup maphook");
|
|
32
|
-
console.log(typeof mapRef.current);
|
|
33
|
-
console.log(JSON.stringify(mapRef.current.style._order));
|
|
34
30
|
if (mapRef.current) {
|
|
35
31
|
mapRef.current.cleanup(_componentId);
|
|
36
32
|
mapRef.current = undefined;
|