@mapcomponents/react-maplibre 0.1.51 → 0.1.52
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 +50 -30
- package/coverage/coverage-final.json +2 -1
- package/coverage/lcov-report/index.html +32 -17
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +343 -0
- package/coverage/lcov-report/src/components/MlCenterPosition/index.html +116 -0
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.tsx.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.tsx.html +2 -2
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.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.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
- package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlMeasureTool/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +106 -34
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +15 -15
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.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/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +2 -2
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/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.tsx.html +1 -1
- 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.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
- package/coverage/lcov-report/src/contexts/MapContext.tsx.html +1 -1
- package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +1 -1
- package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +1 -1
- package/coverage/lcov-report/src/contexts/index.html +1 -1
- package/coverage/lcov-report/src/hooks/index.html +1 -1
- package/coverage/lcov-report/src/hooks/useLayer.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useMap.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useMapState.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov.info +115 -74
- package/dist/components/MlCenterPosition/MlCenterPosition.d.ts +50 -0
- package/dist/components/MlCenterPosition/MlCenterPosition.stories.d.ts +17 -0
- package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.d.ts +1 -1
- package/dist/components/MlNavigationTools/MlNavigationTools.d.ts +25 -3
- package/dist/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.d.ts +1 -1
- package/dist/index.esm.js +67 -11
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/create-map-component.sh +2 -2
- package/src/components/MlCenterPosition/MlCenterPosition.doc.de.md +3 -0
- package/src/components/MlCenterPosition/MlCenterPosition.meta_.json +15 -0
- package/src/components/MlCenterPosition/MlCenterPosition.stories.js +21 -0
- package/src/components/MlCenterPosition/MlCenterPosition.tsx +86 -0
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +1 -1
- package/src/components/MlNavigationTools/MlNavigationTools.stories.js +3 -2
- package/src/components/MlNavigationTools/MlNavigationTools.tsx +44 -20
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx +1 -1
package/package.json
CHANGED
|
@@ -18,14 +18,14 @@ if [ ! -d "$target_path$component_name" ]; then
|
|
|
18
18
|
|
|
19
19
|
mv $target_path$component_name/$template_name.doc.de.md $target_path$component_name/$component_name.doc.de.md
|
|
20
20
|
|
|
21
|
-
mv $target_path$component_name/$template_name.
|
|
21
|
+
mv $target_path$component_name/$template_name.tsx $target_path$component_name/$component_name.tsx
|
|
22
22
|
|
|
23
23
|
mv $target_path$component_name/$template_name.meta_.json $target_path$component_name/$component_name.meta_.json
|
|
24
24
|
|
|
25
25
|
mv $target_path$component_name/$template_name.stories.js $target_path$component_name/$component_name.stories.js
|
|
26
26
|
|
|
27
27
|
sed -i "s/$template_name/$component_name/g" $target_path$component_name/$component_name.doc.de.md
|
|
28
|
-
sed -i "s/$template_name/$component_name/g" $target_path$component_name/$component_name.
|
|
28
|
+
sed -i "s/$template_name/$component_name/g" $target_path$component_name/$component_name.tsx
|
|
29
29
|
sed -i "s/$template_name/$component_name/g" $target_path$component_name/$component_name.meta_.json
|
|
30
30
|
sed -i "s/$template_name/$component_name/g" $target_path$component_name/$component_name.stories.js
|
|
31
31
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import MlCenterPosition from "./MlCenterPosition";
|
|
4
|
+
|
|
5
|
+
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
6
|
+
|
|
7
|
+
const storyoptions = {
|
|
8
|
+
title: "MapComponents/MlCenterPosition",
|
|
9
|
+
component: MlCenterPosition,
|
|
10
|
+
argTypes: {
|
|
11
|
+
},
|
|
12
|
+
decorators: mapContextDecorator,
|
|
13
|
+
parameters: { docs: { source: { type: 'code' } } }
|
|
14
|
+
};
|
|
15
|
+
export default storyoptions;
|
|
16
|
+
|
|
17
|
+
const Template = (args) => <MlCenterPosition />;
|
|
18
|
+
|
|
19
|
+
export const ExampleConfig = Template.bind({});
|
|
20
|
+
ExampleConfig.parameters = {};
|
|
21
|
+
ExampleConfig.args = {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { useState, useCallback } from "react";
|
|
2
|
+
import useMap from "../../hooks/useMap";
|
|
3
|
+
import { Button } from "@mui/material";
|
|
4
|
+
import GpsFixedIcon from "@mui/icons-material/GpsFixed";
|
|
5
|
+
|
|
6
|
+
interface MlCenterPositionProps {
|
|
7
|
+
/**
|
|
8
|
+
* Id of the target MapLibre instance in mapContext
|
|
9
|
+
*/
|
|
10
|
+
mapId?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
13
|
+
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
14
|
+
*/
|
|
15
|
+
insertBeforeLayer?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Active button font color
|
|
18
|
+
*/
|
|
19
|
+
onColor?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Inactive button font color
|
|
22
|
+
*/
|
|
23
|
+
offColor?: string;
|
|
24
|
+
/**
|
|
25
|
+
* CSS style object that is applied to the button component
|
|
26
|
+
*/
|
|
27
|
+
style?: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Component template
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
const MlCenterPosition = (props: MlCenterPositionProps) => {
|
|
35
|
+
const mapHook = useMap({
|
|
36
|
+
mapId: props.mapId,
|
|
37
|
+
waitForLayer: props.insertBeforeLayer,
|
|
38
|
+
});
|
|
39
|
+
const [locationAccessDenied, setLocationAccessDenied] = useState(false);
|
|
40
|
+
|
|
41
|
+
const centerCurrentLocation = () => {
|
|
42
|
+
navigator.geolocation.getCurrentPosition(getLocationSuccess, getLocationError);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getLocationSuccess = useCallback((location) => {
|
|
46
|
+
mapHook.map?.map.setCenter?.([location.coords.longitude, location.coords.latitude]);
|
|
47
|
+
}, [mapHook.map]);
|
|
48
|
+
|
|
49
|
+
const getLocationError = () => {
|
|
50
|
+
console.log("Access of user location denied");
|
|
51
|
+
setLocationAccessDenied(true);
|
|
52
|
+
};
|
|
53
|
+
return <>
|
|
54
|
+
<Button
|
|
55
|
+
sx={{
|
|
56
|
+
zIndex: 1002,
|
|
57
|
+
color: !locationAccessDenied ? props.onColor : props.offColor,
|
|
58
|
+
...props.style,
|
|
59
|
+
}}
|
|
60
|
+
onClick={centerCurrentLocation} disabled={locationAccessDenied}>
|
|
61
|
+
<GpsFixedIcon sx={{ ...(props.style?.fontSize?{fontSize: props.style?.fontSize}:{}) }} />{" "}
|
|
62
|
+
</Button>
|
|
63
|
+
</>;
|
|
64
|
+
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
MlCenterPosition.defaultProps = {
|
|
68
|
+
mapId: undefined,
|
|
69
|
+
style: {
|
|
70
|
+
minWidth: "30px",
|
|
71
|
+
minHeight: "30px",
|
|
72
|
+
width: "30px",
|
|
73
|
+
height: "30px",
|
|
74
|
+
backgroundColor: "#414141",
|
|
75
|
+
borderRadius: "23%",
|
|
76
|
+
margin: 0.15,
|
|
77
|
+
fontSize: "1.3em",
|
|
78
|
+
":hover": {
|
|
79
|
+
backgroundColor: "#515151",
|
|
80
|
+
color: "#ececec",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
onColor: "#ececec",
|
|
84
|
+
offColor: "#666",
|
|
85
|
+
};
|
|
86
|
+
export default MlCenterPosition;
|
|
@@ -43,7 +43,7 @@ type MlGeoJsonLayerProps = {
|
|
|
43
43
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
44
44
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
45
45
|
*/
|
|
46
|
-
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['
|
|
46
|
+
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['paint'];
|
|
47
47
|
/**
|
|
48
48
|
* Layout property object, that is passed to the addLayer call.
|
|
49
49
|
* Possible props depend on the layer type.
|
|
@@ -15,8 +15,9 @@ const storyoptions = {
|
|
|
15
15
|
};
|
|
16
16
|
export default storyoptions;
|
|
17
17
|
|
|
18
|
-
const Template = (args) => <MlNavigationTools />;
|
|
18
|
+
const Template = (args) => <MlNavigationTools {...args} />;
|
|
19
19
|
|
|
20
20
|
export const ExampleConfig = Template.bind({});
|
|
21
21
|
ExampleConfig.parameters = {};
|
|
22
|
-
ExampleConfig.args = {
|
|
22
|
+
ExampleConfig.args = {
|
|
23
|
+
};
|
|
@@ -8,13 +8,29 @@ import MlNavigationCompass from "../MlNavigationCompass/MlNavigationCompass";
|
|
|
8
8
|
import MlFollowGps from "../MlFollowGps/MlFollowGps";
|
|
9
9
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
10
10
|
import useMap from "../../hooks/useMap";
|
|
11
|
+
import MlCenterPosition from "../MlCenterPosition/MlCenterPosition";
|
|
11
12
|
|
|
12
13
|
interface MlNavigationToolsProps {
|
|
14
|
+
/**
|
|
15
|
+
* Id of the target MapLibre instance in mapContext
|
|
16
|
+
*/
|
|
13
17
|
mapId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The layerId of an existing layer this layer should be rendered visually beneath
|
|
20
|
+
* https://maplibre.org/maplibre-gl-js-docs/api/map/#map#addlayer - see "beforeId" property
|
|
21
|
+
*/
|
|
14
22
|
insertBeforeLayer?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Show follow GPS button
|
|
25
|
+
*/
|
|
26
|
+
showFollowGpsButton?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Show center on current position button
|
|
29
|
+
*/
|
|
30
|
+
showCenterLocationButton?: boolean;
|
|
15
31
|
}
|
|
16
32
|
|
|
17
|
-
|
|
33
|
+
/**
|
|
18
34
|
* @component
|
|
19
35
|
*/
|
|
20
36
|
const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
@@ -45,21 +61,22 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
45
61
|
useEffect(() => {
|
|
46
62
|
if (!mapHook.map) return;
|
|
47
63
|
|
|
48
|
-
mapHook.map.on(
|
|
49
|
-
|
|
64
|
+
mapHook.map.on(
|
|
65
|
+
"pitchend",
|
|
66
|
+
() => {
|
|
67
|
+
if (!mapHook.map) return;
|
|
50
68
|
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
setPitch(mapHook.map.map.getPitch());
|
|
70
|
+
},
|
|
71
|
+
mapHook.componentId
|
|
72
|
+
);
|
|
53
73
|
setPitch(mapHook.map.map.getPitch());
|
|
54
74
|
}, [mapHook.map, props.mapId]);
|
|
55
75
|
|
|
56
76
|
const zoomIn = () => {
|
|
57
77
|
if (!mapHook.map) return;
|
|
58
78
|
|
|
59
|
-
if (
|
|
60
|
-
mapHook.map.map.transform._zoom + 0.5 <=
|
|
61
|
-
mapHook.map.map.transform._maxZoom
|
|
62
|
-
) {
|
|
79
|
+
if (mapHook.map.map.transform._zoom + 0.5 <= mapHook.map.map.transform._maxZoom) {
|
|
63
80
|
mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom + 0.5 });
|
|
64
81
|
}
|
|
65
82
|
};
|
|
@@ -67,10 +84,7 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
67
84
|
const zoomOut = () => {
|
|
68
85
|
if (!mapHook.map) return;
|
|
69
86
|
|
|
70
|
-
if (
|
|
71
|
-
mapHook.map.map.transform._zoom - 0.5 >=
|
|
72
|
-
mapHook.map.map.transform._minZoom
|
|
73
|
-
) {
|
|
87
|
+
if (mapHook.map.map.transform._zoom - 0.5 >= mapHook.map.map.transform._minZoom) {
|
|
74
88
|
mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom - 0.5 });
|
|
75
89
|
}
|
|
76
90
|
};
|
|
@@ -108,10 +122,18 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
108
122
|
boxShadow: "0px 0px 18px rgba(0,0,0,.5)",
|
|
109
123
|
}}
|
|
110
124
|
/>
|
|
111
|
-
<Button
|
|
125
|
+
<Button
|
|
126
|
+
sx={{ ...buttonStyle, fontSize: mediaIsMobile ? "1.4em" : "1em", fontWeight: 600 }}
|
|
127
|
+
onClick={adjustPitch}
|
|
128
|
+
>
|
|
112
129
|
{pitch ? "2D" : "3D"}
|
|
113
130
|
</Button>
|
|
131
|
+
{props.showFollowGpsButton &&
|
|
114
132
|
<MlFollowGps style={{ ...(({ color, ...rest }) => rest)(buttonStyle) }} />
|
|
133
|
+
}
|
|
134
|
+
{props.showCenterLocationButton &&
|
|
135
|
+
<MlCenterPosition style={{ ...(({ color, ...rest }) => rest)(buttonStyle) }} />
|
|
136
|
+
}
|
|
115
137
|
<ButtonGroup
|
|
116
138
|
orientation="vertical"
|
|
117
139
|
sx={{
|
|
@@ -122,18 +144,20 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
122
144
|
}}
|
|
123
145
|
>
|
|
124
146
|
<Button sx={{ ...buttonStyle, color: "#ececec" }} onClick={zoomIn}>
|
|
125
|
-
<ControlPointIcon
|
|
126
|
-
sx={{ fontSize: mediaIsMobile ? "1.5em" : "1.2em" }}
|
|
127
|
-
/>
|
|
147
|
+
<ControlPointIcon sx={{ fontSize: mediaIsMobile ? "1.5em" : "1.2em" }} />
|
|
128
148
|
</Button>
|
|
129
149
|
<Button sx={{ ...buttonStyle, color: "#ececec" }} onClick={zoomOut}>
|
|
130
|
-
<RemoveCircleOutlineIcon
|
|
131
|
-
sx={{ fontSize: mediaIsMobile ? "1.5em" : "1.2em" }}
|
|
132
|
-
/>
|
|
150
|
+
<RemoveCircleOutlineIcon sx={{ fontSize: mediaIsMobile ? "1.5em" : "1.2em" }} />
|
|
133
151
|
</Button>
|
|
134
152
|
</ButtonGroup>
|
|
135
153
|
</div>
|
|
136
154
|
);
|
|
137
155
|
};
|
|
138
156
|
|
|
157
|
+
MlNavigationTools.defaultProps = {
|
|
158
|
+
mapId: undefined,
|
|
159
|
+
showFollowGpsButton: true,
|
|
160
|
+
showCenterLocationButton: false,
|
|
161
|
+
};
|
|
162
|
+
|
|
139
163
|
export default MlNavigationTools;
|
|
@@ -32,7 +32,7 @@ interface MlTransitionGeoJsonLayerProps {
|
|
|
32
32
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
33
33
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
34
34
|
*/
|
|
35
|
-
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['
|
|
35
|
+
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['paint'];
|
|
36
36
|
/**
|
|
37
37
|
* Layout property object, that is passed to the addLayer call.
|
|
38
38
|
* Possible props depend on the layer type.
|