@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/dist/index.esm.js
CHANGED
|
@@ -38,14 +38,9 @@ function ownKeys(object, enumerableOnly) {
|
|
|
38
38
|
|
|
39
39
|
if (Object.getOwnPropertySymbols) {
|
|
40
40
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
keys.push.apply(keys, symbols);
|
|
41
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
42
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
43
|
+
})), keys.push.apply(keys, symbols);
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
return keys;
|
|
@@ -53,19 +48,12 @@ function ownKeys(object, enumerableOnly) {
|
|
|
53
48
|
|
|
54
49
|
function _objectSpread2(target) {
|
|
55
50
|
for (var i = 1; i < arguments.length; i++) {
|
|
56
|
-
var source = arguments[i]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
63
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
64
|
-
} else {
|
|
65
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
66
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
51
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
52
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
53
|
+
_defineProperty(target, key, source[key]);
|
|
54
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
55
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
56
|
+
});
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
return target;
|
|
@@ -74,17 +62,11 @@ function _objectSpread2(target) {
|
|
|
74
62
|
function _typeof(obj) {
|
|
75
63
|
"@babel/helpers - typeof";
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
_typeof = function (obj) {
|
|
83
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return _typeof(obj);
|
|
65
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
66
|
+
return typeof obj;
|
|
67
|
+
} : function (obj) {
|
|
68
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
69
|
+
}, _typeof(obj);
|
|
88
70
|
}
|
|
89
71
|
|
|
90
72
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -319,6 +301,8 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
|
|
|
319
301
|
if (!Object.is(item.handler, handler)) {
|
|
320
302
|
return item;
|
|
321
303
|
}
|
|
304
|
+
|
|
305
|
+
return false;
|
|
322
306
|
});
|
|
323
307
|
},
|
|
324
308
|
|
|
@@ -366,12 +350,12 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
|
|
|
366
350
|
//if (self.baseLayers.indexOf(layer.id) === -1) {
|
|
367
351
|
var paint = {};
|
|
368
352
|
var values = (_layer$paint = layer.paint) === null || _layer$paint === void 0 ? void 0 : _layer$paint._values;
|
|
369
|
-
Object.keys(values || {}).
|
|
353
|
+
Object.keys(values || {}).forEach(function (propName) {
|
|
370
354
|
paint[propName] = typeof values[propName].value !== "undefined" ? values[propName].value.value : values[propName];
|
|
371
355
|
});
|
|
372
356
|
var layout = {};
|
|
373
357
|
values = (_layer$layout = layer.layout) === null || _layer$layout === void 0 ? void 0 : _layer$layout._values;
|
|
374
|
-
Object.keys(values || {}).
|
|
358
|
+
Object.keys(values || {}).forEach(function (propName) {
|
|
375
359
|
layout[propName] = typeof values[propName].value !== "undefined" ? values[propName].value.value : values[propName];
|
|
376
360
|
});
|
|
377
361
|
return {
|
|
@@ -868,20 +852,15 @@ function useMapState(props) {
|
|
|
868
852
|
|
|
869
853
|
var _useState = useState(undefined),
|
|
870
854
|
_useState2 = _slicedToArray(_useState, 2),
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
var _useState3 = useState(undefined),
|
|
875
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
876
|
-
viewport = _useState4[0],
|
|
877
|
-
setViewport = _useState4[1];
|
|
855
|
+
viewport = _useState2[0],
|
|
856
|
+
setViewport = _useState2[1];
|
|
878
857
|
|
|
879
858
|
var viewportRef = useRef(undefined);
|
|
880
859
|
|
|
881
|
-
var
|
|
882
|
-
|
|
883
|
-
layers =
|
|
884
|
-
setLayers =
|
|
860
|
+
var _useState3 = useState(undefined),
|
|
861
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
862
|
+
layers = _useState4[0],
|
|
863
|
+
setLayers = _useState4[1];
|
|
885
864
|
|
|
886
865
|
var layersRef = useRef(undefined); //const mapRef = useRef(props.map);
|
|
887
866
|
|
|
@@ -939,15 +918,6 @@ function useMapState(props) {
|
|
|
939
918
|
|
|
940
919
|
initializedRef.current = true;
|
|
941
920
|
mapRef.current = mapContext.getMap(props.mapId);
|
|
942
|
-
/*
|
|
943
|
-
mapRef.current.on(
|
|
944
|
-
"move",
|
|
945
|
-
() => {
|
|
946
|
-
setCenter(mapRef.current.getCenter());
|
|
947
|
-
},
|
|
948
|
-
componentId.current
|
|
949
|
-
);
|
|
950
|
-
*/
|
|
951
921
|
|
|
952
922
|
if (props !== null && props !== void 0 && (_props$watch = props.watch) !== null && _props$watch !== void 0 && _props$watch.viewport) {
|
|
953
923
|
setViewport(mapRef.current.wrapper.viewportState);
|
|
@@ -955,10 +925,9 @@ function useMapState(props) {
|
|
|
955
925
|
var _mapRef$current;
|
|
956
926
|
|
|
957
927
|
if (viewportRef.current !== ((_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.wrapper.viewportStateString)) {
|
|
958
|
-
var _mapRef$current2
|
|
928
|
+
var _mapRef$current2;
|
|
959
929
|
|
|
960
930
|
setViewport((_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.wrapper.viewportState);
|
|
961
|
-
setCenter((_mapRef$current3 = mapRef.current) === null || _mapRef$current3 === void 0 ? void 0 : (_mapRef$current3$wrap = _mapRef$current3.wrapper.viewportState) === null || _mapRef$current3$wrap === void 0 ? void 0 : _mapRef$current3$wrap.center);
|
|
962
931
|
}
|
|
963
932
|
}, componentId.current);
|
|
964
933
|
}
|
|
@@ -1102,7 +1071,7 @@ var MlComponentTemplate = function MlComponentTemplate(props) {
|
|
|
1102
1071
|
|
|
1103
1072
|
initializedRef.current = true;
|
|
1104
1073
|
mapHook.map.setCenter([7.132122000552613, 50.716405378037706]);
|
|
1105
|
-
}, [mapHook.map, props.mapId]);
|
|
1074
|
+
}, [mapHook.map, mapHook.mapIsReady, props.mapId]);
|
|
1106
1075
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
|
|
1107
1076
|
};
|
|
1108
1077
|
|
|
@@ -1412,7 +1381,70 @@ var _transitionToGeojson = function _transitionToGeojson(newGeojson, props, tran
|
|
|
1412
1381
|
}, msPerStep);
|
|
1413
1382
|
};
|
|
1414
1383
|
|
|
1384
|
+
var getDefaultPaintPropsByType = function getDefaultPaintPropsByType(type, defaultPaintOverrides) {
|
|
1385
|
+
switch (type) {
|
|
1386
|
+
case "fill":
|
|
1387
|
+
if (defaultPaintOverrides !== null && defaultPaintOverrides !== void 0 && defaultPaintOverrides.fill) {
|
|
1388
|
+
return defaultPaintOverrides.fill;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
return {
|
|
1392
|
+
"fill-color": "rgba(10,240,256,0.6)"
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
case "line":
|
|
1396
|
+
if (defaultPaintOverrides !== null && defaultPaintOverrides !== void 0 && defaultPaintOverrides.line) {
|
|
1397
|
+
return defaultPaintOverrides.line;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
return {
|
|
1401
|
+
"line-color": "rgb(100,200,100)",
|
|
1402
|
+
"line-width": 5
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
case "circle":
|
|
1406
|
+
default:
|
|
1407
|
+
if (defaultPaintOverrides !== null && defaultPaintOverrides !== void 0 && defaultPaintOverrides.circle) {
|
|
1408
|
+
return defaultPaintOverrides.circle;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
return {
|
|
1412
|
+
"circle-color": "#44aaaa",
|
|
1413
|
+
"circle-stroke-color": "#fff",
|
|
1414
|
+
"circle-stroke-width": 2
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
var mapGeometryTypesToLayerTypes = {
|
|
1420
|
+
Position: "circle",
|
|
1421
|
+
Point: "circle",
|
|
1422
|
+
MultiPoint: "circle",
|
|
1423
|
+
LineString: "line",
|
|
1424
|
+
MultiLineString: "line",
|
|
1425
|
+
Polygon: "fill",
|
|
1426
|
+
MultiPolygon: "fill",
|
|
1427
|
+
GeometryCollection: "circle"
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
var getDefaulLayerTypeByGeometry = function getDefaulLayerTypeByGeometry(geojson) {
|
|
1431
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
|
|
1432
|
+
var _geojson$geometry;
|
|
1433
|
+
|
|
1434
|
+
return mapGeometryTypesToLayerTypes !== null && mapGeometryTypesToLayerTypes !== void 0 && mapGeometryTypesToLayerTypes[geojson === null || geojson === void 0 ? void 0 : (_geojson$geometry = geojson.geometry) === null || _geojson$geometry === void 0 ? void 0 : _geojson$geometry.type] ? mapGeometryTypesToLayerTypes[geojson.geometry.type] : "circle";
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
|
|
1438
|
+
if (geojson.features.length) {
|
|
1439
|
+
return getDefaulLayerTypeByGeometry(geojson.features[0]);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
return "circle";
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1415
1446
|
var msPerStep = 50;
|
|
1447
|
+
var legalLayerTypes = ["circle", "fill", "line"];
|
|
1416
1448
|
/**
|
|
1417
1449
|
* Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
|
|
1418
1450
|
*
|
|
@@ -1421,61 +1453,51 @@ var msPerStep = 50;
|
|
|
1421
1453
|
|
|
1422
1454
|
var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
|
|
1423
1455
|
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
1424
|
-
var
|
|
1425
|
-
var mapState = useMapState({
|
|
1456
|
+
var mapHook = useMap({
|
|
1426
1457
|
mapId: props.mapId,
|
|
1427
|
-
|
|
1428
|
-
viewport: false,
|
|
1429
|
-
layers: true,
|
|
1430
|
-
sources: false
|
|
1431
|
-
}
|
|
1458
|
+
waitForLayer: props.insertBeforeLayer
|
|
1432
1459
|
});
|
|
1433
|
-
var oldGeojsonRef = useRef(null);
|
|
1434
|
-
var mapRef = useRef(null);
|
|
1435
1460
|
var initializedRef = useRef(false);
|
|
1461
|
+
var layerId = useRef(props.layerId || "MlGeoJsonLayer-" + mapHook.componentId);
|
|
1462
|
+
var layerTypeRef = useRef(undefined); // transition effect variables
|
|
1463
|
+
|
|
1464
|
+
var oldGeojsonRef = useRef(null);
|
|
1436
1465
|
var transitionInProgressRef = useRef(false);
|
|
1437
1466
|
var transitionTimeoutRef = useRef(undefined);
|
|
1438
1467
|
var currentTransitionStepRef = useRef(false);
|
|
1439
1468
|
var transitionGeojsonDataRef = useRef([]);
|
|
1440
1469
|
var transitionGeojsonCommonDataRef = useRef([]);
|
|
1441
|
-
var componentId = useRef((props.layerId ? props.layerId : "MlGeoJsonLayer-") + (props.idSuffix || v4()));
|
|
1442
|
-
var layerId = useRef(props.layerId || componentId.current);
|
|
1443
1470
|
useEffect(function () {
|
|
1444
|
-
var _componentId = componentId.current;
|
|
1445
1471
|
return function () {
|
|
1446
1472
|
// This is the cleanup function, it is called when this react component is removed from react-dom
|
|
1447
1473
|
if (transitionTimeoutRef.current) {
|
|
1448
1474
|
clearTimeout(transitionTimeoutRef.current);
|
|
1449
1475
|
}
|
|
1450
|
-
|
|
1451
|
-
if (mapRef.current) {
|
|
1452
|
-
mapRef.current.cleanup(_componentId);
|
|
1453
|
-
mapRef.current = null;
|
|
1454
|
-
}
|
|
1455
1476
|
};
|
|
1456
1477
|
}, []);
|
|
1457
1478
|
useEffect(function () {
|
|
1458
|
-
if (!
|
|
1479
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
1459
1480
|
|
|
1460
1481
|
for (var key in props.layout) {
|
|
1461
|
-
|
|
1482
|
+
mapHook.map.setLayoutProperty(layerId.current, key, props.layout[key]);
|
|
1462
1483
|
}
|
|
1463
|
-
}, [props.layout,
|
|
1484
|
+
}, [props.layout, mapHook.map, props.mapId]);
|
|
1464
1485
|
useEffect(function () {
|
|
1465
|
-
if (!
|
|
1486
|
+
if (!mapHook.map || !initializedRef.current) return;
|
|
1487
|
+
|
|
1488
|
+
var _paint = props.paint || getDefaultPaintPropsByType(layerTypeRef.current, props.defaultPaintOverrides);
|
|
1466
1489
|
|
|
1467
|
-
for (var key in
|
|
1468
|
-
|
|
1490
|
+
for (var key in _paint) {
|
|
1491
|
+
mapHook.map.setPaintProperty(layerId.current, key, _paint[key]);
|
|
1469
1492
|
}
|
|
1470
|
-
}, [props.paint,
|
|
1493
|
+
}, [props.paint, mapHook.map, props.mapId, props.defaultPaintOverrides]);
|
|
1471
1494
|
var transitionToGeojson = useCallback(function (newGeojson) {
|
|
1472
|
-
_transitionToGeojson(newGeojson, props, transitionGeojsonCommonDataRef, transitionGeojsonDataRef, transitionInProgressRef, oldGeojsonRef, msPerStep, currentTransitionStepRef,
|
|
1473
|
-
}, [props]);
|
|
1495
|
+
_transitionToGeojson(newGeojson, props, transitionGeojsonCommonDataRef, transitionGeojsonDataRef, transitionInProgressRef, oldGeojsonRef, msPerStep, currentTransitionStepRef, mapHook.map, layerId.current, transitionTimeoutRef);
|
|
1496
|
+
}, [props, mapHook.map]);
|
|
1474
1497
|
useEffect(function () {
|
|
1475
|
-
var
|
|
1498
|
+
var _mapHook$map;
|
|
1476
1499
|
|
|
1477
|
-
if (!(
|
|
1478
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
1500
|
+
if (!(mapHook !== null && mapHook !== void 0 && (_mapHook$map = mapHook.map) !== null && _mapHook$map !== void 0 && _mapHook$map.getSource(layerId.current)) || !initializedRef.current) return;
|
|
1479
1501
|
|
|
1480
1502
|
if (typeof props.transitionTime !== "undefined" && props.type === "line" && oldGeojsonRef.current) {
|
|
1481
1503
|
transitionInProgressRef.current = false;
|
|
@@ -1484,73 +1506,61 @@ var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
|
|
|
1484
1506
|
transitionGeojsonCommonDataRef.current = [];
|
|
1485
1507
|
transitionToGeojson(props.geojson);
|
|
1486
1508
|
} else {
|
|
1487
|
-
|
|
1509
|
+
mapHook.map.getSource(layerId.current).setData(props.geojson);
|
|
1488
1510
|
}
|
|
1489
1511
|
|
|
1490
1512
|
oldGeojsonRef.current = props.geojson;
|
|
1491
|
-
}, [props.geojson, props.mapId,
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
1513
|
+
}, [props.geojson, props.mapId, mapHook.map, props.type, transitionToGeojson, props.transitionTime]);
|
|
1514
|
+
var createLayer = useCallback(function () {
|
|
1515
|
+
var geojson = props.geojson;
|
|
1495
1516
|
|
|
1496
|
-
if (props.geojson) {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1517
|
+
if (props.type === "line" && typeof props.transitionTime !== "undefined" && props.transitionTime && typeof props.geojson.geometry !== "undefined") {
|
|
1518
|
+
var tmpChunks = lineChunk(props.geojson, 0.01);
|
|
1519
|
+
geojson = tmpChunks.features[0];
|
|
1520
|
+
}
|
|
1500
1521
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1522
|
+
layerTypeRef.current = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
1523
|
+
mapHook.map.addLayer(_objectSpread2({
|
|
1524
|
+
id: layerId.current,
|
|
1525
|
+
source: {
|
|
1526
|
+
type: "geojson",
|
|
1527
|
+
data: geojson
|
|
1528
|
+
},
|
|
1529
|
+
type: layerTypeRef.current,
|
|
1530
|
+
paint: props.paint || getDefaultPaintPropsByType(layerTypeRef.current, props.defaultPaintOverrides),
|
|
1531
|
+
layout: props.layout || {}
|
|
1532
|
+
}, props.options), props.insertBeforeLayer, mapHook.componentId);
|
|
1507
1533
|
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1534
|
+
if (typeof props.onHover !== "undefined") {
|
|
1535
|
+
mapHook.map.on("mousemove", mapHook.componentId, props.onHover, mapHook.componentId);
|
|
1536
|
+
}
|
|
1512
1537
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1538
|
+
if (typeof props.onClick !== "undefined") {
|
|
1539
|
+
mapHook.map.on("click", mapHook.componentId, props.onClick, mapHook.componentId);
|
|
1540
|
+
}
|
|
1515
1541
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1542
|
+
if (typeof props.onLeave !== "undefined") {
|
|
1543
|
+
mapHook.map.on("mouseleave", mapHook.componentId, props.onLeave, mapHook.componentId);
|
|
1544
|
+
}
|
|
1520
1545
|
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
type: props.type || "line",
|
|
1529
|
-
paint: props.paint || {
|
|
1530
|
-
"line-color": "rgb(100,200,100)",
|
|
1531
|
-
"line-width": 10
|
|
1532
|
-
},
|
|
1533
|
-
layout: props.layout || {}
|
|
1534
|
-
}, props.insertBeforeLayer, componentId.current);
|
|
1535
|
-
|
|
1536
|
-
if (typeof props.onHover !== "undefined") {
|
|
1537
|
-
mapRef.current.on("mousemove", componentId.current, props.onHover, componentId.current);
|
|
1538
|
-
}
|
|
1546
|
+
if (props.type === "line" && typeof props.transitionTime !== "undefined" && typeof props.geojson.geometry !== "undefined") {
|
|
1547
|
+
transitionToGeojson(props.geojson);
|
|
1548
|
+
oldGeojsonRef.current = props.geojson;
|
|
1549
|
+
}
|
|
1550
|
+
}, [mapHook.map, props, transitionToGeojson]);
|
|
1551
|
+
useEffect(function () {
|
|
1552
|
+
if (!mapHook.mapIsReady || !props.geojson) return;
|
|
1539
1553
|
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1554
|
+
if (initializedRef.current && legalLayerTypes.indexOf(props.type) !== -1 && layerTypeRef.current && props.type !== layerTypeRef.current) {
|
|
1555
|
+
mapHook.map.cleanup(mapHook.componentId);
|
|
1556
|
+
} else if (initializedRef.current && (legalLayerTypes.indexOf(props.type) === -1 || legalLayerTypes.indexOf(props.type) !== -1 && props.type === layerTypeRef.current)) {
|
|
1557
|
+
return;
|
|
1558
|
+
} // initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
1543
1559
|
|
|
1544
|
-
if (typeof props.onLeave !== "undefined") {
|
|
1545
|
-
mapRef.current.on("mouseleave", componentId.current, props.onLeave, componentId.current);
|
|
1546
|
-
}
|
|
1547
1560
|
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}, [mapContext.mapIds, mapContext, props, transitionToGeojson, mapState.layers]);
|
|
1561
|
+
initializedRef.current = true;
|
|
1562
|
+
createLayer();
|
|
1563
|
+
}, [mapHook.mapIsReady, createLayer, props]);
|
|
1554
1564
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
|
|
1555
1565
|
};
|
|
1556
1566
|
|
|
@@ -1584,6 +1594,16 @@ MlGeoJsonLayer.propTypes = {
|
|
|
1584
1594
|
*/
|
|
1585
1595
|
paint: PropTypes.object,
|
|
1586
1596
|
|
|
1597
|
+
/**
|
|
1598
|
+
* Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
|
|
1599
|
+
*/
|
|
1600
|
+
defaultPaintOverrides: PropTypes.object,
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Javascript object that is spread into the addLayer commands first parameter.
|
|
1604
|
+
*/
|
|
1605
|
+
options: PropTypes.object,
|
|
1606
|
+
|
|
1587
1607
|
/**
|
|
1588
1608
|
* GeoJSON data that is supposed to be rendered by this component.
|
|
1589
1609
|
*/
|
|
@@ -1620,13 +1640,7 @@ MlGeoJsonLayer.propTypes = {
|
|
|
1620
1640
|
* Creates transition animation whenever the geojson prop changes.
|
|
1621
1641
|
* Only works with layer type "line" and LineString GeoJSON data.
|
|
1622
1642
|
*/
|
|
1623
|
-
transitionTime: PropTypes.number
|
|
1624
|
-
|
|
1625
|
-
/**
|
|
1626
|
-
* Id suffix string that is appended to the componentId.
|
|
1627
|
-
* Probably removed soon.
|
|
1628
|
-
*/
|
|
1629
|
-
idSuffix: PropTypes.string
|
|
1643
|
+
transitionTime: PropTypes.number
|
|
1630
1644
|
};
|
|
1631
1645
|
|
|
1632
1646
|
var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
|
|
@@ -2483,7 +2497,6 @@ var MlLayer = function MlLayer(props) {
|
|
|
2483
2497
|
var layerInitializedRef = useRef(false);
|
|
2484
2498
|
var mapRef = useRef(null);
|
|
2485
2499
|
var componentId = useRef((props.layerId ? props.layerId : "MlLayer-") + v4());
|
|
2486
|
-
var idSuffixRef = useRef(props.idSuffix || new Date().getTime());
|
|
2487
2500
|
var layerId = useRef(props.layerId || componentId.current);
|
|
2488
2501
|
var layerPaintConfRef = useRef(undefined);
|
|
2489
2502
|
var layerLayoutConfRef = useRef(undefined);
|
|
@@ -2693,13 +2706,12 @@ var MlVectorTileLayer = function MlVectorTileLayer(props) {
|
|
|
2693
2706
|
initializedRef.current = true;
|
|
2694
2707
|
mapRef.current = mapContext.getMap(props.mapId); // Add the new layer to the openlayers instance once it is available
|
|
2695
2708
|
|
|
2696
|
-
mapRef.current.addSource(sourceName + idSuffixRef.current, {
|
|
2709
|
+
mapRef.current.addSource(sourceName + idSuffixRef.current, _objectSpread2({
|
|
2697
2710
|
type: "vector",
|
|
2698
2711
|
tiles: [props.url],
|
|
2699
2712
|
tileSize: 512,
|
|
2700
|
-
attribution: ""
|
|
2701
|
-
|
|
2702
|
-
});
|
|
2713
|
+
attribution: ""
|
|
2714
|
+
}, props.sourceOptions));
|
|
2703
2715
|
|
|
2704
2716
|
for (var key in props.layers) {
|
|
2705
2717
|
var layerId = layerName + "_" + key + "_" + idSuffixRef.current;
|