@mapcomponents/react-maplibre 0.1.91 → 0.1.94
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
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [v0.1.93] - 2024-01-17
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- 0af148b: remove conditional use of useLayer hook for label layer in MlGeoJsonLayer
|
|
8
|
+
- 718afe6: fix useSource cleanup error
|
|
9
|
+
- c6856e6: fix MlTemporalController to work with useLayer, MlGeoJsonLayer adjustments
|
|
10
|
+
|
|
11
|
+
## [v0.1.92] - 2024-01-16
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- fe33641: fix useSource hook to dynamically adjust to props.sourceId changes
|
|
16
|
+
- fe33641: fix useMap hook to use less setState calls
|
|
17
|
+
- fe33641: fix useLayer hook options.source prop to wait for the source to be added
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- fe33641: add MlGeoJsonLayer labelProp defaults to enable simply passing the property name to props.labelProp to get labels.
|
|
22
|
+
- fe33641: make label layer use the same source as the main layer.
|
|
23
|
+
- fe33641: adjust MlGeoJsonLayer labelProp storybook demo to show the actual use of the property
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## [v0.1.91] - 2024-01-16
|
|
4
27
|
|
|
5
28
|
### Fixed
|
|
@@ -21,7 +21,7 @@ export type MlGeoJsonLayerProps = {
|
|
|
21
21
|
/**
|
|
22
22
|
* GeoJSON data that is supposed to be rendered by this component.
|
|
23
23
|
*/
|
|
24
|
-
geojson
|
|
24
|
+
geojson?: Feature | FeatureCollection | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* Type of the layer that will be added to the MapLibre instance.
|
|
27
27
|
* All types from LayerSpecification union type are supported except the type from
|
|
@@ -29,6 +29,7 @@ export type MlGeoJsonLayerProps = {
|
|
|
29
29
|
*/
|
|
30
30
|
type?: Exclude<LayerSpecification['type'], RasterLayerSpecification['type']>;
|
|
31
31
|
/**
|
|
32
|
+
* @deprecated The property should not be used. Please use the options.paint property instead. This will be removed in the next major release.
|
|
32
33
|
* Paint property object, that is passed to the addLayer call.
|
|
33
34
|
* Possible props depend on the layer type.
|
|
34
35
|
* See https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/
|
|
@@ -41,6 +42,7 @@ export type MlGeoJsonLayerProps = {
|
|
|
41
42
|
*/
|
|
42
43
|
paint?: Exclude<LayerSpecification['paint'], RasterLayerSpecification['paint']>;
|
|
43
44
|
/**
|
|
45
|
+
* @deprecated The property should not be used. Please use the options.layout property instead. This will be removed in the next major release.
|
|
44
46
|
* Layout property object, that is passed to the addLayer call.
|
|
45
47
|
* Possible props depend on the layer type.
|
|
46
48
|
* See https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/
|
package/dist/hooks/useLayer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMapType } from './useMap';
|
|
2
|
-
import {
|
|
2
|
+
import { GeoJSONSourceSpecification, LayerSpecification, MapMouseEvent, GeoJSONFeature, Style, MapEventType, Map, FilterSpecification } from 'maplibre-gl';
|
|
3
3
|
import MapLibreGlWrapper from '../components/MapLibreMap/lib/MapLibreGlWrapper';
|
|
4
4
|
import { GeoJSONObject } from '@turf/turf';
|
|
5
5
|
type getLayerType = Style['getLayer'];
|
|
@@ -21,8 +21,9 @@ export interface useLayerProps {
|
|
|
21
21
|
insertBeforeFirstSymbolLayer?: boolean;
|
|
22
22
|
geojson?: GeoJSONObject;
|
|
23
23
|
options: Partial<LayerSpecification & {
|
|
24
|
-
source?:
|
|
24
|
+
source?: GeoJSONSourceSpecification | string;
|
|
25
25
|
id?: string;
|
|
26
|
+
filter?: FilterSpecification;
|
|
26
27
|
}>;
|
|
27
28
|
onHover?: (ev: MapEventType & unknown) => Map | void;
|
|
28
29
|
onClick?: (ev: MapEventType & unknown) => Map | void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useMapType } from
|
|
2
|
-
import MapLibreGlWrapper from
|
|
3
|
-
import { Source, SourceSpecification } from
|
|
1
|
+
import { useMapType } from './useMap';
|
|
2
|
+
import MapLibreGlWrapper from '../components/MapLibreMap/lib/MapLibreGlWrapper';
|
|
3
|
+
import { Source, SourceSpecification } from 'maplibre-gl';
|
|
4
4
|
type useSourceType = {
|
|
5
5
|
map: MapLibreGlWrapper | undefined;
|
|
6
6
|
source: Source | undefined;
|
package/dist/index.esm.js
CHANGED
|
@@ -1320,7 +1320,7 @@ useMapState.propTypes = {
|
|
|
1320
1320
|
|
|
1321
1321
|
function useMap(props) {
|
|
1322
1322
|
var mapContext = React.useContext(MapContext);
|
|
1323
|
-
var _a = React.useState(),
|
|
1323
|
+
var _a = React.useState({ map: undefined, ready: false }), state = _a[0], setState = _a[1];
|
|
1324
1324
|
var mapState = useMapState({
|
|
1325
1325
|
mapId: props === null || props === void 0 ? void 0 : props.mapId,
|
|
1326
1326
|
watch: {
|
|
@@ -1334,7 +1334,6 @@ function useMap(props) {
|
|
|
1334
1334
|
});
|
|
1335
1335
|
var mapRef = React.useRef();
|
|
1336
1336
|
var componentId = React.useRef(uuid.v4());
|
|
1337
|
-
var _b = React.useState(false), mapIsReady = _b[0], setMapIsReady = _b[1];
|
|
1338
1337
|
var cleanup = function () {
|
|
1339
1338
|
if (mapRef.current) {
|
|
1340
1339
|
mapRef.current.cleanup(componentId.current);
|
|
@@ -1343,7 +1342,6 @@ function useMap(props) {
|
|
|
1343
1342
|
React.useEffect(function () {
|
|
1344
1343
|
return function () {
|
|
1345
1344
|
cleanup();
|
|
1346
|
-
setMapIsReady(false);
|
|
1347
1345
|
mapRef.current = undefined;
|
|
1348
1346
|
};
|
|
1349
1347
|
}, []);
|
|
@@ -1351,8 +1349,7 @@ function useMap(props) {
|
|
|
1351
1349
|
var _a;
|
|
1352
1350
|
if (mapRef.current && mapRef.current.cancelled === true) {
|
|
1353
1351
|
mapRef.current = undefined;
|
|
1354
|
-
|
|
1355
|
-
setMapIsReady(false);
|
|
1352
|
+
setState({ map: undefined, ready: false });
|
|
1356
1353
|
}
|
|
1357
1354
|
if (mapRef.current || !mapContext.mapExists(props === null || props === void 0 ? void 0 : props.mapId))
|
|
1358
1355
|
return;
|
|
@@ -1370,12 +1367,11 @@ function useMap(props) {
|
|
|
1370
1367
|
}
|
|
1371
1368
|
}
|
|
1372
1369
|
mapRef.current = mapContext.getMap(props === null || props === void 0 ? void 0 : props.mapId);
|
|
1373
|
-
|
|
1374
|
-
setMapIsReady(true);
|
|
1370
|
+
setState({ map: mapRef.current, ready: true });
|
|
1375
1371
|
}, [mapContext.mapIds, mapState.layers, mapContext, props]);
|
|
1376
1372
|
return {
|
|
1377
|
-
map: map,
|
|
1378
|
-
mapIsReady:
|
|
1373
|
+
map: state.map,
|
|
1374
|
+
mapIsReady: state.ready,
|
|
1379
1375
|
componentId: componentId.current,
|
|
1380
1376
|
layers: mapState.layers,
|
|
1381
1377
|
cleanup: cleanup,
|
|
@@ -2429,6 +2425,7 @@ var legalLayerTypes = [
|
|
|
2429
2425
|
'background',
|
|
2430
2426
|
];
|
|
2431
2427
|
function useLayer(props) {
|
|
2428
|
+
var _a;
|
|
2432
2429
|
var mapHook = useMap({
|
|
2433
2430
|
mapId: props.mapId,
|
|
2434
2431
|
waitForLayer: props.insertBeforeLayer,
|
|
@@ -2436,17 +2433,17 @@ function useLayer(props) {
|
|
|
2436
2433
|
var layerTypeRef = React.useRef('');
|
|
2437
2434
|
var layerPaintConfRef = React.useRef('');
|
|
2438
2435
|
var layerLayoutConfRef = React.useRef('');
|
|
2439
|
-
var
|
|
2436
|
+
var _b = React.useState(), layer = _b[0], setLayer = _b[1];
|
|
2440
2437
|
var initializedRef = React.useRef(false);
|
|
2441
2438
|
var layerId = React.useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
|
|
2442
2439
|
var createLayer = React.useCallback(function () {
|
|
2443
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2440
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
2444
2441
|
if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
|
|
2445
2442
|
return;
|
|
2446
2443
|
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
2447
2444
|
mapHook.cleanup();
|
|
2448
2445
|
}
|
|
2449
|
-
if (mapHook.map.map.getSource(layerId.current)) {
|
|
2446
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' && mapHook.map.map.getSource(layerId.current)) {
|
|
2450
2447
|
mapHook.map.map.removeSource(layerId.current);
|
|
2451
2448
|
}
|
|
2452
2449
|
if (typeof props.options.source === 'string') {
|
|
@@ -2454,26 +2451,35 @@ function useLayer(props) {
|
|
|
2454
2451
|
return;
|
|
2455
2452
|
}
|
|
2456
2453
|
}
|
|
2454
|
+
if (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
|
|
2455
|
+
!props.geojson &&
|
|
2456
|
+
!((_d = (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.data)) {
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2457
2459
|
if (typeof props.options.type === 'undefined') {
|
|
2458
2460
|
return;
|
|
2459
2461
|
}
|
|
2460
2462
|
initializedRef.current = true;
|
|
2461
2463
|
try {
|
|
2462
2464
|
mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson &&
|
|
2463
|
-
(!((
|
|
2464
|
-
(((
|
|
2465
|
+
(!((_e = props.options) === null || _e === void 0 ? void 0 : _e.source) ||
|
|
2466
|
+
(typeof ((_f = props === null || props === void 0 ? void 0 : props.options) === null || _f === void 0 ? void 0 : _f.source) !== 'string' &&
|
|
2467
|
+
((_h = (_g = props.options) === null || _g === void 0 ? void 0 : _g.source) === null || _h === void 0 ? void 0 : _h.attribution) &&
|
|
2468
|
+
!((_k = (_j = props.options) === null || _j === void 0 ? void 0 : _j.source) === null || _k === void 0 ? void 0 : _k.type))) // if either options.source isn't defined or only options.source.attribution is defined
|
|
2465
2469
|
? {
|
|
2466
2470
|
source: {
|
|
2467
2471
|
type: 'geojson',
|
|
2468
2472
|
data: props.geojson,
|
|
2469
|
-
attribution: ((
|
|
2470
|
-
? (
|
|
2473
|
+
attribution: typeof ((_l = props === null || props === void 0 ? void 0 : props.options) === null || _l === void 0 ? void 0 : _l.source) !== 'string' && ((_m = props.options.source) === null || _m === void 0 ? void 0 : _m.attribution)
|
|
2474
|
+
? (_o = props.options.source) === null || _o === void 0 ? void 0 : _o.attribution
|
|
2471
2475
|
: '',
|
|
2472
2476
|
},
|
|
2477
|
+
// eslint-disable-next-line no-mixed-spaces-and-tabs
|
|
2473
2478
|
}
|
|
2474
|
-
: {})), (typeof ((
|
|
2479
|
+
: {})), (typeof ((_p = props.options) === null || _p === void 0 ? void 0 : _p.source) === 'string'
|
|
2475
2480
|
? {
|
|
2476
2481
|
source: props.options.source,
|
|
2482
|
+
// eslint-disable-next-line no-mixed-spaces-and-tabs
|
|
2477
2483
|
}
|
|
2478
2484
|
: {})), { id: layerId.current }), props.insertBeforeLayer
|
|
2479
2485
|
? props.insertBeforeLayer
|
|
@@ -2498,18 +2504,19 @@ function useLayer(props) {
|
|
|
2498
2504
|
mapHook.map.on('styledata', function () {
|
|
2499
2505
|
var _a;
|
|
2500
2506
|
if (initializedRef.current && !((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
|
|
2501
|
-
console.log('Recreate Layer');
|
|
2502
2507
|
createLayer();
|
|
2503
2508
|
}
|
|
2504
2509
|
}, mapHook.componentId);
|
|
2505
|
-
layerPaintConfRef.current = JSON.stringify((
|
|
2506
|
-
layerLayoutConfRef.current = JSON.stringify((
|
|
2510
|
+
layerPaintConfRef.current = JSON.stringify((_q = props.options) === null || _q === void 0 ? void 0 : _q.paint);
|
|
2511
|
+
layerLayoutConfRef.current = JSON.stringify((_r = props.options) === null || _r === void 0 ? void 0 : _r.layout);
|
|
2507
2512
|
layerTypeRef.current = props.options.type;
|
|
2508
|
-
}, [props, mapHook
|
|
2513
|
+
}, [props, mapHook]);
|
|
2509
2514
|
React.useEffect(function () {
|
|
2510
2515
|
var _a, _b, _c, _d;
|
|
2511
2516
|
if (!mapHook.map)
|
|
2512
2517
|
return;
|
|
2518
|
+
if (!props.geojson && !props.options.source)
|
|
2519
|
+
return;
|
|
2513
2520
|
if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === false &&
|
|
2514
2521
|
initializedRef.current &&
|
|
2515
2522
|
((_d = (_c = (_b = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getLayer) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)) &&
|
|
@@ -2519,7 +2526,7 @@ function useLayer(props) {
|
|
|
2519
2526
|
return;
|
|
2520
2527
|
}
|
|
2521
2528
|
createLayer();
|
|
2522
|
-
}, [mapHook.map,
|
|
2529
|
+
}, [mapHook.map, mapHook.mapIsReady, props, createLayer]);
|
|
2523
2530
|
React.useEffect(function () {
|
|
2524
2531
|
var _a, _b, _c, _d, _e, _f;
|
|
2525
2532
|
if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
|
|
@@ -2574,6 +2581,29 @@ function useLayer(props) {
|
|
|
2574
2581
|
mapHook.cleanup();
|
|
2575
2582
|
};
|
|
2576
2583
|
}, []);
|
|
2584
|
+
React.useEffect(function () {
|
|
2585
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2586
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' ||
|
|
2587
|
+
!mapHook.map ||
|
|
2588
|
+
(typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
|
|
2589
|
+
((_d = (_c = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _c === void 0 ? void 0 : _c.getLayer) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)) &&
|
|
2590
|
+
((_f = (_e = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _e === void 0 ? void 0 : _e.getSource) === null || _f === void 0 ? void 0 : _f.call(_e, props.options.source)))) {
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2593
|
+
var findSourceHandler = function () {
|
|
2594
|
+
var _a, _b, _c;
|
|
2595
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) === 'string' &&
|
|
2596
|
+
((_c = (_b = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _b === void 0 ? void 0 : _b.getSource) === null || _c === void 0 ? void 0 : _c.call(_b, props.options.source))) {
|
|
2597
|
+
createLayer();
|
|
2598
|
+
}
|
|
2599
|
+
};
|
|
2600
|
+
mapHook.map.on('sourcedata', findSourceHandler);
|
|
2601
|
+
return function () {
|
|
2602
|
+
if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
|
|
2603
|
+
mapHook.map.off('sourcedata', findSourceHandler);
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
}, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
|
|
2577
2607
|
return {
|
|
2578
2608
|
map: mapHook.map,
|
|
2579
2609
|
layer: layer,
|
|
@@ -2680,35 +2710,115 @@ var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
|
2680
2710
|
return "fill";
|
|
2681
2711
|
};
|
|
2682
2712
|
|
|
2713
|
+
function useSource(props) {
|
|
2714
|
+
var _a;
|
|
2715
|
+
var mapHook = useMap({
|
|
2716
|
+
mapId: props.mapId,
|
|
2717
|
+
});
|
|
2718
|
+
var _b = React.useState(), source = _b[0], setSource = _b[1];
|
|
2719
|
+
var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
|
|
2720
|
+
var removeSource = React.useCallback(function () {
|
|
2721
|
+
var _a, _b;
|
|
2722
|
+
if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
|
|
2723
|
+
for (var _i = 0, _c = Object.entries(mapHook.map.map.style._layers); _i < _c.length; _i++) {
|
|
2724
|
+
var _d = _c[_i], layerId = _d[0], layer = _d[1];
|
|
2725
|
+
if (layer.source === sourceId.current) {
|
|
2726
|
+
mapHook.map.removeLayer(layerId);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
if (mapHook.map.getSource(sourceId.current)) {
|
|
2730
|
+
mapHook.map.removeSource(sourceId.current);
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
}, [mapHook.map]);
|
|
2734
|
+
var createSource = React.useCallback(function () {
|
|
2735
|
+
var _a;
|
|
2736
|
+
if (!mapHook.map)
|
|
2737
|
+
return;
|
|
2738
|
+
if (props.source.type === 'geojson' && !props.source.data)
|
|
2739
|
+
return;
|
|
2740
|
+
if (mapHook.map.map.getSource(sourceId.current)) {
|
|
2741
|
+
removeSource();
|
|
2742
|
+
}
|
|
2743
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source));
|
|
2744
|
+
setSource(mapHook.map.map.getSource(sourceId.current));
|
|
2745
|
+
}, [props, mapHook, removeSource]);
|
|
2746
|
+
React.useEffect(function () {
|
|
2747
|
+
var _a, _b, _c, _d;
|
|
2748
|
+
if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(sourceId.current)))
|
|
2749
|
+
return;
|
|
2750
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2751
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
2752
|
+
(_d = (_c = mapHook.map.map.getSource(sourceId.current)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.source.data);
|
|
2753
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2754
|
+
//@ts-ignore data only exists on GeoJsonSource
|
|
2755
|
+
}, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
|
|
2756
|
+
React.useEffect(function () {
|
|
2757
|
+
var _a, _b, _c;
|
|
2758
|
+
if (((_c = (_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource) === null || _c === void 0 ? void 0 : _c.call(_b, props.sourceId)) && props.sourceId === sourceId.current)
|
|
2759
|
+
return;
|
|
2760
|
+
sourceId.current = props.sourceId;
|
|
2761
|
+
createSource();
|
|
2762
|
+
}, [mapHook.map, props, createSource]);
|
|
2763
|
+
//cleanup
|
|
2764
|
+
React.useEffect(function () {
|
|
2765
|
+
return function () {
|
|
2766
|
+
removeSource();
|
|
2767
|
+
};
|
|
2768
|
+
}, [removeSource]);
|
|
2769
|
+
return {
|
|
2770
|
+
map: mapHook.map,
|
|
2771
|
+
source: source,
|
|
2772
|
+
componentId: mapHook.componentId,
|
|
2773
|
+
mapHook: mapHook,
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2683
2777
|
/**
|
|
2684
2778
|
* Adds source and layer to display GeoJSON data on the map.
|
|
2685
2779
|
*
|
|
2686
2780
|
* @component
|
|
2687
2781
|
*/
|
|
2688
2782
|
var MlGeoJsonLayer = function (props) {
|
|
2689
|
-
var _a, _b, _c;
|
|
2783
|
+
var _a, _b, _c, _d, _e;
|
|
2690
2784
|
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
2691
|
-
var layerId = props.layerId || 'MlGeoJsonLayer-' + uuid.v4();
|
|
2692
|
-
var labelLayerId = "label-".concat(layerId);
|
|
2693
|
-
|
|
2785
|
+
var layerId = React.useRef(props.layerId || 'MlGeoJsonLayer-' + uuid.v4());
|
|
2786
|
+
var labelLayerId = "label-".concat(layerId.current);
|
|
2787
|
+
React.useEffect(function () {
|
|
2788
|
+
if (!props.layerId) {
|
|
2789
|
+
layerId.current = 'MlGeoJsonLayer-' + uuid.v4();
|
|
2790
|
+
}
|
|
2791
|
+
else {
|
|
2792
|
+
layerId.current = props.layerId;
|
|
2793
|
+
}
|
|
2794
|
+
}, [props.layerId]);
|
|
2795
|
+
useSource({
|
|
2796
|
+
mapId: props.mapId,
|
|
2797
|
+
sourceId: "source-" + layerId.current,
|
|
2798
|
+
source: {
|
|
2799
|
+
type: 'geojson',
|
|
2800
|
+
data: props.geojson,
|
|
2801
|
+
},
|
|
2802
|
+
});
|
|
2694
2803
|
useLayer({
|
|
2695
2804
|
mapId: props.mapId,
|
|
2696
|
-
layerId:
|
|
2697
|
-
|
|
2698
|
-
options: __assign(__assign({}, props.options), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.layout), type: layerType }),
|
|
2805
|
+
layerId: layerId.current,
|
|
2806
|
+
options: __assign(__assign({ source: "source-" + layerId.current }, props.options), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.layout), type: layerType }),
|
|
2699
2807
|
insertBeforeLayer: props.insertBeforeLayer,
|
|
2700
2808
|
onHover: props.onHover,
|
|
2701
2809
|
onClick: props.onClick,
|
|
2702
2810
|
onLeave: props.onLeave,
|
|
2703
2811
|
});
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2812
|
+
// Label useLayer hook can't be called conditionally.
|
|
2813
|
+
// Using it with geojson and options.source undefined will cause it to return without creating a layer.
|
|
2814
|
+
useLayer({
|
|
2815
|
+
mapId: props.mapId,
|
|
2816
|
+
options: __assign(__assign(__assign({ source: props.labelProp ? "source-" + layerId.current : undefined, id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }, ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), (((_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_d = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _d === void 0 ? void 0 : _d.layout) ? props.labelOptions.layout : {})), (((_e = props === null || props === void 0 ? void 0 : props.layout) === null || _e === void 0 ? void 0 : _e.visibility) ? { visibility: props.layout.visibility } : {})), paint: {
|
|
2817
|
+
'text-halo-width': 1,
|
|
2818
|
+
'text-halo-color': '#fefefe',
|
|
2819
|
+
'text-color': '#121212',
|
|
2820
|
+
} }),
|
|
2821
|
+
});
|
|
2712
2822
|
return React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
2713
2823
|
};
|
|
2714
2824
|
|
|
@@ -4579,64 +4689,6 @@ useLayerHoverPopup.defaultProps = {
|
|
|
4579
4689
|
mapId: undefined,
|
|
4580
4690
|
};
|
|
4581
4691
|
|
|
4582
|
-
function useSource(props) {
|
|
4583
|
-
var _a;
|
|
4584
|
-
var mapHook = useMap({
|
|
4585
|
-
mapId: props.mapId,
|
|
4586
|
-
});
|
|
4587
|
-
var initializedRef = React.useRef(false);
|
|
4588
|
-
var _b = React.useState(), source = _b[0], setSource = _b[1];
|
|
4589
|
-
var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : "Source-") + mapHook.componentId);
|
|
4590
|
-
var createSource = React.useCallback(function () {
|
|
4591
|
-
var _a;
|
|
4592
|
-
if (!mapHook.map)
|
|
4593
|
-
return;
|
|
4594
|
-
initializedRef.current = true;
|
|
4595
|
-
if (mapHook.map.map.getSource(sourceId.current)) {
|
|
4596
|
-
mapHook.cleanup();
|
|
4597
|
-
}
|
|
4598
|
-
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source), mapHook.componentId);
|
|
4599
|
-
setSource(mapHook.map.map.getSource(sourceId.current));
|
|
4600
|
-
}, [props, mapHook.map]);
|
|
4601
|
-
React.useEffect(function () {
|
|
4602
|
-
if (!mapHook.map || initializedRef.current)
|
|
4603
|
-
return;
|
|
4604
|
-
createSource();
|
|
4605
|
-
}, [mapHook.map, props, createSource]);
|
|
4606
|
-
React.useEffect(function () {
|
|
4607
|
-
var _a, _b, _c, _d;
|
|
4608
|
-
if (!initializedRef.current || !((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(props.sourceId)))
|
|
4609
|
-
return;
|
|
4610
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4611
|
-
//@ts-ignore setData only exists on GeoJsonSource
|
|
4612
|
-
(_d = (_c = mapHook.map.map.getSource(props.sourceId)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.source.data);
|
|
4613
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4614
|
-
//@ts-ignore data only exists on GeoJsonSource
|
|
4615
|
-
}, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
|
|
4616
|
-
//cleanup
|
|
4617
|
-
React.useEffect(function () {
|
|
4618
|
-
return function () {
|
|
4619
|
-
var _a, _b, _c;
|
|
4620
|
-
initializedRef.current = false;
|
|
4621
|
-
if (mapHook.map && ((_c = (_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.style) === null || _c === void 0 ? void 0 : _c._layers)) {
|
|
4622
|
-
for (var _i = 0, _d = Object.entries(mapHook.map.map.style._layers); _i < _d.length; _i++) {
|
|
4623
|
-
var _e = _d[_i], layerId = _e[0], layer = _e[1];
|
|
4624
|
-
if (layer.source === sourceId.current) {
|
|
4625
|
-
mapHook.map.map.removeLayer(layerId);
|
|
4626
|
-
}
|
|
4627
|
-
}
|
|
4628
|
-
mapHook.map.map.removeSource(sourceId.current);
|
|
4629
|
-
}
|
|
4630
|
-
};
|
|
4631
|
-
}, [mapHook.map]);
|
|
4632
|
-
return {
|
|
4633
|
-
map: mapHook.map,
|
|
4634
|
-
source: source,
|
|
4635
|
-
componentId: mapHook.componentId,
|
|
4636
|
-
mapHook: mapHook,
|
|
4637
|
-
};
|
|
4638
|
-
}
|
|
4639
|
-
|
|
4640
4692
|
/**
|
|
4641
4693
|
* MlGpxViewer visualizes a given GPX Track on the map
|
|
4642
4694
|
*/
|
|
@@ -6215,13 +6267,18 @@ var MlTemporalController = function (props) {
|
|
|
6215
6267
|
};
|
|
6216
6268
|
}, [mapHook.map, props.onClick, props.onHover, props.onLeave]);
|
|
6217
6269
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
6218
|
-
filteredData && props.ownLayer && (React__default["default"].createElement(MlGeoJsonLayer, { type: props.type, mapId: props.mapId,
|
|
6270
|
+
filteredData && props.ownLayer && (React__default["default"].createElement(MlGeoJsonLayer, { type: props.type, mapId: props.mapId,
|
|
6271
|
+
//layerId="timeController"
|
|
6272
|
+
//insertBeforeLayer={props.insertBeforeLayer || 'timeControllerLabels'}
|
|
6273
|
+
paint: props.paint ||
|
|
6219
6274
|
paint, options: {
|
|
6220
6275
|
source: {
|
|
6276
|
+
type: 'geojson',
|
|
6221
6277
|
attribution: props.attribution,
|
|
6278
|
+
data: filteredData
|
|
6222
6279
|
},
|
|
6223
6280
|
} })),
|
|
6224
|
-
props.label && (React__default["default"].createElement(MlTemporalControllerLabels, { data: filteredData, currentVal: currentVal, fadeIn: props.labelFadeIn, fadeOut: props.labelFadeOut, step: props.step, labelField: labelField, labelColor: labelColor, timeField: props.timeField, minVal: minVal, accumulate: props.accumulate, isPlaying: isPlaying })),
|
|
6281
|
+
filteredData && props.label && (React__default["default"].createElement(MlTemporalControllerLabels, { data: filteredData, currentVal: currentVal, fadeIn: props.labelFadeIn, fadeOut: props.labelFadeOut, step: props.step, labelField: labelField, labelColor: labelColor, timeField: props.timeField, minVal: minVal, accumulate: props.accumulate, isPlaying: isPlaying })),
|
|
6225
6282
|
React__default["default"].createElement(TemporalControllerPlayer, { currentVal: currentVal, isPlaying: isPlaying, step: props.step, interval: props.interval, minVal: minVal, maxVal: maxVal, returnCurrent: setCurrentVal, returnPlaying: setIsPlaying, open: false, fadeIn: props.fadeIn, fadeOut: props.fadeOut, featuresColor: featuresColor, labels: props.label, labelColor: labelColor, labelFadeIn: props.labelFadeIn, labelFadeOut: props.labelFadeOut, accumulate: props.accumulate, display: props.displayCurrentValue })));
|
|
6226
6283
|
};
|
|
6227
6284
|
MlTemporalController.defaultProps = {
|