@mapcomponents/react-maplibre 0.1.16 → 0.1.20
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 +16 -7
- package/coverage/clover.xml +259 -285
- package/coverage/coverage-final.json +10 -10
- package/coverage/lcov-report/index.html +42 -43
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +2 -3
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +2 -3
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +2 -3
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +2 -3
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.js.html +2 -3
- package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +2 -3
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +2 -3
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +2 -3
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +2 -3
- package/coverage/lcov-report/src/components/MlGPXViewer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +145 -161
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +16 -17
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +9 -13
- package/coverage/lcov-report/src/components/MlLayer/index.html +16 -17
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +2 -3
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +2 -3
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +2 -3
- package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +2 -3
- package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +3 -10
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +9 -82
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +10 -11
- package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +2 -3
- package/coverage/lcov-report/src/components/MlMarker/MlMarker.js.html +6 -7
- package/coverage/lcov-report/src/components/MlMarker/index.html +6 -7
- package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.js.html +2 -3
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +2 -3
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +2 -3
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +2 -3
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +2 -3
- package/coverage/lcov-report/src/components/MlScaleReference/index.html +2 -3
- package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +2 -3
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +2 -3
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +2 -3
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +2 -3
- package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +6 -25
- package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +6 -7
- package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.js.html +3 -4
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +2 -3
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +2 -3
- package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.js.html +2 -3
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +2 -3
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.js.html +6 -19
- package/coverage/lcov-report/src/components/MlWmsLoader/index.html +8 -9
- package/coverage/lcov-report/src/hooks/index.html +14 -15
- package/coverage/lcov-report/src/hooks/useMap.js.html +23 -24
- package/coverage/lcov-report/src/hooks/useMapState.js.html +7 -50
- package/coverage/lcov-report/src/hooks/useWms.js.html +9 -22
- package/coverage/lcov-report/src/i18n.js.html +2 -3
- package/coverage/lcov-report/src/index.html +2 -3
- package/coverage/lcov-report/src/translations/english.js.html +2 -3
- package/coverage/lcov-report/src/translations/german.js.html +2 -3
- package/coverage/lcov-report/src/translations/index.html +2 -3
- package/coverage/lcov.info +490 -524
- package/dist/index.esm.js +165 -153
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.js +3 -2
- package/src/components/MlComponentTemplate/MlComponentTemplate.js +3 -3
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js +104 -109
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +35 -6
- package/src/components/MlGeoJsonLayer/assets/sample_polygon_1.json +33 -0
- package/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.js +25 -0
- package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.js +31 -0
- package/src/components/MlLayer/MlLayer.js +0 -1
- package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +0 -2
- package/src/components/MlLayerSwitcher/MlLayerSwitcher.stories.js +3 -6
- package/src/components/MlLayerSwitcher/components/LayerBox.js +2 -26
- package/src/components/MlMarker/MlMarker.js +1 -1
- package/src/components/MlShareMapState/MlShareMapState.stories.js +14 -17
- package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.stories.js +1 -3
- package/src/components/MlUseMapDebugger/MlUseMapDebugger.js +1 -7
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +1 -1
- package/src/components/MlWmsLoader/MlWmsLoader.js +0 -4
- package/src/hooks/useMapState.js +0 -14
- package/src/hooks/useWms.js +2 -7
- package/src/ui_components/ImageLoader.js +8 -3
- package/src/ui_components/Sidebar.js +1 -1
- package/src/ui_components/TopToolbar.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapcomponents/react-maplibre",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@fontsource/roboto": "^4.5.1",
|
|
13
13
|
"@mapbox/mapbox-gl-draw": "^1.2.0",
|
|
14
14
|
"@mapbox/mapbox-gl-sync-move": "^0.3.0",
|
|
15
|
-
"@mapcomponents/react-core": "^0.1.
|
|
15
|
+
"@mapcomponents/react-core": "^0.1.7",
|
|
16
16
|
"@mui/icons-material": "^5.0.1",
|
|
17
17
|
"@mui/material": "5.0.0",
|
|
18
18
|
"@mui/styles": "^5.0.1",
|
|
@@ -69,6 +69,7 @@ const MapLibreGlWrapper = function (props) {
|
|
|
69
69
|
if (!Object.is(item.handler, handler)) {
|
|
70
70
|
return item;
|
|
71
71
|
}
|
|
72
|
+
return false;
|
|
72
73
|
});
|
|
73
74
|
},
|
|
74
75
|
/**
|
|
@@ -111,7 +112,7 @@ const MapLibreGlWrapper = function (props) {
|
|
|
111
112
|
//if (self.baseLayers.indexOf(layer.id) === -1) {
|
|
112
113
|
let paint = {};
|
|
113
114
|
let values = layer.paint?._values;
|
|
114
|
-
Object.keys(values || {}).
|
|
115
|
+
Object.keys(values || {}).forEach((propName) => {
|
|
115
116
|
paint[propName] =
|
|
116
117
|
typeof values[propName].value !== "undefined"
|
|
117
118
|
? values[propName].value.value
|
|
@@ -119,7 +120,7 @@ const MapLibreGlWrapper = function (props) {
|
|
|
119
120
|
});
|
|
120
121
|
let layout = {};
|
|
121
122
|
values = layer.layout?._values;
|
|
122
|
-
Object.keys(values || {}).
|
|
123
|
+
Object.keys(values || {}).forEach((propName) => {
|
|
123
124
|
layout[propName] =
|
|
124
125
|
typeof values[propName].value !== "undefined"
|
|
125
126
|
? values[propName].value.value
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useEffect
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import useMap from "../../hooks/useMap";
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ import useMap from "../../hooks/useMap";
|
|
|
11
11
|
* @component
|
|
12
12
|
*/
|
|
13
13
|
const MlComponentTemplate = (props) => {
|
|
14
|
-
const mapHook = useMap({mapId: props.mapId, waitForLayer: props.insertBeforeLayer});
|
|
14
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
15
15
|
const initializedRef = useRef(false);
|
|
16
16
|
|
|
17
17
|
useEffect(() => {
|
|
@@ -21,7 +21,7 @@ const MlComponentTemplate = (props) => {
|
|
|
21
21
|
initializedRef.current = true;
|
|
22
22
|
|
|
23
23
|
mapHook.map.setCenter([7.132122000552613, 50.716405378037706]);
|
|
24
|
-
}, [mapHook.map, props.mapId]);
|
|
24
|
+
}, [mapHook.map, mapHook.mapIsReady, props.mapId]);
|
|
25
25
|
|
|
26
26
|
return <></>;
|
|
27
27
|
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import React, { useRef, useEffect,
|
|
1
|
+
import React, { useRef, useEffect, useCallback } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
4
|
import * as turf from "@turf/turf";
|
|
6
|
-
|
|
7
|
-
import
|
|
5
|
+
|
|
6
|
+
import useMap from "../../hooks/useMap";
|
|
8
7
|
|
|
9
8
|
import { _transitionToGeojson } from "./util/transitionFunctions";
|
|
9
|
+
import getDefaultPaintPropsByType from "./util/getDefaultPaintPropsByType";
|
|
10
|
+
import getDefaulLayerTypeByGeometry from "./util/getDefaultLayerTypeByGeometry";
|
|
10
11
|
|
|
11
12
|
const msPerStep = 50;
|
|
13
|
+
const legalLayerTypes = ["circle", "fill", "line"];
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
|
|
@@ -17,58 +19,46 @@ const msPerStep = 50;
|
|
|
17
19
|
*/
|
|
18
20
|
const MlGeoJsonLayer = (props) => {
|
|
19
21
|
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
20
|
-
const
|
|
21
|
-
const mapState = useMapState({
|
|
22
|
-
mapId: props.mapId,
|
|
23
|
-
watch: {
|
|
24
|
-
viewport: false,
|
|
25
|
-
layers: true,
|
|
26
|
-
sources: false,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
const oldGeojsonRef = useRef(null);
|
|
30
|
-
const mapRef = useRef(null);
|
|
22
|
+
const mapHook = useMap({ mapId: props.mapId, waitForLayer: props.insertBeforeLayer });
|
|
31
23
|
const initializedRef = useRef(false);
|
|
24
|
+
const layerId = useRef(props.layerId || "MlGeoJsonLayer-" + mapHook.componentId);
|
|
25
|
+
const layerTypeRef = useRef(undefined);
|
|
26
|
+
|
|
27
|
+
// transition effect variables
|
|
28
|
+
const oldGeojsonRef = useRef(null);
|
|
32
29
|
const transitionInProgressRef = useRef(false);
|
|
33
30
|
const transitionTimeoutRef = useRef(undefined);
|
|
34
31
|
const currentTransitionStepRef = useRef(false);
|
|
35
32
|
const transitionGeojsonDataRef = useRef([]);
|
|
36
33
|
const transitionGeojsonCommonDataRef = useRef([]);
|
|
37
|
-
const componentId = useRef(
|
|
38
|
-
(props.layerId ? props.layerId : "MlGeoJsonLayer-") + (props.idSuffix || uuidv4())
|
|
39
|
-
);
|
|
40
|
-
const layerId = useRef(props.layerId || componentId.current);
|
|
41
34
|
|
|
42
35
|
useEffect(() => {
|
|
43
|
-
let _componentId = componentId.current;
|
|
44
36
|
return () => {
|
|
45
37
|
// This is the cleanup function, it is called when this react component is removed from react-dom
|
|
46
38
|
if (transitionTimeoutRef.current) {
|
|
47
39
|
clearTimeout(transitionTimeoutRef.current);
|
|
48
40
|
}
|
|
49
|
-
if (mapRef.current) {
|
|
50
|
-
mapRef.current.cleanup(_componentId);
|
|
51
|
-
|
|
52
|
-
mapRef.current = null;
|
|
53
|
-
}
|
|
54
41
|
};
|
|
55
42
|
}, []);
|
|
56
43
|
|
|
57
44
|
useEffect(() => {
|
|
58
|
-
if (!
|
|
45
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
59
46
|
|
|
60
47
|
for (var key in props.layout) {
|
|
61
|
-
|
|
48
|
+
mapHook.map.setLayoutProperty(layerId.current, key, props.layout[key]);
|
|
62
49
|
}
|
|
63
|
-
}, [props.layout,
|
|
50
|
+
}, [props.layout, mapHook.map, props.mapId]);
|
|
64
51
|
|
|
65
52
|
useEffect(() => {
|
|
66
|
-
if (!
|
|
53
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
54
|
+
|
|
55
|
+
let _paint =
|
|
56
|
+
props.paint || getDefaultPaintPropsByType(layerTypeRef.current, props.defaultPaintOverrides);
|
|
67
57
|
|
|
68
|
-
for (var key in
|
|
69
|
-
|
|
58
|
+
for (var key in _paint) {
|
|
59
|
+
mapHook.map.setPaintProperty(layerId.current, key, _paint[key]);
|
|
70
60
|
}
|
|
71
|
-
}, [props.paint,
|
|
61
|
+
}, [props.paint, mapHook.map, props.mapId, props.defaultPaintOverrides]);
|
|
72
62
|
|
|
73
63
|
const transitionToGeojson = useCallback(
|
|
74
64
|
(newGeojson) => {
|
|
@@ -81,18 +71,16 @@ const MlGeoJsonLayer = (props) => {
|
|
|
81
71
|
oldGeojsonRef,
|
|
82
72
|
msPerStep,
|
|
83
73
|
currentTransitionStepRef,
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
mapHook.map,
|
|
75
|
+
layerId.current,
|
|
86
76
|
transitionTimeoutRef
|
|
87
77
|
);
|
|
88
78
|
},
|
|
89
|
-
[props]
|
|
79
|
+
[props, mapHook.map]
|
|
90
80
|
);
|
|
91
81
|
|
|
92
82
|
useEffect(() => {
|
|
93
|
-
if (!
|
|
94
|
-
// the MapLibre-gl instance (mapContext.map) is accessible here
|
|
95
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
83
|
+
if (!mapHook?.map?.getSource(layerId.current) || !initializedRef.current) return;
|
|
96
84
|
|
|
97
85
|
if (
|
|
98
86
|
typeof props.transitionTime !== "undefined" &&
|
|
@@ -105,92 +93,96 @@ const MlGeoJsonLayer = (props) => {
|
|
|
105
93
|
transitionGeojsonCommonDataRef.current = [];
|
|
106
94
|
transitionToGeojson(props.geojson);
|
|
107
95
|
} else {
|
|
108
|
-
|
|
96
|
+
mapHook.map.getSource(layerId.current).setData(props.geojson);
|
|
109
97
|
}
|
|
110
98
|
oldGeojsonRef.current = props.geojson;
|
|
111
99
|
}, [
|
|
112
100
|
props.geojson,
|
|
113
101
|
props.mapId,
|
|
114
|
-
|
|
102
|
+
mapHook.map,
|
|
115
103
|
props.type,
|
|
116
104
|
transitionToGeojson,
|
|
117
105
|
props.transitionTime,
|
|
118
106
|
]);
|
|
119
107
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// the MapLibre-gl instance (mapContext.map) is accessible here
|
|
123
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
108
|
+
const createLayer = useCallback(() => {
|
|
109
|
+
let geojson = props.geojson;
|
|
124
110
|
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
if (
|
|
112
|
+
props.type === "line" &&
|
|
113
|
+
typeof props.transitionTime !== "undefined" &&
|
|
114
|
+
props.transitionTime &&
|
|
115
|
+
typeof props.geojson.geometry !== "undefined"
|
|
116
|
+
) {
|
|
117
|
+
var tmpChunks = turf.lineChunk(props.geojson, 0.01);
|
|
118
|
+
geojson = tmpChunks.features[0];
|
|
119
|
+
}
|
|
129
120
|
|
|
130
|
-
|
|
131
|
-
if (layer.id === props.insertBeforeLayer) {
|
|
132
|
-
layerFound = true;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (!layerFound) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
initializedRef.current = true;
|
|
140
|
-
let geojson = props.geojson;
|
|
121
|
+
layerTypeRef.current = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
141
122
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
123
|
+
mapHook.map.addLayer(
|
|
124
|
+
{
|
|
125
|
+
id: layerId.current,
|
|
126
|
+
source: {
|
|
127
|
+
type: "geojson",
|
|
128
|
+
data: geojson,
|
|
129
|
+
},
|
|
130
|
+
type: layerTypeRef.current,
|
|
131
|
+
paint:
|
|
132
|
+
props.paint ||
|
|
133
|
+
getDefaultPaintPropsByType(layerTypeRef.current, props.defaultPaintOverrides),
|
|
134
|
+
layout: props.layout || {},
|
|
135
|
+
...props.options,
|
|
136
|
+
},
|
|
137
|
+
props.insertBeforeLayer,
|
|
138
|
+
mapHook.componentId
|
|
139
|
+
);
|
|
151
140
|
|
|
152
|
-
|
|
141
|
+
if (typeof props.onHover !== "undefined") {
|
|
142
|
+
mapHook.map.on("mousemove", mapHook.componentId, props.onHover, mapHook.componentId);
|
|
143
|
+
}
|
|
153
144
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
source: {
|
|
158
|
-
type: "geojson",
|
|
159
|
-
data: geojson,
|
|
160
|
-
},
|
|
161
|
-
type: props.type || "line",
|
|
162
|
-
paint: props.paint || {
|
|
163
|
-
"line-color": "rgb(100,200,100)",
|
|
164
|
-
"line-width": 10,
|
|
165
|
-
},
|
|
166
|
-
layout: props.layout || {},
|
|
167
|
-
},
|
|
168
|
-
props.insertBeforeLayer,
|
|
169
|
-
componentId.current
|
|
170
|
-
);
|
|
145
|
+
if (typeof props.onClick !== "undefined") {
|
|
146
|
+
mapHook.map.on("click", mapHook.componentId, props.onClick, mapHook.componentId);
|
|
147
|
+
}
|
|
171
148
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
149
|
+
if (typeof props.onLeave !== "undefined") {
|
|
150
|
+
mapHook.map.on("mouseleave", mapHook.componentId, props.onLeave, mapHook.componentId);
|
|
151
|
+
}
|
|
175
152
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
153
|
+
if (
|
|
154
|
+
props.type === "line" &&
|
|
155
|
+
typeof props.transitionTime !== "undefined" &&
|
|
156
|
+
typeof props.geojson.geometry !== "undefined"
|
|
157
|
+
) {
|
|
158
|
+
transitionToGeojson(props.geojson);
|
|
159
|
+
oldGeojsonRef.current = props.geojson;
|
|
160
|
+
}
|
|
161
|
+
}, [mapHook.map, props, transitionToGeojson]);
|
|
179
162
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!mapHook.mapIsReady || !props.geojson) return;
|
|
183
165
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
166
|
+
if (
|
|
167
|
+
initializedRef.current &&
|
|
168
|
+
legalLayerTypes.indexOf(props.type) !== -1 &&
|
|
169
|
+
layerTypeRef.current &&
|
|
170
|
+
props.type !== layerTypeRef.current
|
|
171
|
+
) {
|
|
172
|
+
mapHook.map.cleanup(mapHook.componentId);
|
|
173
|
+
} else if (
|
|
174
|
+
initializedRef.current &&
|
|
175
|
+
(legalLayerTypes.indexOf(props.type) === -1 ||
|
|
176
|
+
(legalLayerTypes.indexOf(props.type) !== -1 && props.type === layerTypeRef.current))
|
|
177
|
+
) {
|
|
178
|
+
return;
|
|
192
179
|
}
|
|
193
|
-
|
|
180
|
+
|
|
181
|
+
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
182
|
+
initializedRef.current = true;
|
|
183
|
+
|
|
184
|
+
createLayer();
|
|
185
|
+
}, [mapHook.mapIsReady, createLayer, props]);
|
|
194
186
|
|
|
195
187
|
return <></>;
|
|
196
188
|
};
|
|
@@ -221,6 +213,14 @@ MlGeoJsonLayer.propTypes = {
|
|
|
221
213
|
* https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
|
|
222
214
|
*/
|
|
223
215
|
paint: PropTypes.object,
|
|
216
|
+
/**
|
|
217
|
+
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
218
|
+
*/
|
|
219
|
+
defaultPaintOverrides: PropTypes.object,
|
|
220
|
+
/**
|
|
221
|
+
* Javascript object that is spread into the addLayer commands first parameter.
|
|
222
|
+
*/
|
|
223
|
+
options: PropTypes.object,
|
|
224
224
|
/**
|
|
225
225
|
* GeoJSON data that is supposed to be rendered by this component.
|
|
226
226
|
*/
|
|
@@ -252,11 +252,6 @@ MlGeoJsonLayer.propTypes = {
|
|
|
252
252
|
* Only works with layer type "line" and LineString GeoJSON data.
|
|
253
253
|
*/
|
|
254
254
|
transitionTime: PropTypes.number,
|
|
255
|
-
/**
|
|
256
|
-
* Id suffix string that is appended to the componentId.
|
|
257
|
-
* Probably removed soon.
|
|
258
|
-
*/
|
|
259
|
-
idSuffix: PropTypes.string,
|
|
260
255
|
};
|
|
261
256
|
|
|
262
257
|
export default MlGeoJsonLayer;
|
|
@@ -7,7 +7,9 @@ import { MapContext } from "@mapcomponents/react-core";
|
|
|
7
7
|
|
|
8
8
|
import sample_geojson_1 from "./assets/sample_1.json";
|
|
9
9
|
import sample_geojson_2 from "./assets/sample_2.json";
|
|
10
|
+
import sample_polygon_geojson_1 from "./assets/sample_polygon_1.json";
|
|
10
11
|
|
|
12
|
+
console.log(sample_polygon_geojson_1);
|
|
11
13
|
const storyoptions = {
|
|
12
14
|
title: "MapComponents/MlGeoJsonLayer",
|
|
13
15
|
component: MlGeoJsonLayer,
|
|
@@ -20,6 +22,13 @@ const storyoptions = {
|
|
|
20
22
|
export default storyoptions;
|
|
21
23
|
|
|
22
24
|
const Template = (props) => {
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<MlGeoJsonLayer {...props} />
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
const LinestringTransitionTemplate = (props) => {
|
|
23
32
|
const mapContext = useContext(MapContext);
|
|
24
33
|
const [geojson, setGeojson] = useState(sample_geojson_1);
|
|
25
34
|
const initializedRef = useRef(false);
|
|
@@ -28,9 +37,7 @@ const Template = (props) => {
|
|
|
28
37
|
if (!mapContext.getMap() || initializedRef.current) return;
|
|
29
38
|
|
|
30
39
|
initializedRef.current = true;
|
|
31
|
-
mapContext
|
|
32
|
-
.getMap()
|
|
33
|
-
.setCenter({ lng: 7.137609868988648, lat: 50.74746799549129 });
|
|
40
|
+
mapContext.getMap().setCenter({ lng: 7.137609868988648, lat: 50.74746799549129 });
|
|
34
41
|
mapContext.getMap().setZoom(9.5);
|
|
35
42
|
|
|
36
43
|
setTimeout(() => {
|
|
@@ -45,6 +52,28 @@ const Template = (props) => {
|
|
|
45
52
|
);
|
|
46
53
|
};
|
|
47
54
|
|
|
48
|
-
export const
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
export const Linestring = LinestringTransitionTemplate.bind({});
|
|
56
|
+
Linestring.parameters = {};
|
|
57
|
+
Linestring.args = {};
|
|
58
|
+
|
|
59
|
+
export const Polygon = Template.bind({});
|
|
60
|
+
Polygon.parameters = {};
|
|
61
|
+
Polygon.args = {
|
|
62
|
+
geojson: sample_polygon_geojson_1,
|
|
63
|
+
};
|
|
64
|
+
export const DefaultPaintOverrides = Template.bind({});
|
|
65
|
+
DefaultPaintOverrides.parameters = {};
|
|
66
|
+
DefaultPaintOverrides.args = {
|
|
67
|
+
defaultPaintOverrides: {
|
|
68
|
+
fill: {
|
|
69
|
+
"fill-color": "blue",
|
|
70
|
+
},
|
|
71
|
+
circle: {
|
|
72
|
+
"circle-color": "red",
|
|
73
|
+
},
|
|
74
|
+
line: {
|
|
75
|
+
"line-color": "orange",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
geojson: sample_polygon_geojson_1,
|
|
79
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "FeatureCollection",
|
|
3
|
+
"features": [
|
|
4
|
+
{
|
|
5
|
+
"type": "Feature",
|
|
6
|
+
"properties": {},
|
|
7
|
+
"geometry": {
|
|
8
|
+
"coordinates": [
|
|
9
|
+
[
|
|
10
|
+
[7.08646747303149, 50.74485058672653],
|
|
11
|
+
[7.084287513691095, 50.74371917250187],
|
|
12
|
+
[7.084437772332876, 50.743610683782215],
|
|
13
|
+
[7.084640903561933, 50.743721758552354],
|
|
14
|
+
[7.085805654941254, 50.74293993704128],
|
|
15
|
+
[7.087023278906713, 50.74218320888983],
|
|
16
|
+
[7.087791368229503, 50.74258090834434],
|
|
17
|
+
[7.088796806075749, 50.743261830692745],
|
|
18
|
+
[7.089275088452752, 50.743701110992674],
|
|
19
|
+
[7.088087117762917, 50.74409411011173],
|
|
20
|
+
[7.087662548338368, 50.743784963165815],
|
|
21
|
+
[7.087184330538875, 50.7440368518605],
|
|
22
|
+
[7.087233860417484, 50.744077781245316],
|
|
23
|
+
[7.08714938625954, 50.744122118772154],
|
|
24
|
+
[7.087057544749172, 50.74427276821896],
|
|
25
|
+
[7.087104984084277, 50.744509715654885],
|
|
26
|
+
[7.08646747303149, 50.74485058672653]
|
|
27
|
+
]
|
|
28
|
+
],
|
|
29
|
+
"type": "Polygon"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mapGeometryTypesToLayerTypes = {
|
|
2
|
+
Position: "circle",
|
|
3
|
+
Point: "circle",
|
|
4
|
+
MultiPoint: "circle",
|
|
5
|
+
LineString: "line",
|
|
6
|
+
MultiLineString: "line",
|
|
7
|
+
Polygon: "fill",
|
|
8
|
+
MultiPolygon: "fill",
|
|
9
|
+
GeometryCollection: "circle",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getDefaulLayerTypeByGeometry = (geojson) => {
|
|
13
|
+
if (geojson?.type === "Feature") {
|
|
14
|
+
return mapGeometryTypesToLayerTypes?.[geojson?.geometry?.type]
|
|
15
|
+
? mapGeometryTypesToLayerTypes[geojson.geometry.type]
|
|
16
|
+
: "circle";
|
|
17
|
+
}
|
|
18
|
+
if (geojson?.type === "FeatureCollection") {
|
|
19
|
+
if (geojson.features.length) {
|
|
20
|
+
return getDefaulLayerTypeByGeometry(geojson.features[0]);
|
|
21
|
+
}
|
|
22
|
+
return "circle";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export default getDefaulLayerTypeByGeometry;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const getDefaultPaintPropsByType = (type, defaultPaintOverrides) => {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case "fill":
|
|
4
|
+
if (defaultPaintOverrides?.fill) {
|
|
5
|
+
return defaultPaintOverrides.fill;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
"fill-color": "rgba(10,240,256,0.6)",
|
|
9
|
+
};
|
|
10
|
+
case "line":
|
|
11
|
+
if (defaultPaintOverrides?.line) {
|
|
12
|
+
return defaultPaintOverrides.line;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
"line-color": "rgb(100,200,100)",
|
|
16
|
+
"line-width": 5,
|
|
17
|
+
};
|
|
18
|
+
case "circle":
|
|
19
|
+
default:
|
|
20
|
+
if (defaultPaintOverrides?.circle) {
|
|
21
|
+
return defaultPaintOverrides.circle;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
"circle-color": "#44aaaa",
|
|
25
|
+
"circle-stroke-color": "#fff",
|
|
26
|
+
"circle-stroke-width": 2,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default getDefaultPaintPropsByType;
|
|
@@ -19,7 +19,6 @@ const MlLayer = (props) => {
|
|
|
19
19
|
const layerInitializedRef = useRef(false);
|
|
20
20
|
const mapRef = useRef(null);
|
|
21
21
|
const componentId = useRef((props.layerId ? props.layerId : "MlLayer-") + uuidv4());
|
|
22
|
-
const idSuffixRef = useRef(props.idSuffix || new Date().getTime());
|
|
23
22
|
const layerId = useRef(props.layerId || componentId.current);
|
|
24
23
|
const layerPaintConfRef = useRef(undefined);
|
|
25
24
|
const layerLayoutConfRef = useRef(undefined);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import "@fontsource/roboto/300.css";
|
|
3
3
|
import "@fontsource/roboto/400.css";
|
|
4
4
|
import "@fontsource/roboto/500.css";
|
|
5
|
-
import { css, cx } from '@emotion/css'
|
|
6
5
|
import "./MlLayerSwitcher.css";
|
|
7
6
|
//External
|
|
8
7
|
import { useEffect, useContext, useState } from "react";
|
|
@@ -14,7 +13,6 @@ import { MapContext } from "@mapcomponents/react-core";
|
|
|
14
13
|
import LayerBox from "./components/LayerBox";
|
|
15
14
|
import Divider from "@mui/material/Divider";
|
|
16
15
|
import useMapState from "../../hooks/useMapState";
|
|
17
|
-
import LoadingOverlay from "../../ui_components/LoadingOverlay";
|
|
18
16
|
/**
|
|
19
17
|
* @component
|
|
20
18
|
*
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import MlWmsLayer from "../MlWmsLayer/MlWmsLayer";
|
|
3
3
|
import MlLayerSwitcher from "./MlLayerSwitcher";
|
|
4
|
-
import MlGeoJsonLayer from
|
|
4
|
+
import MlGeoJsonLayer from "../MlGeoJsonLayer/MlGeoJsonLayer";
|
|
5
5
|
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
6
6
|
import sample_geojson_1 from "./assets/sample_1.json";
|
|
7
7
|
import sample_geojson_2 from "./assets/sample_2.json";
|
|
8
|
-
import { Props } from "@storybook/addon-docs/blocks";
|
|
9
8
|
|
|
10
9
|
const storyoptions = {
|
|
11
10
|
title: "MapComponents/MlLayerSwitcher",
|
|
@@ -17,9 +16,7 @@ const storyoptions = {
|
|
|
17
16
|
decorators: mapContextDecorator,
|
|
18
17
|
};
|
|
19
18
|
export default storyoptions;
|
|
20
|
-
const layerId = "nw_uraufnahme_rw";
|
|
21
19
|
const Template = (args) => {
|
|
22
|
-
const [geojson, setGeojson] = useState(sample_geojson_1);
|
|
23
20
|
return (
|
|
24
21
|
<>
|
|
25
22
|
<MlWmsLayer
|
|
@@ -39,7 +36,7 @@ const Template = (args) => {
|
|
|
39
36
|
<MlGeoJsonLayer
|
|
40
37
|
type="line"
|
|
41
38
|
layout={{ visibility: args.geojsonLayerVisible ? "visible" : "none" }}
|
|
42
|
-
geojson={
|
|
39
|
+
geojson={sample_geojson_1}
|
|
43
40
|
layerId="geojson1"
|
|
44
41
|
/>
|
|
45
42
|
<MlGeoJsonLayer
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { css
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { css } from "@emotion/css";
|
|
3
3
|
import { Box } from "@mui/system";
|
|
4
4
|
import ImageLoader from "../../../ui_components/ImageLoader";
|
|
5
|
-
import { propsToClassKey } from "@mui/styles";
|
|
6
5
|
import useMapState from "../../../hooks/useMapState";
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -10,8 +9,6 @@ import useMapState from "../../../hooks/useMapState";
|
|
|
10
9
|
*
|
|
11
10
|
*/
|
|
12
11
|
const LayerBox = (props) => {
|
|
13
|
-
const [activeClassName, setActiveClassName] = useState("");
|
|
14
|
-
const [className, setClassName] = useState("mllayerswitcher-layer-box ");
|
|
15
12
|
const { layers } = useMapState({
|
|
16
13
|
mapId: props.mapId,
|
|
17
14
|
watch: {
|
|
@@ -23,33 +20,12 @@ const LayerBox = (props) => {
|
|
|
23
20
|
matchLayerIds: props.layerId,
|
|
24
21
|
},
|
|
25
22
|
});
|
|
26
|
-
const hoverBorderColor = "#1C62D7"; //Navy Blue
|
|
27
|
-
const activeBorderColor = "";
|
|
28
23
|
const width = "40px";
|
|
29
24
|
|
|
30
25
|
const defaultClass = css`
|
|
31
26
|
& img:hover {
|
|
32
27
|
}
|
|
33
28
|
`;
|
|
34
|
-
const activeClass =
|
|
35
|
-
defaultClass +
|
|
36
|
-
`& img {
|
|
37
|
-
border-color: rgb(196, 240, 0);
|
|
38
|
-
border-radius: 8px;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
`;
|
|
42
|
-
const hoverClass = css``;
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
const isActive = props.activeLayers?.indexOf(props.layerId) !== -1;
|
|
46
|
-
|
|
47
|
-
if (isActive) {
|
|
48
|
-
setClassName(activeClass);
|
|
49
|
-
} else {
|
|
50
|
-
setClassName(defaultClass);
|
|
51
|
-
}
|
|
52
|
-
}, [props.activeLayers]);
|
|
53
29
|
|
|
54
30
|
return (
|
|
55
31
|
<>
|
|
@@ -67,7 +67,6 @@ const MlMarker = (props) => {
|
|
|
67
67
|
useEffect(() => {
|
|
68
68
|
if (mapRef.current && iframe.current?.contentWindow?.document?.body?.scrollHeight) {
|
|
69
69
|
setTimeout(() => {
|
|
70
|
-
let mapWidth = mapRef.current._container.clientWidth;
|
|
71
70
|
let mapHeight = mapRef.current._container.clientHeight;
|
|
72
71
|
|
|
73
72
|
const _pixelPos = mapRef.current.project([props.lng, props.lat]);
|
|
@@ -124,6 +123,7 @@ const MlMarker = (props) => {
|
|
|
124
123
|
ref={iframe}
|
|
125
124
|
sandbox="allow-same-origin allow-popups-to-escape-sandbox"
|
|
126
125
|
frameBorder="0"
|
|
126
|
+
title={componentId.current}
|
|
127
127
|
></iframe>
|
|
128
128
|
</Paper>
|
|
129
129
|
)}
|