@mapcomponents/react-maplibre 0.1.23 → 0.1.27
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 +54 -8
- package/coverage/clover.xml +90 -96
- package/coverage/coverage-final.json +6 -6
- package/coverage/lcov-report/index.html +25 -25
- 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 +43 -94
- 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 +2 -2
- 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 +7 -10
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +10 -10
- 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 +6 -6
- package/coverage/lcov-report/src/hooks/useMap.js.html +15 -6
- package/coverage/lcov-report/src/hooks/useMapState.js.html +21 -12
- package/coverage/lcov-report/src/hooks/useWms.js.html +2 -2
- 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 +154 -164
- package/dist/index.esm.js +97 -106
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/MlFollowGps/MlFollowGps.js +29 -46
- package/src/components/MlFollowGps/MlFollowGps.test.js +1 -1
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +1 -2
- package/src/hooks/useMap.js +5 -2
- package/src/hooks/useMapState.js +3 -0
- package/src/hooks/useWms.js +1 -1
- package/dist/b556faa3bc6829d2.png +0 -0
- package/src/components/MlFollowGps/assets/marker.png +0 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useEffect, useState, useCallback } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import useMap from "../../hooks/useMap";
|
|
4
4
|
|
|
@@ -6,9 +6,6 @@ import Button from "@mui/material/Button";
|
|
|
6
6
|
import RoomIcon from "@mui/icons-material/Room";
|
|
7
7
|
import { point, circle } from "@turf/turf";
|
|
8
8
|
import MlGeoJsonLayer from "../MlGeoJsonLayer/MlGeoJsonLayer";
|
|
9
|
-
import MlImageMarkerLayer from "../MlImageMarkerLayer/MlImageMarkerLayer";
|
|
10
|
-
|
|
11
|
-
import marker from "./assets/marker.png";
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Adds a button that makes the map follow the users GPS position using
|
|
@@ -24,25 +21,20 @@ const MlFollowGps = (props) => {
|
|
|
24
21
|
|
|
25
22
|
const [isFollowed, setIsFollowed] = useState(false);
|
|
26
23
|
const [geoJson, setGeoJson] = useState(undefined);
|
|
27
|
-
const watchIdRef = useRef(undefined);
|
|
28
24
|
const [locationAccessDenied, setLocationAccessDenied] = useState(false);
|
|
29
25
|
|
|
30
26
|
const [accuracyGeoJson, setAccuracyGeoJson] = useState();
|
|
31
27
|
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
return () => {
|
|
34
|
-
if (watchIdRef.current) {
|
|
35
|
-
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
36
|
-
watchIdRef.current = undefined;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
28
|
const getLocationSuccess = useCallback(
|
|
42
29
|
(pos) => {
|
|
43
30
|
if (!mapHook.map) return;
|
|
44
31
|
|
|
45
|
-
mapHook.map.
|
|
32
|
+
mapHook.map.flyTo({
|
|
33
|
+
center: [pos.coords.longitude, pos.coords.latitude],
|
|
34
|
+
zoom: 18,
|
|
35
|
+
speed: 1,
|
|
36
|
+
curve: 1,
|
|
37
|
+
});
|
|
46
38
|
const geoJsonPoint = point([pos.coords.longitude, pos.coords.latitude]);
|
|
47
39
|
setGeoJson(geoJsonPoint);
|
|
48
40
|
setAccuracyGeoJson(circle(geoJsonPoint, pos.coords.accuracy / 1000));
|
|
@@ -59,12 +51,11 @@ const MlFollowGps = (props) => {
|
|
|
59
51
|
if (!mapHook.map) return;
|
|
60
52
|
|
|
61
53
|
if (isFollowed) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
54
|
+
let _watchId = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
navigator.geolocation.clearWatch(_watchId);
|
|
58
|
+
};
|
|
68
59
|
}
|
|
69
60
|
}, [isFollowed, getLocationSuccess]);
|
|
70
61
|
|
|
@@ -75,30 +66,26 @@ const MlFollowGps = (props) => {
|
|
|
75
66
|
geojson={accuracyGeoJson}
|
|
76
67
|
type={"fill"}
|
|
77
68
|
paint={{
|
|
78
|
-
"fill-color": "#
|
|
79
|
-
"fill-opacity": 0.
|
|
69
|
+
"fill-color": "#cbd300",
|
|
70
|
+
"fill-opacity": 0.3,
|
|
80
71
|
...props.accuracyPaint,
|
|
81
72
|
}}
|
|
82
|
-
insertBeforeLayer={
|
|
73
|
+
insertBeforeLayer={props.insertBeforeLayer}
|
|
83
74
|
/>
|
|
84
75
|
)}
|
|
85
76
|
|
|
86
77
|
{isFollowed && geoJson && (
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"icon-size": 0.1,
|
|
97
|
-
"icon-offset": [0, -340],
|
|
98
|
-
...props.markerLayout,
|
|
99
|
-
},
|
|
78
|
+
<MlGeoJsonLayer
|
|
79
|
+
geojson={geoJson}
|
|
80
|
+
type={"circle"}
|
|
81
|
+
paint={{
|
|
82
|
+
"circle-color": "#009ee0",
|
|
83
|
+
"circle-radius": 5,
|
|
84
|
+
"circle-stroke-color": "#fafaff",
|
|
85
|
+
"circle-stroke-width": 1,
|
|
86
|
+
...props.circlePaint,
|
|
100
87
|
}}
|
|
101
|
-
|
|
88
|
+
insertBeforeLayer={props.insertBeforeLayer}
|
|
102
89
|
/>
|
|
103
90
|
)}
|
|
104
91
|
|
|
@@ -160,14 +147,10 @@ MlFollowGps.propTypes = {
|
|
|
160
147
|
*/
|
|
161
148
|
accuracyPaint: PropTypes.object,
|
|
162
149
|
/**
|
|
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.
|
|
150
|
+
* position circle paint property object, that is passed to the MlGeoJsonLayer responsible for drawing the accuracy circle.
|
|
151
|
+
* Use any available paint prop from layer type "fill".
|
|
152
|
+
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
170
153
|
*/
|
|
171
|
-
|
|
154
|
+
circlePaint: PropTypes.object,
|
|
172
155
|
};
|
|
173
156
|
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
|
});
|
|
@@ -24,7 +24,7 @@ const MlVectorTileLayer = (props) => {
|
|
|
24
24
|
|
|
25
25
|
// Add the new layer to the openlayers instance once it is available
|
|
26
26
|
mapHook.map.addSource(
|
|
27
|
-
layerId,
|
|
27
|
+
layerId.current,
|
|
28
28
|
{
|
|
29
29
|
type: "vector",
|
|
30
30
|
tiles: [props.url],
|
|
@@ -39,7 +39,6 @@ const MlVectorTileLayer = (props) => {
|
|
|
39
39
|
let _layerId = layerId.current + "_" + key;
|
|
40
40
|
layerIdsRef.current[key] = _layerId;
|
|
41
41
|
|
|
42
|
-
console.log(_layerId);
|
|
43
42
|
mapHook.map.addLayer(
|
|
44
43
|
{
|
|
45
44
|
id: _layerId,
|
package/src/hooks/useMap.js
CHANGED
|
@@ -11,9 +11,12 @@ function useMap(props) {
|
|
|
11
11
|
mapId: props.mapId,
|
|
12
12
|
watch: {
|
|
13
13
|
viewport: false,
|
|
14
|
-
layers: true,
|
|
14
|
+
layers: props.waitForLayer ? true : false,
|
|
15
15
|
sources: false,
|
|
16
16
|
},
|
|
17
|
+
filter: {
|
|
18
|
+
includeBaseLayers: true,
|
|
19
|
+
},
|
|
17
20
|
});
|
|
18
21
|
|
|
19
22
|
const initializedRef = useRef(false);
|
|
@@ -21,7 +24,7 @@ function useMap(props) {
|
|
|
21
24
|
|
|
22
25
|
const componentId = useRef(uuidv4());
|
|
23
26
|
|
|
24
|
-
const [mapIsReady, setMapIsReady] = useState(
|
|
27
|
+
const [mapIsReady, setMapIsReady] = useState(false);
|
|
25
28
|
|
|
26
29
|
useEffect(() => {
|
|
27
30
|
let _componentId = componentId.current;
|
package/src/hooks/useMapState.js
CHANGED
|
@@ -61,6 +61,7 @@ function useMapState(props) {
|
|
|
61
61
|
let _componentId = componentId.current;
|
|
62
62
|
|
|
63
63
|
return () => {
|
|
64
|
+
// cleanup all event listeners
|
|
64
65
|
if (mapRef.current) {
|
|
65
66
|
mapRef.current.cleanup(_componentId);
|
|
66
67
|
mapRef.current = undefined;
|
|
@@ -79,6 +80,7 @@ function useMapState(props) {
|
|
|
79
80
|
if (props?.watch?.viewport) {
|
|
80
81
|
setViewport(mapRef.current.wrapper.viewportState);
|
|
81
82
|
|
|
83
|
+
// register viewportchange event handler
|
|
82
84
|
mapRef.current.wrapper.on(
|
|
83
85
|
"viewportchange",
|
|
84
86
|
() => {
|
|
@@ -90,6 +92,7 @@ function useMapState(props) {
|
|
|
90
92
|
);
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
// register layerchange event handler
|
|
93
96
|
if (props?.watch?.layers) {
|
|
94
97
|
refreshLayerState();
|
|
95
98
|
|
package/src/hooks/useWms.js
CHANGED
|
@@ -63,7 +63,7 @@ function useWms(props) {
|
|
|
63
63
|
useEffect(() => {
|
|
64
64
|
if (!capabilities?.Service) return;
|
|
65
65
|
|
|
66
|
-
setWmsUrl(capabilities.
|
|
66
|
+
setWmsUrl(capabilities.Capability?.Request?.GetMap?.DCPType?.[0]?.HTTP?.Get?.OnlineResource);
|
|
67
67
|
// set getFeatureInfo url
|
|
68
68
|
setGetFeatureInfoUrl(
|
|
69
69
|
capabilities.Capability?.Request?.GetFeatureInfo?.DCPType?.[0]?.HTTP?.Get?.OnlineResource
|
|
Binary file
|
|
Binary file
|