@mapcomponents/react-maplibre 0.1.90 → 0.1.92
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,6 +1,33 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## [v0.1.
|
|
3
|
+
## [v0.1.92] - 2024-01-16
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- fe33641: fix useSource hook to dynamically adjust to props.sourceId changes
|
|
8
|
+
- fe33641: fix useMap hook to use less setState calls
|
|
9
|
+
- fe33641: fix useLayer hook options.source prop to wait for the source to be added
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- fe33641: add MlGeoJsonLayer labelProp defaults to enable simply passing the property name to props.labelProp to get labels.
|
|
14
|
+
- fe33641: make label layer use the same source as the main layer.
|
|
15
|
+
- fe33641: adjust MlGeoJsonLayer labelProp storybook demo to show the actual use of the property
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [v0.1.91] - 2024-01-16
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- 4775728: remove mbtiles protocol handler from build to fix sql.js error
|
|
23
|
+
|
|
24
|
+
## [v0.1.90] - 2024-01-16 (broken)
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- f40622f: fix build error suggesting marking sql.js as external
|
|
29
|
+
|
|
30
|
+
## [v0.1.89] - 2024-01-02 (broken)
|
|
4
31
|
|
|
5
32
|
### Fixed
|
|
6
33
|
|
|
@@ -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/
|
|
@@ -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
|
@@ -68,8 +68,6 @@ var csv2geojson = require('csv2geojson');
|
|
|
68
68
|
var topojsonClient = require('topojson-client');
|
|
69
69
|
var osm2geojson = require('osm2geojson-lite');
|
|
70
70
|
var externParser = require('@tmcw/togeojson');
|
|
71
|
-
var initSqlJs = require('sql.js');
|
|
72
|
-
var pako = require('pako');
|
|
73
71
|
var KeyboardArrowDownIcon = require('@mui/icons-material/KeyboardArrowDown');
|
|
74
72
|
var KeyboardArrowUpIcon = require('@mui/icons-material/KeyboardArrowUp');
|
|
75
73
|
var AppBar = require('@mui/material/AppBar');
|
|
@@ -161,8 +159,6 @@ var IndeterminateCheckBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(Inde
|
|
|
161
159
|
var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
|
|
162
160
|
var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
|
|
163
161
|
var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
|
|
164
|
-
var initSqlJs__default = /*#__PURE__*/_interopDefaultLegacy(initSqlJs);
|
|
165
|
-
var pako__namespace = /*#__PURE__*/_interopNamespace(pako);
|
|
166
162
|
var KeyboardArrowDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowDownIcon);
|
|
167
163
|
var KeyboardArrowUpIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowUpIcon);
|
|
168
164
|
var AppBar__default = /*#__PURE__*/_interopDefaultLegacy(AppBar);
|
|
@@ -1324,7 +1320,7 @@ useMapState.propTypes = {
|
|
|
1324
1320
|
|
|
1325
1321
|
function useMap(props) {
|
|
1326
1322
|
var mapContext = React.useContext(MapContext);
|
|
1327
|
-
var _a = React.useState(),
|
|
1323
|
+
var _a = React.useState({ map: undefined, ready: false }), state = _a[0], setState = _a[1];
|
|
1328
1324
|
var mapState = useMapState({
|
|
1329
1325
|
mapId: props === null || props === void 0 ? void 0 : props.mapId,
|
|
1330
1326
|
watch: {
|
|
@@ -1338,7 +1334,6 @@ function useMap(props) {
|
|
|
1338
1334
|
});
|
|
1339
1335
|
var mapRef = React.useRef();
|
|
1340
1336
|
var componentId = React.useRef(uuid.v4());
|
|
1341
|
-
var _b = React.useState(false), mapIsReady = _b[0], setMapIsReady = _b[1];
|
|
1342
1337
|
var cleanup = function () {
|
|
1343
1338
|
if (mapRef.current) {
|
|
1344
1339
|
mapRef.current.cleanup(componentId.current);
|
|
@@ -1347,7 +1342,6 @@ function useMap(props) {
|
|
|
1347
1342
|
React.useEffect(function () {
|
|
1348
1343
|
return function () {
|
|
1349
1344
|
cleanup();
|
|
1350
|
-
setMapIsReady(false);
|
|
1351
1345
|
mapRef.current = undefined;
|
|
1352
1346
|
};
|
|
1353
1347
|
}, []);
|
|
@@ -1355,8 +1349,7 @@ function useMap(props) {
|
|
|
1355
1349
|
var _a;
|
|
1356
1350
|
if (mapRef.current && mapRef.current.cancelled === true) {
|
|
1357
1351
|
mapRef.current = undefined;
|
|
1358
|
-
|
|
1359
|
-
setMapIsReady(false);
|
|
1352
|
+
setState({ map: undefined, ready: false });
|
|
1360
1353
|
}
|
|
1361
1354
|
if (mapRef.current || !mapContext.mapExists(props === null || props === void 0 ? void 0 : props.mapId))
|
|
1362
1355
|
return;
|
|
@@ -1374,12 +1367,11 @@ function useMap(props) {
|
|
|
1374
1367
|
}
|
|
1375
1368
|
}
|
|
1376
1369
|
mapRef.current = mapContext.getMap(props === null || props === void 0 ? void 0 : props.mapId);
|
|
1377
|
-
|
|
1378
|
-
setMapIsReady(true);
|
|
1370
|
+
setState({ map: mapRef.current, ready: true });
|
|
1379
1371
|
}, [mapContext.mapIds, mapState.layers, mapContext, props]);
|
|
1380
1372
|
return {
|
|
1381
|
-
map: map,
|
|
1382
|
-
mapIsReady:
|
|
1373
|
+
map: state.map,
|
|
1374
|
+
mapIsReady: state.ready,
|
|
1383
1375
|
componentId: componentId.current,
|
|
1384
1376
|
layers: mapState.layers,
|
|
1385
1377
|
cleanup: cleanup,
|
|
@@ -2433,6 +2425,7 @@ var legalLayerTypes = [
|
|
|
2433
2425
|
'background',
|
|
2434
2426
|
];
|
|
2435
2427
|
function useLayer(props) {
|
|
2428
|
+
var _a;
|
|
2436
2429
|
var mapHook = useMap({
|
|
2437
2430
|
mapId: props.mapId,
|
|
2438
2431
|
waitForLayer: props.insertBeforeLayer,
|
|
@@ -2440,17 +2433,17 @@ function useLayer(props) {
|
|
|
2440
2433
|
var layerTypeRef = React.useRef('');
|
|
2441
2434
|
var layerPaintConfRef = React.useRef('');
|
|
2442
2435
|
var layerLayoutConfRef = React.useRef('');
|
|
2443
|
-
var
|
|
2436
|
+
var _b = React.useState(), layer = _b[0], setLayer = _b[1];
|
|
2444
2437
|
var initializedRef = React.useRef(false);
|
|
2445
2438
|
var layerId = React.useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
|
|
2446
2439
|
var createLayer = React.useCallback(function () {
|
|
2447
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2440
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
2448
2441
|
if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
|
|
2449
2442
|
return;
|
|
2450
2443
|
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
2451
2444
|
mapHook.cleanup();
|
|
2452
2445
|
}
|
|
2453
|
-
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)) {
|
|
2454
2447
|
mapHook.map.map.removeSource(layerId.current);
|
|
2455
2448
|
}
|
|
2456
2449
|
if (typeof props.options.source === 'string') {
|
|
@@ -2464,18 +2457,18 @@ function useLayer(props) {
|
|
|
2464
2457
|
initializedRef.current = true;
|
|
2465
2458
|
try {
|
|
2466
2459
|
mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson &&
|
|
2467
|
-
(!((
|
|
2468
|
-
(((
|
|
2460
|
+
(!((_b = props.options) === null || _b === void 0 ? void 0 : _b.source) ||
|
|
2461
|
+
(((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.attribution) && !((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.source) === null || _f === void 0 ? void 0 : _f.type))) // if either options.source isn't defined or only options.source.attribution is defined
|
|
2469
2462
|
? {
|
|
2470
2463
|
source: {
|
|
2471
2464
|
type: 'geojson',
|
|
2472
2465
|
data: props.geojson,
|
|
2473
|
-
attribution: ((
|
|
2474
|
-
? (
|
|
2466
|
+
attribution: ((_g = props.options.source) === null || _g === void 0 ? void 0 : _g.attribution)
|
|
2467
|
+
? (_h = props.options.source) === null || _h === void 0 ? void 0 : _h.attribution
|
|
2475
2468
|
: '',
|
|
2476
2469
|
},
|
|
2477
2470
|
}
|
|
2478
|
-
: {})), (typeof ((
|
|
2471
|
+
: {})), (typeof ((_j = props.options) === null || _j === void 0 ? void 0 : _j.source) === 'string'
|
|
2479
2472
|
? {
|
|
2480
2473
|
source: props.options.source,
|
|
2481
2474
|
}
|
|
@@ -2506,8 +2499,8 @@ function useLayer(props) {
|
|
|
2506
2499
|
createLayer();
|
|
2507
2500
|
}
|
|
2508
2501
|
}, mapHook.componentId);
|
|
2509
|
-
layerPaintConfRef.current = JSON.stringify((
|
|
2510
|
-
layerLayoutConfRef.current = JSON.stringify((
|
|
2502
|
+
layerPaintConfRef.current = JSON.stringify((_k = props.options) === null || _k === void 0 ? void 0 : _k.paint);
|
|
2503
|
+
layerLayoutConfRef.current = JSON.stringify((_l = props.options) === null || _l === void 0 ? void 0 : _l.layout);
|
|
2511
2504
|
layerTypeRef.current = props.options.type;
|
|
2512
2505
|
}, [props, mapHook.map]);
|
|
2513
2506
|
React.useEffect(function () {
|
|
@@ -2523,7 +2516,7 @@ function useLayer(props) {
|
|
|
2523
2516
|
return;
|
|
2524
2517
|
}
|
|
2525
2518
|
createLayer();
|
|
2526
|
-
}, [mapHook.map, props.options, createLayer]);
|
|
2519
|
+
}, [mapHook.map, mapHook.mapIsReady, props.options, createLayer]);
|
|
2527
2520
|
React.useEffect(function () {
|
|
2528
2521
|
var _a, _b, _c, _d, _e, _f;
|
|
2529
2522
|
if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
|
|
@@ -2578,6 +2571,29 @@ function useLayer(props) {
|
|
|
2578
2571
|
mapHook.cleanup();
|
|
2579
2572
|
};
|
|
2580
2573
|
}, []);
|
|
2574
|
+
React.useEffect(function () {
|
|
2575
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2576
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' ||
|
|
2577
|
+
!mapHook.map ||
|
|
2578
|
+
(typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
|
|
2579
|
+
((_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)) &&
|
|
2580
|
+
((_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)))) {
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
var findSourceHandler = function () {
|
|
2584
|
+
var _a, _b, _c;
|
|
2585
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) === 'string' &&
|
|
2586
|
+
((_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))) {
|
|
2587
|
+
createLayer();
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
mapHook.map.on('sourcedata', findSourceHandler);
|
|
2591
|
+
return function () {
|
|
2592
|
+
if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
|
|
2593
|
+
mapHook.map.off('sourcedata', findSourceHandler);
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
}, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
|
|
2581
2597
|
return {
|
|
2582
2598
|
map: mapHook.map,
|
|
2583
2599
|
layer: layer,
|
|
@@ -2684,6 +2700,66 @@ var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
|
2684
2700
|
return "fill";
|
|
2685
2701
|
};
|
|
2686
2702
|
|
|
2703
|
+
function useSource(props) {
|
|
2704
|
+
var _a;
|
|
2705
|
+
var mapHook = useMap({
|
|
2706
|
+
mapId: props.mapId,
|
|
2707
|
+
});
|
|
2708
|
+
var initializedRef = React.useRef(false);
|
|
2709
|
+
var _b = React.useState(), source = _b[0], setSource = _b[1];
|
|
2710
|
+
var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
|
|
2711
|
+
var createSource = React.useCallback(function () {
|
|
2712
|
+
var _a;
|
|
2713
|
+
if (!mapHook.map)
|
|
2714
|
+
return;
|
|
2715
|
+
initializedRef.current = true;
|
|
2716
|
+
if (mapHook.map.map.getSource(sourceId.current)) {
|
|
2717
|
+
mapHook.cleanup();
|
|
2718
|
+
}
|
|
2719
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source), mapHook.componentId);
|
|
2720
|
+
setSource(mapHook.map.map.getSource(sourceId.current));
|
|
2721
|
+
}, [props, mapHook.map]);
|
|
2722
|
+
React.useEffect(function () {
|
|
2723
|
+
var _a, _b, _c, _d;
|
|
2724
|
+
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)))
|
|
2725
|
+
return;
|
|
2726
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2727
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
2728
|
+
(_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);
|
|
2729
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2730
|
+
//@ts-ignore data only exists on GeoJsonSource
|
|
2731
|
+
}, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
|
|
2732
|
+
React.useEffect(function () {
|
|
2733
|
+
var _a, _b, _c;
|
|
2734
|
+
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)
|
|
2735
|
+
return;
|
|
2736
|
+
sourceId.current = props.sourceId;
|
|
2737
|
+
createSource();
|
|
2738
|
+
}, [mapHook.map, props, createSource]);
|
|
2739
|
+
//cleanup
|
|
2740
|
+
React.useEffect(function () {
|
|
2741
|
+
return function () {
|
|
2742
|
+
var _a, _b, _c;
|
|
2743
|
+
initializedRef.current = false;
|
|
2744
|
+
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)) {
|
|
2745
|
+
for (var _i = 0, _d = Object.entries(mapHook.map.map.style._layers); _i < _d.length; _i++) {
|
|
2746
|
+
var _e = _d[_i], layerId = _e[0], layer = _e[1];
|
|
2747
|
+
if (layer.source === sourceId.current) {
|
|
2748
|
+
mapHook.map.map.removeLayer(layerId);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
mapHook.map.map.removeSource(sourceId.current);
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
}, [mapHook.map]);
|
|
2755
|
+
return {
|
|
2756
|
+
map: mapHook.map,
|
|
2757
|
+
source: source,
|
|
2758
|
+
componentId: mapHook.componentId,
|
|
2759
|
+
mapHook: mapHook,
|
|
2760
|
+
};
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2687
2763
|
/**
|
|
2688
2764
|
* Adds source and layer to display GeoJSON data on the map.
|
|
2689
2765
|
*
|
|
@@ -2692,14 +2768,28 @@ var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
|
2692
2768
|
var MlGeoJsonLayer = function (props) {
|
|
2693
2769
|
var _a, _b, _c;
|
|
2694
2770
|
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
2695
|
-
var layerId = props.layerId || 'MlGeoJsonLayer-' + uuid.v4();
|
|
2696
|
-
var labelLayerId = "label-".concat(layerId);
|
|
2697
|
-
|
|
2771
|
+
var layerId = React.useRef(props.layerId || 'MlGeoJsonLayer-' + uuid.v4());
|
|
2772
|
+
var labelLayerId = "label-".concat(layerId.current);
|
|
2773
|
+
React.useEffect(function () {
|
|
2774
|
+
if (!props.layerId) {
|
|
2775
|
+
layerId.current = 'MlGeoJsonLayer-' + uuid.v4();
|
|
2776
|
+
}
|
|
2777
|
+
else {
|
|
2778
|
+
layerId.current = props.layerId;
|
|
2779
|
+
}
|
|
2780
|
+
}, [props.layerId]);
|
|
2781
|
+
useSource({
|
|
2782
|
+
mapId: props.mapId,
|
|
2783
|
+
sourceId: layerId.current,
|
|
2784
|
+
source: {
|
|
2785
|
+
type: 'geojson',
|
|
2786
|
+
data: props.geojson,
|
|
2787
|
+
},
|
|
2788
|
+
});
|
|
2698
2789
|
useLayer({
|
|
2699
2790
|
mapId: props.mapId,
|
|
2700
|
-
layerId:
|
|
2701
|
-
|
|
2702
|
-
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 }),
|
|
2791
|
+
layerId: layerId.current,
|
|
2792
|
+
options: __assign(__assign({ 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 }),
|
|
2703
2793
|
insertBeforeLayer: props.insertBeforeLayer,
|
|
2704
2794
|
onHover: props.onHover,
|
|
2705
2795
|
onClick: props.onClick,
|
|
@@ -2708,9 +2798,11 @@ var MlGeoJsonLayer = function (props) {
|
|
|
2708
2798
|
if (props.labelProp) {
|
|
2709
2799
|
useLayer({
|
|
2710
2800
|
mapId: props.mapId,
|
|
2711
|
-
layerId: labelLayerId,
|
|
2712
|
-
|
|
2713
|
-
|
|
2801
|
+
options: __assign(__assign({ source: props.labelProp ? layerId.current : undefined, id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }, ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), { layout: __assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}") }, (((_c = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _c === void 0 ? void 0 : _c.layout) ? props.labelOptions.layout : {})), paint: {
|
|
2802
|
+
'text-halo-width': 1,
|
|
2803
|
+
'text-halo-color': '#121212',
|
|
2804
|
+
'text-color': '#fefefe',
|
|
2805
|
+
} }),
|
|
2714
2806
|
});
|
|
2715
2807
|
}
|
|
2716
2808
|
return React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
@@ -4583,64 +4675,6 @@ useLayerHoverPopup.defaultProps = {
|
|
|
4583
4675
|
mapId: undefined,
|
|
4584
4676
|
};
|
|
4585
4677
|
|
|
4586
|
-
function useSource(props) {
|
|
4587
|
-
var _a;
|
|
4588
|
-
var mapHook = useMap({
|
|
4589
|
-
mapId: props.mapId,
|
|
4590
|
-
});
|
|
4591
|
-
var initializedRef = React.useRef(false);
|
|
4592
|
-
var _b = React.useState(), source = _b[0], setSource = _b[1];
|
|
4593
|
-
var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : "Source-") + mapHook.componentId);
|
|
4594
|
-
var createSource = React.useCallback(function () {
|
|
4595
|
-
var _a;
|
|
4596
|
-
if (!mapHook.map)
|
|
4597
|
-
return;
|
|
4598
|
-
initializedRef.current = true;
|
|
4599
|
-
if (mapHook.map.map.getSource(sourceId.current)) {
|
|
4600
|
-
mapHook.cleanup();
|
|
4601
|
-
}
|
|
4602
|
-
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source), mapHook.componentId);
|
|
4603
|
-
setSource(mapHook.map.map.getSource(sourceId.current));
|
|
4604
|
-
}, [props, mapHook.map]);
|
|
4605
|
-
React.useEffect(function () {
|
|
4606
|
-
if (!mapHook.map || initializedRef.current)
|
|
4607
|
-
return;
|
|
4608
|
-
createSource();
|
|
4609
|
-
}, [mapHook.map, props, createSource]);
|
|
4610
|
-
React.useEffect(function () {
|
|
4611
|
-
var _a, _b, _c, _d;
|
|
4612
|
-
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)))
|
|
4613
|
-
return;
|
|
4614
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4615
|
-
//@ts-ignore setData only exists on GeoJsonSource
|
|
4616
|
-
(_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);
|
|
4617
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4618
|
-
//@ts-ignore data only exists on GeoJsonSource
|
|
4619
|
-
}, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
|
|
4620
|
-
//cleanup
|
|
4621
|
-
React.useEffect(function () {
|
|
4622
|
-
return function () {
|
|
4623
|
-
var _a, _b, _c;
|
|
4624
|
-
initializedRef.current = false;
|
|
4625
|
-
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)) {
|
|
4626
|
-
for (var _i = 0, _d = Object.entries(mapHook.map.map.style._layers); _i < _d.length; _i++) {
|
|
4627
|
-
var _e = _d[_i], layerId = _e[0], layer = _e[1];
|
|
4628
|
-
if (layer.source === sourceId.current) {
|
|
4629
|
-
mapHook.map.map.removeLayer(layerId);
|
|
4630
|
-
}
|
|
4631
|
-
}
|
|
4632
|
-
mapHook.map.map.removeSource(sourceId.current);
|
|
4633
|
-
}
|
|
4634
|
-
};
|
|
4635
|
-
}, [mapHook.map]);
|
|
4636
|
-
return {
|
|
4637
|
-
map: mapHook.map,
|
|
4638
|
-
source: source,
|
|
4639
|
-
componentId: mapHook.componentId,
|
|
4640
|
-
mapHook: mapHook,
|
|
4641
|
-
};
|
|
4642
|
-
}
|
|
4643
|
-
|
|
4644
4678
|
/**
|
|
4645
4679
|
* MlGpxViewer visualizes a given GPX Track on the map
|
|
4646
4680
|
*/
|
|
@@ -7777,128 +7811,6 @@ var XMLProtocolHandler = function (params, callback) {
|
|
|
7777
7811
|
return { cancel: function () { } };
|
|
7778
7812
|
};
|
|
7779
7813
|
|
|
7780
|
-
var loadedMbtiles = {};
|
|
7781
|
-
var parseTileParams = function (url) {
|
|
7782
|
-
var urlParts = url.split('://');
|
|
7783
|
-
var mbtilesUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
|
|
7784
|
-
var mbtilesParts = mbtilesUrl.split('/');
|
|
7785
|
-
var mbtilesPartsLength = mbtilesParts.length;
|
|
7786
|
-
var y = mbtilesParts.splice(mbtilesPartsLength - 1, 1)[0];
|
|
7787
|
-
var x = mbtilesParts.splice(mbtilesPartsLength - 2, 1)[0];
|
|
7788
|
-
var z = mbtilesParts.splice(mbtilesPartsLength - 3, 1)[0];
|
|
7789
|
-
var filename = mbtilesParts.join('/');
|
|
7790
|
-
return {
|
|
7791
|
-
filename: filename,
|
|
7792
|
-
z: z,
|
|
7793
|
-
x: x,
|
|
7794
|
-
y: y,
|
|
7795
|
-
};
|
|
7796
|
-
};
|
|
7797
|
-
// mbtiles files are sqlite databases. This function loads the database and returns a handler
|
|
7798
|
-
// to work with sqlite databases in javascript we need to use sql.js.
|
|
7799
|
-
// to make this work in your project make sure to copy sql-wasm.wasm to the file root of your public folder and
|
|
7800
|
-
// add the following config to the externals prop of your webpack config
|
|
7801
|
-
// {externals: { fs: 'fs' }};
|
|
7802
|
-
var getMbtilesDbHandler = function (_a) {
|
|
7803
|
-
var filename = _a.filename;
|
|
7804
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
7805
|
-
var SQL, fetched, buf, db;
|
|
7806
|
-
return __generator(this, function (_b) {
|
|
7807
|
-
switch (_b.label) {
|
|
7808
|
-
case 0:
|
|
7809
|
-
if (!!loadedMbtiles[filename]) return [3 /*break*/, 4];
|
|
7810
|
-
return [4 /*yield*/, initSqlJs__default["default"]()];
|
|
7811
|
-
case 1:
|
|
7812
|
-
SQL = _b.sent();
|
|
7813
|
-
return [4 /*yield*/, fetch(filename)];
|
|
7814
|
-
case 2:
|
|
7815
|
-
fetched = _b.sent();
|
|
7816
|
-
return [4 /*yield*/, fetched.arrayBuffer()];
|
|
7817
|
-
case 3:
|
|
7818
|
-
buf = _b.sent();
|
|
7819
|
-
db = new SQL.Database(new Uint8Array(buf));
|
|
7820
|
-
loadedMbtiles[filename] = db;
|
|
7821
|
-
_b.label = 4;
|
|
7822
|
-
case 4: return [2 /*return*/, loadedMbtiles[filename]];
|
|
7823
|
-
}
|
|
7824
|
-
});
|
|
7825
|
-
});
|
|
7826
|
-
};
|
|
7827
|
-
/**
|
|
7828
|
-
* Example usage:
|
|
7829
|
-
* getBufferFromMbtiles({ filename: 'mbtiles/countries.mbtiles', z: '0', x: '0', y: '0' }).then(
|
|
7830
|
-
* (result) => {
|
|
7831
|
-
* console.log(result);
|
|
7832
|
-
* }
|
|
7833
|
-
* );
|
|
7834
|
-
*/
|
|
7835
|
-
function getBufferFromMbtiles(params) {
|
|
7836
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7837
|
-
var db, query;
|
|
7838
|
-
return __generator(this, function (_a) {
|
|
7839
|
-
switch (_a.label) {
|
|
7840
|
-
case 0: return [4 /*yield*/, getMbtilesDbHandler(params)];
|
|
7841
|
-
case 1:
|
|
7842
|
-
db = _a.sent();
|
|
7843
|
-
query = 'SELECT tile_data FROM tiles WHERE zoom_level = ' +
|
|
7844
|
-
params.z +
|
|
7845
|
-
' AND tile_column = ' +
|
|
7846
|
-
params.x +
|
|
7847
|
-
' AND tile_row = ' +
|
|
7848
|
-
(Math.pow(2, parseInt(params.z)) - parseInt(params.y) - 1);
|
|
7849
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
7850
|
-
try {
|
|
7851
|
-
// some of the logic here was heavily inspired by
|
|
7852
|
-
// https://github.com/IsraelHikingMap/Site/blob/6aa2ec0cfb8891fa048b1d9e2a4fc7d4cbcc8c97/IsraelHiking.Web/src/application/services/database.service.ts
|
|
7853
|
-
var result = db.exec(query);
|
|
7854
|
-
if (result.length !== 1) {
|
|
7855
|
-
reject(new Error('Tile not found.'));
|
|
7856
|
-
return;
|
|
7857
|
-
}
|
|
7858
|
-
var resultData = result[0].values[0][0];
|
|
7859
|
-
var binData = void 0;
|
|
7860
|
-
var isGzipped = resultData[0] === 0x1f && resultData[1] === 0x8b;
|
|
7861
|
-
if (isGzipped) {
|
|
7862
|
-
binData = pako__namespace.inflate(resultData);
|
|
7863
|
-
}
|
|
7864
|
-
else {
|
|
7865
|
-
binData = resultData;
|
|
7866
|
-
}
|
|
7867
|
-
if (binData === null || binData === void 0 ? void 0 : binData.buffer) {
|
|
7868
|
-
resolve(binData.buffer);
|
|
7869
|
-
}
|
|
7870
|
-
else {
|
|
7871
|
-
reject(new Error('Tile not found.'));
|
|
7872
|
-
return;
|
|
7873
|
-
}
|
|
7874
|
-
}
|
|
7875
|
-
catch (error) {
|
|
7876
|
-
reject(error);
|
|
7877
|
-
}
|
|
7878
|
-
})];
|
|
7879
|
-
}
|
|
7880
|
-
});
|
|
7881
|
-
});
|
|
7882
|
-
}
|
|
7883
|
-
/**
|
|
7884
|
-
* Expects a tile url in the following format:
|
|
7885
|
-
*
|
|
7886
|
-
* 'mbtiles://mbtiles/countries.mbtiles/{z}/{x}/{y}'
|
|
7887
|
-
*/
|
|
7888
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7889
|
-
var mbTilesProtocolHandler = function (params, callback) {
|
|
7890
|
-
var parsedParams = parseTileParams(params.url);
|
|
7891
|
-
getBufferFromMbtiles(parsedParams).then(function (result) {
|
|
7892
|
-
if (result) {
|
|
7893
|
-
callback(null, result, null, null);
|
|
7894
|
-
}
|
|
7895
|
-
else {
|
|
7896
|
-
callback(new Error('Tile not found'));
|
|
7897
|
-
}
|
|
7898
|
-
});
|
|
7899
|
-
return { cancel: function () { } };
|
|
7900
|
-
};
|
|
7901
|
-
|
|
7902
7814
|
var handlers = {
|
|
7903
7815
|
csv: CSVProtocolHandler,
|
|
7904
7816
|
topojson: TopojsonProtocolHandler,
|
|
@@ -7906,7 +7818,7 @@ var handlers = {
|
|
|
7906
7818
|
gpx: XMLProtocolHandler,
|
|
7907
7819
|
kml: XMLProtocolHandler,
|
|
7908
7820
|
tcx: XMLProtocolHandler,
|
|
7909
|
-
mbtiles: mbTilesProtocolHandler
|
|
7821
|
+
//mbtiles: mbTilesProtocolHandler
|
|
7910
7822
|
};
|
|
7911
7823
|
var types = ['fill', 'line', 'circle'];
|
|
7912
7824
|
function ProtocolHandlerLayerForm(props) {
|
|
@@ -8152,19 +8064,12 @@ var AddLayerPopup = function (props) {
|
|
|
8152
8064
|
};
|
|
8153
8065
|
AddLayerPopup.defaultProps = {};
|
|
8154
8066
|
|
|
8155
|
-
function AddProtocol(props) {
|
|
8156
|
-
useAddProtocol({
|
|
8157
|
-
protocol: props.protocol,
|
|
8158
|
-
handler: props.handler,
|
|
8159
|
-
});
|
|
8160
|
-
return React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
8161
|
-
}
|
|
8162
8067
|
var AddLayerButton = function (props) {
|
|
8163
8068
|
var _a = React__default["default"].useState(false), popupOpen = _a[0], setPopupOpen = _a[1];
|
|
8164
8069
|
var layerTypes = props.layerTypes || [
|
|
8165
8070
|
'geojson',
|
|
8166
8071
|
'wms',
|
|
8167
|
-
'mbtiles',
|
|
8072
|
+
//'mbtiles',
|
|
8168
8073
|
'csv',
|
|
8169
8074
|
'topojson',
|
|
8170
8075
|
'osm',
|
|
@@ -8173,10 +8078,6 @@ var AddLayerButton = function (props) {
|
|
|
8173
8078
|
'tcx',
|
|
8174
8079
|
];
|
|
8175
8080
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
8176
|
-
layerTypes.includes('mbtiles') && (React__default["default"].createElement(AddProtocol, __assign({}, {
|
|
8177
|
-
protocol: 'mbtiles',
|
|
8178
|
-
handler: mbTilesProtocolHandler,
|
|
8179
|
-
}))),
|
|
8180
8081
|
React__default["default"].createElement(material.Button, { variant: "contained", sx: __assign({ marginTop: '10px' }, props.sx), onClick: function () { return setPopupOpen(true); } },
|
|
8181
8082
|
React__default["default"].createElement(PlaylistAddIcon__default["default"], null)),
|
|
8182
8083
|
React__default["default"].createElement(AddLayerPopup, { open: popupOpen, setOpen: setPopupOpen, onComplete: props === null || props === void 0 ? void 0 : props.onComplete, layerTypes: layerTypes })));
|