@mapcomponents/react-maplibre 0.1.49 → 0.1.53
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 +33 -1
- package/coverage/clover.xml +133 -112
- package/coverage/coverage-final.json +5 -4
- 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 +26 -11
- 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 +195 -42
- 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 +22 -19
- 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 +19 -10
- 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 +301 -257
- package/dist/components/MapLibreMap/lib/MapLibreGlWrapper.d.ts +3 -2
- 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 +15 -8
- package/dist/components/MlNavigationTools/MlNavigationTools.d.ts +39 -3
- package/dist/components/MlNavigationTools/MlNavigationTools.stories.d.ts +8 -3
- package/dist/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.d.ts +22 -17
- package/dist/decorators/NoNavToolsDecorator.d.ts +2 -0
- package/dist/hooks/useLayer.d.ts +7 -5
- package/dist/index.esm.js +78 -15
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/create-map-component.sh +2 -2
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.ts +4 -3
- 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 +14 -9
- package/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.ts +2 -1
- package/src/components/MlNavigationTools/MlNavigationTools.stories.js +43 -6
- package/src/components/MlNavigationTools/MlNavigationTools.tsx +79 -28
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx +18 -17
- package/src/decorators/NoNavToolsDecorator.js +31 -0
- package/src/hooks/useLayer.ts +11 -8
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
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Map, IControl, MapOptions as MapOptionsType
|
|
1
|
+
import { Map, IControl, MapOptions as MapOptionsType, } from "!maplibre-gl";
|
|
2
|
+
import { Map as MapType } from "maplibre-gl";
|
|
2
3
|
|
|
3
4
|
type EventArgArray = [string, string | Function, Function?];
|
|
4
5
|
type LayerState = {
|
|
@@ -53,7 +54,7 @@ class MapLibreGlWrapper {
|
|
|
53
54
|
};
|
|
54
55
|
initRegisteredElements: Function;
|
|
55
56
|
addNativeMaplibreFunctionsAndProps: Function;
|
|
56
|
-
map:
|
|
57
|
+
map: MapType;
|
|
57
58
|
style: object;
|
|
58
59
|
|
|
59
60
|
styleJson: object;
|
|
@@ -603,7 +604,7 @@ class MapLibreGlWrapper {
|
|
|
603
604
|
});
|
|
604
605
|
}
|
|
605
606
|
|
|
606
|
-
self.map = new Map(props.mapOptions);
|
|
607
|
+
self.map = new Map(props.mapOptions) as MapType;
|
|
607
608
|
//@ts-ignore
|
|
608
609
|
window._map = self.map;
|
|
609
610
|
|
|
@@ -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;
|
|
@@ -8,6 +8,9 @@ import getDefaultPaintPropsByType from "./util/getDefaultPaintPropsByType";
|
|
|
8
8
|
import getDefaulLayerTypeByGeometry from "./util/getDefaultLayerTypeByGeometry";
|
|
9
9
|
import { Feature, FeatureCollection } from "@turf/turf";
|
|
10
10
|
|
|
11
|
+
|
|
12
|
+
import { LineLayerSpecification, CircleLayerSpecification, FillLayerSpecification,MapLayerMouseEvent, LayerSpecification } from "maplibre-gl";
|
|
13
|
+
|
|
11
14
|
type MlGeoJsonLayerProps = {
|
|
12
15
|
/**
|
|
13
16
|
* Id of the target MapLibre instance in mapContext
|
|
@@ -16,6 +19,8 @@ type MlGeoJsonLayerProps = {
|
|
|
16
19
|
/**
|
|
17
20
|
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
18
21
|
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
22
|
+
* This layer will not be added to the maplibre-gl instance until a layer with an
|
|
23
|
+
* id that matches the value of insertBeforeLayer is created.
|
|
19
24
|
*/
|
|
20
25
|
insertBeforeLayer?: string;
|
|
21
26
|
/**
|
|
@@ -30,7 +35,7 @@ type MlGeoJsonLayerProps = {
|
|
|
30
35
|
* Type of the layer that will be added to the MapLibre instance.
|
|
31
36
|
* Possible values: "line", "circle", "fill"
|
|
32
37
|
*/
|
|
33
|
-
type?:
|
|
38
|
+
type?: "fill" | "line" | "circle";
|
|
34
39
|
/**
|
|
35
40
|
* Paint property object, that is passed to the addLayer call.
|
|
36
41
|
* Possible props depend on the layer type.
|
|
@@ -38,7 +43,7 @@ type MlGeoJsonLayerProps = {
|
|
|
38
43
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
39
44
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
40
45
|
*/
|
|
41
|
-
paint?:
|
|
46
|
+
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['paint'];
|
|
42
47
|
/**
|
|
43
48
|
* Layout property object, that is passed to the addLayer call.
|
|
44
49
|
* Possible props depend on the layer type.
|
|
@@ -46,28 +51,28 @@ type MlGeoJsonLayerProps = {
|
|
|
46
51
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
47
52
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
48
53
|
*/
|
|
49
|
-
layout?:
|
|
54
|
+
layout?: CircleLayerSpecification['layout'] | FillLayerSpecification['layout'] | LineLayerSpecification['layout'];
|
|
50
55
|
/**
|
|
51
56
|
* Javascript object that is spread into the addLayer commands first parameter.
|
|
52
57
|
*/
|
|
53
|
-
options?:
|
|
58
|
+
options?: CircleLayerSpecification | FillLayerSpecification | LineLayerSpecification;
|
|
54
59
|
/**
|
|
55
60
|
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
56
61
|
*/
|
|
57
|
-
defaultPaintOverrides?:
|
|
62
|
+
defaultPaintOverrides?: { circle?: CircleLayerSpecification['paint'], fill?: FillLayerSpecification['paint'], line?: LineLayerSpecification['paint'] };
|
|
58
63
|
/**
|
|
59
64
|
* Hover event handler that is executed whenever a geometry rendered by this component is hovered.
|
|
60
65
|
*/
|
|
61
|
-
onHover?:
|
|
66
|
+
onHover?: MapLayerMouseEvent;
|
|
62
67
|
/**
|
|
63
68
|
* Click event handler that is executed whenever a geometry rendered by this component is clicked.
|
|
64
69
|
*/
|
|
65
|
-
onClick?:
|
|
70
|
+
onClick?: MapLayerMouseEvent;
|
|
66
71
|
/**
|
|
67
72
|
* Leave event handler that is executed whenever a geometry rendered by this component is
|
|
68
73
|
* left/unhovered.
|
|
69
74
|
*/
|
|
70
|
-
onLeave?:
|
|
75
|
+
onLeave?: MapLayerMouseEvent;
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
/**
|
|
@@ -91,7 +96,7 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => {
|
|
|
91
96
|
),
|
|
92
97
|
layout: props.layout || {},
|
|
93
98
|
...props.options,
|
|
94
|
-
type: layerType,
|
|
99
|
+
type: layerType as LayerSpecification['type'],
|
|
95
100
|
},
|
|
96
101
|
insertBeforeLayer: props.insertBeforeLayer,
|
|
97
102
|
onHover: props.onHover,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Feature, FeatureCollection } from "@turf/turf";
|
|
2
|
+
import { LayerSpecification } from "maplibre-gl";
|
|
2
3
|
|
|
3
4
|
const mapGeometryTypesToLayerTypes = {
|
|
4
5
|
Position: "circle",
|
|
@@ -13,7 +14,7 @@ const mapGeometryTypesToLayerTypes = {
|
|
|
13
14
|
|
|
14
15
|
const getDefaulLayerTypeByGeometry: Function = (
|
|
15
16
|
geojson: Feature | FeatureCollection
|
|
16
|
-
):
|
|
17
|
+
): LayerSpecification['type'] => {
|
|
17
18
|
if (geojson?.type === "Feature") {
|
|
18
19
|
return mapGeometryTypesToLayerTypes?.[geojson?.geometry?.type]
|
|
19
20
|
? mapGeometryTypesToLayerTypes[geojson.geometry.type]
|
|
@@ -2,7 +2,9 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
import MlNavigationTools from "./MlNavigationTools";
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import noNavToolsDecorator from "../../decorators/NoNavToolsDecorator";
|
|
6
|
+
import BuildIcon from "@mui/icons-material/Build";
|
|
7
|
+
import Button from "@mui/material/Button";
|
|
6
8
|
|
|
7
9
|
const storyoptions = {
|
|
8
10
|
title: "MapComponents/MlNavigationTools",
|
|
@@ -11,12 +13,47 @@ const storyoptions = {
|
|
|
11
13
|
url: {},
|
|
12
14
|
layer: {},
|
|
13
15
|
},
|
|
14
|
-
decorators:
|
|
16
|
+
decorators: noNavToolsDecorator,
|
|
15
17
|
};
|
|
16
18
|
export default storyoptions;
|
|
17
19
|
|
|
18
|
-
const Template = (args) => <MlNavigationTools />;
|
|
20
|
+
const Template = (args) => <MlNavigationTools {...args} />;
|
|
19
21
|
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
export const DefaultConfig = Template.bind({});
|
|
23
|
+
DefaultConfig.parameters = {};
|
|
24
|
+
DefaultConfig.args = {};
|
|
25
|
+
|
|
26
|
+
export const No3DButton = Template.bind({});
|
|
27
|
+
No3DButton.parameters = {};
|
|
28
|
+
No3DButton.args = {
|
|
29
|
+
show3DButton: false,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const ShowCenterLocationButton = Template.bind({});
|
|
33
|
+
ShowCenterLocationButton.parameters = {};
|
|
34
|
+
ShowCenterLocationButton.args = {
|
|
35
|
+
showFollowGpsButton: false,
|
|
36
|
+
showCenterLocationButton: true,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const NoZoomButtons = Template.bind({});
|
|
40
|
+
NoZoomButtons.parameters = {};
|
|
41
|
+
NoZoomButtons.args = {
|
|
42
|
+
showZoomButtons: false,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const NoFollowGpsButton = Template.bind({});
|
|
46
|
+
NoFollowGpsButton.parameters = {};
|
|
47
|
+
NoFollowGpsButton.args = {
|
|
48
|
+
showFollowGpsButton: false,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const CustomButton = Template.bind({});
|
|
52
|
+
CustomButton.parameters = {};
|
|
53
|
+
CustomButton.args = {
|
|
54
|
+
children: (
|
|
55
|
+
<Button onClick={() => {}}>
|
|
56
|
+
<BuildIcon sx={{ fontSize: "1em" }} />
|
|
57
|
+
</Button>
|
|
58
|
+
),
|
|
59
|
+
};
|
|
@@ -8,13 +8,41 @@ 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 3D button
|
|
25
|
+
*/
|
|
26
|
+
show3DButton?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Show zoom button
|
|
29
|
+
*/
|
|
30
|
+
showZoomButtons?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Show follow GPS button
|
|
33
|
+
*/
|
|
34
|
+
showFollowGpsButton?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Show center on current position button
|
|
37
|
+
*/
|
|
38
|
+
showCenterLocationButton?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Additional JSX Elements to be rendered below MlNavigationTools buttons
|
|
41
|
+
*/
|
|
42
|
+
children?: JSX.Element;
|
|
15
43
|
}
|
|
16
44
|
|
|
17
|
-
|
|
45
|
+
/**
|
|
18
46
|
* @component
|
|
19
47
|
*/
|
|
20
48
|
const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
@@ -35,31 +63,35 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
35
63
|
//border: "1px solid #bbb",
|
|
36
64
|
//boxShadow: "0px 0px 4px rgba(0,0,0,.5)",
|
|
37
65
|
margin: 0.15,
|
|
38
|
-
fontSize: mediaIsMobile ? "1.
|
|
66
|
+
fontSize: mediaIsMobile ? "1.4em" : "1.2em",
|
|
39
67
|
":hover": {
|
|
40
68
|
backgroundColor: "#515151",
|
|
41
69
|
},
|
|
42
70
|
color: "#ececec",
|
|
43
71
|
};
|
|
72
|
+
const iconStyle = {
|
|
73
|
+
fontSize: buttonStyle.fontSize,
|
|
74
|
+
}
|
|
44
75
|
|
|
45
76
|
useEffect(() => {
|
|
46
77
|
if (!mapHook.map) return;
|
|
47
78
|
|
|
48
|
-
mapHook.map.on(
|
|
49
|
-
|
|
79
|
+
mapHook.map.on(
|
|
80
|
+
"pitchend",
|
|
81
|
+
() => {
|
|
82
|
+
if (!mapHook.map) return;
|
|
50
83
|
|
|
51
|
-
|
|
52
|
-
|
|
84
|
+
setPitch(mapHook.map.map.getPitch());
|
|
85
|
+
},
|
|
86
|
+
mapHook.componentId
|
|
87
|
+
);
|
|
53
88
|
setPitch(mapHook.map.map.getPitch());
|
|
54
89
|
}, [mapHook.map, props.mapId]);
|
|
55
90
|
|
|
56
91
|
const zoomIn = () => {
|
|
57
92
|
if (!mapHook.map) return;
|
|
58
93
|
|
|
59
|
-
if (
|
|
60
|
-
mapHook.map.map.transform._zoom + 0.5 <=
|
|
61
|
-
mapHook.map.map.transform._maxZoom
|
|
62
|
-
) {
|
|
94
|
+
if (mapHook.map.map.transform._zoom + 0.5 <= mapHook.map.map.transform._maxZoom) {
|
|
63
95
|
mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom + 0.5 });
|
|
64
96
|
}
|
|
65
97
|
};
|
|
@@ -67,10 +99,7 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
67
99
|
const zoomOut = () => {
|
|
68
100
|
if (!mapHook.map) return;
|
|
69
101
|
|
|
70
|
-
if (
|
|
71
|
-
mapHook.map.map.transform._zoom - 0.5 >=
|
|
72
|
-
mapHook.map.map.transform._minZoom
|
|
73
|
-
) {
|
|
102
|
+
if (mapHook.map.map.transform._zoom - 0.5 >= mapHook.map.map.transform._minZoom) {
|
|
74
103
|
mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom - 0.5 });
|
|
75
104
|
}
|
|
76
105
|
};
|
|
@@ -108,10 +137,20 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
108
137
|
boxShadow: "0px 0px 18px rgba(0,0,0,.5)",
|
|
109
138
|
}}
|
|
110
139
|
/>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
140
|
+
{props.show3DButton && (
|
|
141
|
+
<Button
|
|
142
|
+
sx={{ ...buttonStyle, fontSize: mediaIsMobile ? "1.4em" : "1em", fontWeight: 600 }}
|
|
143
|
+
onClick={adjustPitch}
|
|
144
|
+
>
|
|
145
|
+
{pitch ? "2D" : "3D"}
|
|
146
|
+
</Button>
|
|
147
|
+
)}
|
|
148
|
+
{props.showFollowGpsButton && (
|
|
149
|
+
<MlFollowGps style={{ ...(({ color, ...rest }) => rest)(buttonStyle) }} />
|
|
150
|
+
)}
|
|
151
|
+
{props.showCenterLocationButton && (
|
|
152
|
+
<MlCenterPosition style={{ ...(({ color, ...rest }) => rest)(buttonStyle) }} />
|
|
153
|
+
)}
|
|
115
154
|
<ButtonGroup
|
|
116
155
|
orientation="vertical"
|
|
117
156
|
sx={{
|
|
@@ -121,19 +160,31 @@ const MlNavigationTools = (props: MlNavigationToolsProps) => {
|
|
|
121
160
|
"Button:hover": { border: "none" },
|
|
122
161
|
}}
|
|
123
162
|
>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sx={{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
163
|
+
{props.showZoomButtons && (
|
|
164
|
+
<>
|
|
165
|
+
<Button sx={{ ...buttonStyle }} onClick={zoomIn}>
|
|
166
|
+
<ControlPointIcon sx={{...iconStyle}} />
|
|
167
|
+
</Button>
|
|
168
|
+
<Button sx={{ ...buttonStyle }} onClick={zoomOut}>
|
|
169
|
+
<RemoveCircleOutlineIcon sx={{...iconStyle}} />
|
|
170
|
+
</Button>
|
|
171
|
+
</>
|
|
172
|
+
)}
|
|
134
173
|
</ButtonGroup>
|
|
174
|
+
{props.children &&
|
|
175
|
+
React.cloneElement(props.children, {
|
|
176
|
+
sx: { ...buttonStyle },
|
|
177
|
+
})}
|
|
135
178
|
</div>
|
|
136
179
|
);
|
|
137
180
|
};
|
|
138
181
|
|
|
182
|
+
MlNavigationTools.defaultProps = {
|
|
183
|
+
mapId: undefined,
|
|
184
|
+
show3DButton: true,
|
|
185
|
+
showFollowGpsButton: true,
|
|
186
|
+
showCenterLocationButton: false,
|
|
187
|
+
showZoomButtons: true,
|
|
188
|
+
};
|
|
189
|
+
|
|
139
190
|
export default MlNavigationTools;
|
|
@@ -7,6 +7,7 @@ import useMap from "../../hooks/useMap";
|
|
|
7
7
|
import { _transitionToGeojson } from "./util/transitionFunctions";
|
|
8
8
|
import MlGeoJsonLayer from "../MlGeoJsonLayer/MlGeoJsonLayer";
|
|
9
9
|
import { Feature, FeatureCollection } from "@turf/turf";
|
|
10
|
+
import { CircleLayerSpecification, FillLayerSpecification, LineLayerSpecification, MapLayerMouseEvent } from "maplibre-gl";
|
|
10
11
|
|
|
11
12
|
const msPerStep = 50;
|
|
12
13
|
|
|
@@ -15,57 +16,57 @@ interface MlTransitionGeoJsonLayerProps {
|
|
|
15
16
|
* Id of the target MapLibre instance in mapContext
|
|
16
17
|
*/
|
|
17
18
|
mapId: string;
|
|
19
|
+
/**
|
|
20
|
+
* GeoJSON data that is supposed to be rendered by this component.
|
|
21
|
+
*/
|
|
22
|
+
geojson: Feature | FeatureCollection | undefined;
|
|
18
23
|
/**
|
|
19
24
|
* Type of the layer that will be added to the MapLibre instance.
|
|
20
25
|
* Possible values: "line", "circle", "fill"
|
|
21
26
|
*/
|
|
22
|
-
type
|
|
27
|
+
type?: "fill" | "line" | "circle";
|
|
23
28
|
/**
|
|
24
|
-
*
|
|
29
|
+
* Paint property object, that is passed to the addLayer call.
|
|
25
30
|
* Possible props depend on the layer type.
|
|
26
31
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
|
|
27
32
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
28
33
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
29
34
|
*/
|
|
30
|
-
|
|
35
|
+
paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['paint'];
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
37
|
+
* Layout property object, that is passed to the addLayer call.
|
|
33
38
|
* Possible props depend on the layer type.
|
|
34
39
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
|
|
35
40
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
|
|
36
41
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
37
42
|
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
41
|
-
*/
|
|
42
|
-
defaultPaintOverrides: any;
|
|
43
|
+
layout?: CircleLayerSpecification['layout'] | FillLayerSpecification['layout'] | LineLayerSpecification['layout'];
|
|
43
44
|
/**
|
|
44
45
|
* Javascript object that is spread into the addLayer commands first parameter.
|
|
45
46
|
*/
|
|
46
|
-
options
|
|
47
|
+
options?: CircleLayerSpecification | FillLayerSpecification | LineLayerSpecification;
|
|
47
48
|
/**
|
|
48
|
-
*
|
|
49
|
+
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
+
defaultPaintOverrides?: { circle?: CircleLayerSpecification['paint'], fill?: FillLayerSpecification['paint'], line?: LineLayerSpecification['paint'] };
|
|
51
52
|
/**
|
|
52
53
|
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
53
54
|
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
54
55
|
*/
|
|
55
56
|
insertBeforeLayer: string;
|
|
56
57
|
/**
|
|
57
|
-
*
|
|
58
|
+
* Hover event handler that is executed whenever a geometry rendered by this component is hovered.
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
+
onHover?: MapLayerMouseEvent;
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* Click event handler that is executed whenever a geometry rendered by this component is clicked.
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
+
onClick?: MapLayerMouseEvent;
|
|
64
65
|
/**
|
|
65
66
|
* Leave event handler that is executed whenever a geometry rendered by this component is
|
|
66
67
|
* left/unhovered.
|
|
67
68
|
*/
|
|
68
|
-
onLeave
|
|
69
|
+
onLeave?: MapLayerMouseEvent;
|
|
69
70
|
/**
|
|
70
71
|
* Creates transition animation whenever the geojson prop changes.
|
|
71
72
|
* Only works with layer type "line" and LineString GeoJSON data.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { MapComponentsProvider } from "../index";
|
|
4
|
+
import MapLibreMap from "../components/MapLibreMap/MapLibreMap";
|
|
5
|
+
import "./style.css";
|
|
6
|
+
import { createTheme, ThemeProvider } from "@mui/material/styles";
|
|
7
|
+
import MlNavgiationTools from "../components/MlNavigationTools/MlNavigationTools";
|
|
8
|
+
|
|
9
|
+
const theme = createTheme({});
|
|
10
|
+
|
|
11
|
+
const decorators = [
|
|
12
|
+
(Story) => (
|
|
13
|
+
<div className="fullscreen_map">
|
|
14
|
+
<ThemeProvider theme={theme}>
|
|
15
|
+
<MapComponentsProvider>
|
|
16
|
+
<Story />
|
|
17
|
+
<MapLibreMap
|
|
18
|
+
options={{
|
|
19
|
+
zoom: 14.5,
|
|
20
|
+
style: "https://wms.wheregroup.com/tileserver/style/osm-bright.json",
|
|
21
|
+
center: [7.0851268, 50.73884],
|
|
22
|
+
}}
|
|
23
|
+
mapId="map_1"
|
|
24
|
+
/>
|
|
25
|
+
</MapComponentsProvider>
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
</div>
|
|
28
|
+
),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export default decorators;
|
package/src/hooks/useLayer.ts
CHANGED
|
@@ -6,6 +6,9 @@ import { LayerSpecification } from "maplibre-gl";
|
|
|
6
6
|
|
|
7
7
|
import MapLibreGlWrapper from "../components/MapLibreMap/lib/MapLibreGlWrapper";
|
|
8
8
|
|
|
9
|
+
import { MapLayerMouseEvent } from "maplibre-gl";
|
|
10
|
+
import { GeoJSONObject } from "@turf/turf";
|
|
11
|
+
|
|
9
12
|
type useLayerType = {
|
|
10
13
|
map: MapLibreGlWrapper | undefined;
|
|
11
14
|
layer: LayerSpecification;
|
|
@@ -20,11 +23,11 @@ interface useLayerProps {
|
|
|
20
23
|
idPrefix?: string;
|
|
21
24
|
insertBeforeLayer?: string;
|
|
22
25
|
insertBeforeFirstSymbolLayer?: boolean;
|
|
23
|
-
geojson?:
|
|
24
|
-
options: LayerSpecification
|
|
25
|
-
onHover?:
|
|
26
|
-
onClick?:
|
|
27
|
-
onLeave?:
|
|
26
|
+
geojson?: GeoJSONObject;
|
|
27
|
+
options: Partial<LayerSpecification>;
|
|
28
|
+
onHover?: MapLayerMouseEvent;
|
|
29
|
+
onClick?: MapLayerMouseEvent;
|
|
30
|
+
onLeave?: MapLayerMouseEvent;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
const legalLayerTypes = [
|
|
@@ -116,7 +119,7 @@ function useLayer(props: useLayerProps): useLayerType {
|
|
|
116
119
|
|
|
117
120
|
layerPaintConfRef.current = JSON.stringify(props.options?.paint);
|
|
118
121
|
layerLayoutConfRef.current = JSON.stringify(props.options?.layout);
|
|
119
|
-
layerTypeRef.current = props.options.type;
|
|
122
|
+
layerTypeRef.current = props.options.type as LayerSpecification['type'];
|
|
120
123
|
}, [props, mapHook.map]);
|
|
121
124
|
|
|
122
125
|
useEffect(() => {
|
|
@@ -124,8 +127,8 @@ function useLayer(props: useLayerProps): useLayerType {
|
|
|
124
127
|
|
|
125
128
|
if (
|
|
126
129
|
initializedRef.current &&
|
|
127
|
-
(legalLayerTypes.indexOf(props.options.type) === -1 ||
|
|
128
|
-
(legalLayerTypes.indexOf(props.options.type) !== -1 &&
|
|
130
|
+
(legalLayerTypes.indexOf(props.options.type as LayerSpecification['type']) === -1 ||
|
|
131
|
+
(legalLayerTypes.indexOf(props.options.type as LayerSpecification['type']) !== -1 &&
|
|
129
132
|
props.options.type === layerTypeRef.current))
|
|
130
133
|
) {
|
|
131
134
|
return;
|