@mapcomponents/react-maplibre 0.1.16 → 0.1.17
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 +257 -284
- package/coverage/coverage-final.json +10 -10
- package/coverage/lcov-report/index.html +44 -45
- 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 +123 -181
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +20 -21
- 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 +2 -3
- 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 +487 -524
- package/dist/index.esm.js +137 -148
- 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 +90 -109
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +20 -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 +22 -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/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.17",
|
|
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,43 @@ 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;
|
|
67
54
|
|
|
68
55
|
for (var key in props.paint) {
|
|
69
|
-
|
|
56
|
+
mapHook.map.setPaintProperty(layerId.current, key, props.paint[key]);
|
|
70
57
|
}
|
|
71
|
-
}, [props.paint,
|
|
58
|
+
}, [props.paint, mapHook.map, props.mapId]);
|
|
72
59
|
|
|
73
60
|
const transitionToGeojson = useCallback(
|
|
74
61
|
(newGeojson) => {
|
|
@@ -81,18 +68,16 @@ const MlGeoJsonLayer = (props) => {
|
|
|
81
68
|
oldGeojsonRef,
|
|
82
69
|
msPerStep,
|
|
83
70
|
currentTransitionStepRef,
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
mapHook.map,
|
|
72
|
+
layerId.current,
|
|
86
73
|
transitionTimeoutRef
|
|
87
74
|
);
|
|
88
75
|
},
|
|
89
|
-
[props]
|
|
76
|
+
[props, mapHook.map]
|
|
90
77
|
);
|
|
91
78
|
|
|
92
79
|
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
|
|
80
|
+
if (!mapHook?.map?.getSource(layerId.current) || !initializedRef.current) return;
|
|
96
81
|
|
|
97
82
|
if (
|
|
98
83
|
typeof props.transitionTime !== "undefined" &&
|
|
@@ -105,92 +90,93 @@ const MlGeoJsonLayer = (props) => {
|
|
|
105
90
|
transitionGeojsonCommonDataRef.current = [];
|
|
106
91
|
transitionToGeojson(props.geojson);
|
|
107
92
|
} else {
|
|
108
|
-
|
|
93
|
+
mapHook.map.getSource(layerId.current).setData(props.geojson);
|
|
109
94
|
}
|
|
110
95
|
oldGeojsonRef.current = props.geojson;
|
|
111
96
|
}, [
|
|
112
97
|
props.geojson,
|
|
113
98
|
props.mapId,
|
|
114
|
-
|
|
99
|
+
mapHook.map,
|
|
115
100
|
props.type,
|
|
116
101
|
transitionToGeojson,
|
|
117
102
|
props.transitionTime,
|
|
118
103
|
]);
|
|
119
104
|
|
|
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
|
|
124
|
-
|
|
125
|
-
if (props.geojson) {
|
|
126
|
-
//check if insertBeforeLayer exists
|
|
127
|
-
if (props.insertBeforeLayer) {
|
|
128
|
-
let layerFound = false;
|
|
129
|
-
|
|
130
|
-
mapState?.layers?.forEach((layer) => {
|
|
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;
|
|
105
|
+
const createLayer = useCallback(() => {
|
|
106
|
+
let geojson = props.geojson;
|
|
141
107
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
108
|
+
if (
|
|
109
|
+
props.type === "line" &&
|
|
110
|
+
typeof props.transitionTime !== "undefined" &&
|
|
111
|
+
props.transitionTime &&
|
|
112
|
+
typeof props.geojson.geometry !== "undefined"
|
|
113
|
+
) {
|
|
114
|
+
var tmpChunks = turf.lineChunk(props.geojson, 0.01);
|
|
115
|
+
geojson = tmpChunks.features[0];
|
|
116
|
+
}
|
|
151
117
|
|
|
152
|
-
|
|
118
|
+
layerTypeRef.current = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
153
119
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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 || {},
|
|
120
|
+
mapHook.map.addLayer(
|
|
121
|
+
{
|
|
122
|
+
id: layerId.current,
|
|
123
|
+
source: {
|
|
124
|
+
type: "geojson",
|
|
125
|
+
data: geojson,
|
|
167
126
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
127
|
+
type: layerTypeRef.current,
|
|
128
|
+
paint: props.paint || getDefaultPaintPropsByType(layerTypeRef.current),
|
|
129
|
+
layout: props.layout || {},
|
|
130
|
+
},
|
|
131
|
+
props.insertBeforeLayer,
|
|
132
|
+
mapHook.componentId
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (typeof props.onHover !== "undefined") {
|
|
136
|
+
mapHook.map.on("mousemove", mapHook.componentId, props.onHover, mapHook.componentId);
|
|
137
|
+
}
|
|
171
138
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
139
|
+
if (typeof props.onClick !== "undefined") {
|
|
140
|
+
mapHook.map.on("click", mapHook.componentId, props.onClick, mapHook.componentId);
|
|
141
|
+
}
|
|
175
142
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
143
|
+
if (typeof props.onLeave !== "undefined") {
|
|
144
|
+
mapHook.map.on("mouseleave", mapHook.componentId, props.onLeave, mapHook.componentId);
|
|
145
|
+
}
|
|
179
146
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
147
|
+
if (
|
|
148
|
+
props.type === "line" &&
|
|
149
|
+
typeof props.transitionTime !== "undefined" &&
|
|
150
|
+
typeof props.geojson.geometry !== "undefined"
|
|
151
|
+
) {
|
|
152
|
+
transitionToGeojson(props.geojson);
|
|
153
|
+
oldGeojsonRef.current = props.geojson;
|
|
154
|
+
}
|
|
155
|
+
}, [mapHook.map, props, transitionToGeojson]);
|
|
183
156
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!mapHook.mapIsReady || !props.geojson) return;
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
initializedRef.current &&
|
|
162
|
+
legalLayerTypes.indexOf(props.type) !== -1 &&
|
|
163
|
+
layerTypeRef.current &&
|
|
164
|
+
props.type !== layerTypeRef.current
|
|
165
|
+
) {
|
|
166
|
+
mapHook.map.cleanup(mapHook.componentId);
|
|
167
|
+
} else if (
|
|
168
|
+
initializedRef.current &&
|
|
169
|
+
(legalLayerTypes.indexOf(props.type) === -1 ||
|
|
170
|
+
(legalLayerTypes.indexOf(props.type) !== -1 && props.type === layerTypeRef.current))
|
|
171
|
+
) {
|
|
172
|
+
return;
|
|
192
173
|
}
|
|
193
|
-
|
|
174
|
+
|
|
175
|
+
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
176
|
+
initializedRef.current = true;
|
|
177
|
+
|
|
178
|
+
createLayer();
|
|
179
|
+
}, [mapHook.mapIsReady, createLayer, props]);
|
|
194
180
|
|
|
195
181
|
return <></>;
|
|
196
182
|
};
|
|
@@ -252,11 +238,6 @@ MlGeoJsonLayer.propTypes = {
|
|
|
252
238
|
* Only works with layer type "line" and LineString GeoJSON data.
|
|
253
239
|
*/
|
|
254
240
|
transitionTime: PropTypes.number,
|
|
255
|
-
/**
|
|
256
|
-
* Id suffix string that is appended to the componentId.
|
|
257
|
-
* Probably removed soon.
|
|
258
|
-
*/
|
|
259
|
-
idSuffix: PropTypes.string,
|
|
260
241
|
};
|
|
261
242
|
|
|
262
243
|
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,13 @@ const Template = (props) => {
|
|
|
45
52
|
);
|
|
46
53
|
};
|
|
47
54
|
|
|
48
|
-
export const
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
export const LinestringExample = LinestringTransitionTemplate.bind({});
|
|
56
|
+
LinestringExample.parameters = {};
|
|
57
|
+
LinestringExample.args = {};
|
|
58
|
+
|
|
59
|
+
export const PolygonExample = Template.bind({});
|
|
60
|
+
PolygonExample.parameters = {};
|
|
61
|
+
PolygonExample.args = {
|
|
62
|
+
type: "line",
|
|
63
|
+
geojson: sample_polygon_geojson_1,
|
|
64
|
+
};
|
|
@@ -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,22 @@
|
|
|
1
|
+
const getDefaultPaintPropsByType = (type) => {
|
|
2
|
+
switch (type) {
|
|
3
|
+
case "fill":
|
|
4
|
+
return {
|
|
5
|
+
"fill-color": "rgba(10,240,256,0.6)",
|
|
6
|
+
};
|
|
7
|
+
case "line":
|
|
8
|
+
return {
|
|
9
|
+
"line-color": "rgb(100,200,100)",
|
|
10
|
+
"line-width": 5,
|
|
11
|
+
};
|
|
12
|
+
case "circle":
|
|
13
|
+
default:
|
|
14
|
+
return {
|
|
15
|
+
"circle-color": "#44aaaa",
|
|
16
|
+
"circle-stroke-color": "#fff",
|
|
17
|
+
"circle-stroke-width": 2,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
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
|
)}
|