@mapcomponents/react-maplibre 0.1.24 → 0.1.28
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 +72 -7
- package/coverage/clover.xml +461 -489
- 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 -77
- 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 +1 -1
- 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 +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 +826 -882
- package/dist/index.esm.js +288 -517
- package/dist/index.esm.js.map +1 -1
- package/jsdoc.json +3 -3
- package/package.json +9 -9
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.js +5 -1
- 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 +99 -54
- package/src/components/MlFollowGps/MlFollowGps.test.js +1 -1
- 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/hooks/useWms.js +1 -1
- package/dist/b556faa3bc6829d2.png +0 -0
- package/src/components/MlFollowGps/assets/marker.png +0 -0
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import MlOsmLayer from "./MlOsmLayer";
|
|
4
4
|
import TopToolbar from "../../ui_components/TopToolbar";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
5
6
|
|
|
6
7
|
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
7
8
|
|
|
@@ -19,11 +20,22 @@ const storyoptions = {
|
|
|
19
20
|
};
|
|
20
21
|
export default storyoptions;
|
|
21
22
|
|
|
22
|
-
const Template = (props) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const Template = (props) => {
|
|
24
|
+
const [showLayer, setShowLayer] = useState(true);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<TopToolbar>
|
|
28
|
+
<Button
|
|
29
|
+
color="primary"
|
|
30
|
+
variant={showLayer ? "contained" : "outlined"}
|
|
31
|
+
onClick={() => setShowLayer(!showLayer)}
|
|
32
|
+
>
|
|
33
|
+
OSM
|
|
34
|
+
</Button>
|
|
35
|
+
{showLayer && <MlOsmLayer {...props} />}
|
|
36
|
+
</TopToolbar>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
27
39
|
|
|
28
40
|
// <MapLibreMap options={args.options} />
|
|
29
41
|
export const ExampleConfig = Template.bind({});
|
|
@@ -31,8 +43,7 @@ ExampleConfig.args = {
|
|
|
31
43
|
sourceOptions: {
|
|
32
44
|
tiles: ["https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg"],
|
|
33
45
|
attribution:
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
'Map tiles by <a target="_top" rel="noopener" href="http://stamen.com">Stamen Design</a>, under <a target="_top" rel="noopener" href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a target="_top" rel="noopener" href="http://openstreetmap.org">OpenStreetMap</a>, under <a target="_top" rel="noopener" href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>',
|
|
36
47
|
},
|
|
37
|
-
layerOptions: {}
|
|
38
|
-
};
|
|
48
|
+
layerOptions: {},
|
|
49
|
+
};
|
|
@@ -8,12 +8,12 @@ const testComponent = <MlOsmLayer />;
|
|
|
8
8
|
layerRemovalTest(
|
|
9
9
|
"<MlOsmLayer />",
|
|
10
10
|
testComponent,
|
|
11
|
-
new RegExp('^.*"MlOsmLayer-
|
|
12
|
-
"MlOsmLayer-
|
|
11
|
+
new RegExp('^.*"MlOsmLayer-' + uuid_regex + '".*$'),
|
|
12
|
+
"MlOsmLayer-{uuid}"
|
|
13
13
|
);
|
|
14
14
|
sourceRemovalTest(
|
|
15
15
|
"<MlOsmLayer />",
|
|
16
16
|
testComponent,
|
|
17
|
-
new RegExp('^.*"MlOsmLayer-
|
|
18
|
-
"MlOsmLayer-
|
|
17
|
+
new RegExp('^.*"MlOsmLayer-' + uuid_regex + '".*$'),
|
|
18
|
+
"MlOsmLayer-{uuid}"
|
|
19
19
|
);
|
|
@@ -1,63 +1,29 @@
|
|
|
1
|
-
import React, { useRef, useEffect, useState,
|
|
2
|
-
|
|
3
|
-
import { MapContext } from "@mapcomponents/react-core";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
1
|
+
import React, { useRef, useEffect, useState, useCallback } from "react";
|
|
2
|
+
import useMap from "../../hooks/useMap";
|
|
5
3
|
|
|
6
4
|
const MlScaleReference = (props) => {
|
|
7
|
-
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
8
|
-
const mapContext = useContext(MapContext);
|
|
9
|
-
const mapRef = useRef(undefined);
|
|
10
|
-
const initializedRef = useRef(false);
|
|
11
5
|
const zoomRef = useRef(0);
|
|
12
|
-
|
|
13
|
-
const componentId = useRef(
|
|
14
|
-
(props.idPrefix ? props.idPrefix : "MlScaleReference-") + uuidv4()
|
|
15
|
-
);
|
|
6
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
16
7
|
|
|
17
8
|
const [pxWidth, setPxWidth] = useState(0);
|
|
18
9
|
const [text, setText] = useState("");
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return () => {
|
|
24
|
-
// This is the cleanup function, it is called when this react component is removed from react-dom
|
|
25
|
-
// try to remove anything this component has added to the MapLibre-gl instance
|
|
26
|
-
// e.g.: remove the layer
|
|
27
|
-
// mapContext.getMap(props.mapId).removeLayer(layerRef.current);
|
|
28
|
-
// check for the existence of map.style before calling getLayer or getSource
|
|
29
|
-
if (mapRef.current) {
|
|
30
|
-
mapRef.current.cleanup(_componentId);
|
|
31
|
-
mapRef.current = undefined;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
|
|
38
|
-
// the MapLibre-gl instance (mapContext.map) is accessible here
|
|
39
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
40
|
-
initializedRef.current = true;
|
|
41
|
-
mapRef.current = mapContext.getMap(props.mapId);
|
|
42
|
-
mapRef.current.on("move", updateScale.current, componentId.current);
|
|
43
|
-
updateScale.current();
|
|
44
|
-
}, [mapContext.mapIds, mapContext, props.mapId]);
|
|
45
|
-
|
|
46
|
-
const updateScale = useRef(() => {
|
|
47
|
-
if (mapRef.current.map.getZoom() === zoomRef.current) {
|
|
11
|
+
const updateScale = useCallback(() => {
|
|
12
|
+
if (mapHook.map?.map.getZoom() === zoomRef.current) {
|
|
48
13
|
return;
|
|
49
14
|
}
|
|
15
|
+
if (!mapHook.map) return;
|
|
50
16
|
|
|
51
|
-
zoomRef.current =
|
|
17
|
+
zoomRef.current = mapHook.map?.map.getZoom();
|
|
52
18
|
// Calculation from MapLibre
|
|
53
19
|
// A horizontal scale is imagined to be present at center of the map
|
|
54
20
|
// Using spherical law of cosines approximation, the real distance is
|
|
55
21
|
// found between the two coordinates.
|
|
56
22
|
const maxWidth = props.maxWidth || 100;
|
|
57
23
|
|
|
58
|
-
const y =
|
|
59
|
-
const left =
|
|
60
|
-
const right =
|
|
24
|
+
const y = mapHook.map._container.clientHeight / 2;
|
|
25
|
+
const left = mapHook.map.unproject([0, y]);
|
|
26
|
+
const right = mapHook.map.unproject([maxWidth, y]);
|
|
61
27
|
const maxMeters = left.distanceTo(right);
|
|
62
28
|
// The real distance corresponding to 100px scale length is rounded off to
|
|
63
29
|
// near pretty number and the scale length for the same is found out.
|
|
@@ -66,39 +32,31 @@ const MlScaleReference = (props) => {
|
|
|
66
32
|
const maxFeet = 3.2808 * maxMeters;
|
|
67
33
|
if (maxFeet > 5280) {
|
|
68
34
|
const maxMiles = maxFeet / 5280;
|
|
69
|
-
setScale(
|
|
70
|
-
maxWidth,
|
|
71
|
-
maxMiles,
|
|
72
|
-
mapRef.current._getUIString("ScaleControl.Miles")
|
|
73
|
-
);
|
|
35
|
+
setScale(maxWidth, maxMiles, mapHook.map._getUIString("ScaleControl.Miles"));
|
|
74
36
|
} else {
|
|
75
|
-
setScale(
|
|
76
|
-
maxWidth,
|
|
77
|
-
maxFeet,
|
|
78
|
-
mapRef.current._getUIString("ScaleControl.Feet")
|
|
79
|
-
);
|
|
37
|
+
setScale(maxWidth, maxFeet, mapHook.map._getUIString("ScaleControl.Feet"));
|
|
80
38
|
}
|
|
81
39
|
} else if (props.unit === "nautical") {
|
|
82
40
|
const maxNauticals = maxMeters / 1852;
|
|
83
|
-
setScale(
|
|
84
|
-
maxWidth,
|
|
85
|
-
maxNauticals,
|
|
86
|
-
mapRef.current._getUIString("ScaleControl.NauticalMiles")
|
|
87
|
-
);
|
|
41
|
+
setScale(maxWidth, maxNauticals, mapHook.map._getUIString("ScaleControl.NauticalMiles"));
|
|
88
42
|
} else if (maxMeters >= 1000) {
|
|
89
|
-
setScale(
|
|
90
|
-
maxWidth,
|
|
91
|
-
maxMeters / 1000,
|
|
92
|
-
mapRef.current._getUIString("ScaleControl.Kilometers")
|
|
93
|
-
);
|
|
43
|
+
setScale(maxWidth, maxMeters / 1000, mapHook.map._getUIString("ScaleControl.Kilometers"));
|
|
94
44
|
} else {
|
|
95
|
-
setScale(
|
|
96
|
-
maxWidth,
|
|
97
|
-
maxMeters,
|
|
98
|
-
mapRef.current._getUIString("ScaleControl.Meters")
|
|
99
|
-
);
|
|
45
|
+
setScale(maxWidth, maxMeters, mapHook.map._getUIString("ScaleControl.Meters"));
|
|
100
46
|
}
|
|
101
|
-
});
|
|
47
|
+
}, [mapHook.map, props.unit, props.maxWidth]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!mapHook.map) return;
|
|
51
|
+
|
|
52
|
+
let _updateScale = updateScale;
|
|
53
|
+
mapHook.map.on("move", _updateScale, mapHook.componentId);
|
|
54
|
+
updateScale();
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
mapHook.map.off("move", _updateScale);
|
|
58
|
+
};
|
|
59
|
+
}, [mapHook.map, updateScale]);
|
|
102
60
|
|
|
103
61
|
const setScale = (maxWidth, maxDistance, unit) => {
|
|
104
62
|
const distance = getRoundNum(maxDistance);
|
|
@@ -116,18 +74,7 @@ const MlScaleReference = (props) => {
|
|
|
116
74
|
const pow10 = Math.pow(10, `${Math.floor(num)}`.length - 1);
|
|
117
75
|
let d = num / pow10;
|
|
118
76
|
|
|
119
|
-
d =
|
|
120
|
-
d >= 10
|
|
121
|
-
? 10
|
|
122
|
-
: d >= 5
|
|
123
|
-
? 5
|
|
124
|
-
: d >= 3
|
|
125
|
-
? 3
|
|
126
|
-
: d >= 2
|
|
127
|
-
? 2
|
|
128
|
-
: d >= 1
|
|
129
|
-
? 1
|
|
130
|
-
: getDecimalRoundNum(d);
|
|
77
|
+
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : d >= 1 ? 1 : getDecimalRoundNum(d);
|
|
131
78
|
|
|
132
79
|
return pow10 * d;
|
|
133
80
|
};
|
|
@@ -79,9 +79,7 @@ const Template = () => {
|
|
|
79
79
|
"visibility",
|
|
80
80
|
currentVisibility === "none" ? "visible" : "none"
|
|
81
81
|
);
|
|
82
|
-
|
|
83
|
-
mapHook.map._render();
|
|
84
|
-
}, 100);
|
|
82
|
+
mapHook.map.map.fire("zoom");
|
|
85
83
|
}}
|
|
86
84
|
>
|
|
87
85
|
{el.visible ? <VisibilityIcon /> : <VisibilityOffIcon />}
|