@mapcomponents/react-maplibre 1.0.4 → 1.0.5

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/dist/index.esm.js CHANGED
@@ -4,16 +4,15 @@ import React__default, { useMemo, useEffect, useCallback, useState, useRef, useC
4
4
  import { createTheme, ThemeProvider, styled as styled$2, useTheme } from '@mui/material/styles';
5
5
  import { v4 } from 'uuid';
6
6
  import 'maplibre-gl/dist/maplibre-gl.css';
7
- import { Button, Autocomplete, TextField, CircularProgress, useMediaQuery, FormControl, InputLabel, Select, MenuItem, FormLabel, RadioGroup, FormControlLabel, Radio, styled, List, ListItem, ListItemIcon, IconButton, Checkbox, ListItemText, Grid, Paper, Box as Box$1, Typography, Slider, Drawer, Tooltip, Snackbar, DialogTitle as DialogTitle$1, DialogActions as DialogActions$1, ListItemButton, ListItemAvatar, Avatar, DialogContent as DialogContent$1, OutlinedInput, Accordion, AccordionSummary, Dialog as Dialog$1 } from '@mui/material';
7
+ import { Button, CircularProgress, useMediaQuery, FormControl, InputLabel, Select, MenuItem, FormLabel, RadioGroup, FormControlLabel, Radio, styled, List, ListItem, ListItemIcon, IconButton, Checkbox, ListItemText, Grid, Paper, Box as Box$1, Typography, TextField, Slider, Drawer, Tooltip, Snackbar, DialogTitle as DialogTitle$1, DialogActions as DialogActions$1, ListItemButton, ListItemAvatar, Avatar, DialogContent as DialogContent$1, OutlinedInput, Accordion, AccordionSummary, Dialog as Dialog$1 } from '@mui/material';
8
8
  import FilterCenterFocusIcon from '@mui/icons-material/FilterCenterFocus';
9
- import elasticlunr from 'elasticlunr';
10
- import * as turf from '@turf/turf';
11
- import { point, circle, lineArc, bbox, booleanContains, bboxPolygon, featureCollection, distance, lineOffset } from '@turf/turf';
12
9
  import PrinterIcon from '@mui/icons-material/Print';
13
10
  import Button$1 from '@mui/material/Button';
14
11
  import jsPDF from 'jspdf';
15
12
  import ReactDOM from 'react-dom';
16
13
  import Moveable from 'react-moveable';
14
+ import * as turf from '@turf/turf';
15
+ import { point, circle, lineArc, bbox, booleanContains, bboxPolygon, featureCollection, distance, lineOffset } from '@turf/turf';
17
16
  import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
18
17
  import MapboxDraw from '@mapbox/mapbox-gl-draw';
19
18
  import GpsFixedIcon from '@mui/icons-material/GpsFixed';
@@ -1320,741 +1319,144 @@ MlCenterPosition.defaultProps = {
1320
1319
  mapId: undefined,
1321
1320
  };
1322
1321
 
1323
- var legalLayerTypes = [
1324
- 'fill',
1325
- 'line',
1326
- 'symbol',
1327
- 'circle',
1328
- 'heatmap',
1329
- 'fill-extrusion',
1330
- 'raster',
1331
- 'hillshade',
1332
- 'background',
1333
- ];
1334
- function determineSource(props) {
1335
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1336
- if (typeof props.options.source === 'string') {
1337
- return {
1338
- source: props.options.source,
1339
- };
1340
- }
1341
- else if (props.geojson &&
1342
- (!((_a = props.options) === null || _a === void 0 ? void 0 : _a.source) ||
1343
- (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
1344
- ((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.attribution) &&
1345
- !((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.source) === null || _f === void 0 ? void 0 : _f.type)))) {
1346
- return {
1347
- source: {
1348
- type: 'geojson',
1349
- data: props.geojson || '',
1350
- attribution: typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'string' && ((_h = props.options.source) === null || _h === void 0 ? void 0 : _h.attribution)
1351
- ? (_j = props.options.source) === null || _j === void 0 ? void 0 : _j.attribution
1352
- : '',
1353
- },
1354
- };
1322
+ /**
1323
+ * Component description
1324
+ *
1325
+ */
1326
+ var MlComponentTemplate = function (props) {
1327
+ var mapHook = useMap({
1328
+ mapId: props.mapId,
1329
+ });
1330
+ console.log(mapHook.componentId + " remove this log");
1331
+ return React__default.createElement(React__default.Fragment, null);
1332
+ };
1333
+ MlComponentTemplate.defaultProps = {
1334
+ mapId: undefined,
1335
+ };
1336
+
1337
+ var createExport = function (options) {
1338
+ var width = options.width;
1339
+ var height = options.height;
1340
+ // Create map container
1341
+ var hiddenContainer = document.createElement('div');
1342
+ hiddenContainer.className = 'hidden-map';
1343
+ hiddenContainer.style.width = '0px';
1344
+ hiddenContainer.style.height = '0px';
1345
+ hiddenContainer.style.overflow = 'hidden';
1346
+ document.body.appendChild(hiddenContainer);
1347
+ var container = document.createElement('div');
1348
+ container.style.width = width + 'px';
1349
+ container.style.height = height + 'px';
1350
+ hiddenContainer.appendChild(container);
1351
+ var style = options.map.map.getStyle();
1352
+ var _loop_1 = function (name_1) {
1353
+ var src = style.sources[name_1];
1354
+ Object.keys(src).forEach(function (key) {
1355
+ // delete property if value is undefined.
1356
+ // for instance, raster-dem might have undefined value in "url" and "bounds"
1357
+ if (!src[key]) {
1358
+ delete src[key];
1359
+ }
1360
+ });
1361
+ };
1362
+ // delete undefined source properties
1363
+ for (var name_1 in style.sources) {
1364
+ _loop_1(name_1);
1355
1365
  }
1356
- return {};
1366
+ // Create a new MapLibre-gl instance
1367
+ var renderMap = new Map({
1368
+ container: container,
1369
+ center: options.map.map.getCenter(),
1370
+ zoom: options.map.map.getZoom(),
1371
+ bearing: 0,
1372
+ pitch: 0,
1373
+ interactive: false,
1374
+ preserveDrawingBuffer: true,
1375
+ fadeDuration: 0,
1376
+ attributionControl: false,
1377
+ style: style,
1378
+ });
1379
+ var bboxCamera = renderMap._cameraForBoxAndBearing([options.bboxUnrotated[0], options.bboxUnrotated[1]], [options.bboxUnrotated[2], options.bboxUnrotated[3]], options.bearing + options.map.map.getBearing());
1380
+ renderMap._fitInternal(bboxCamera);
1381
+ return new Promise(function (resolve) {
1382
+ console.log('before idle');
1383
+ renderMap.once('idle', function () {
1384
+ var params = __assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer, createPdf: function (_options) {
1385
+ return createJsPdf(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
1386
+ }, createPng: function (_options) {
1387
+ return createPng(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
1388
+ } });
1389
+ resolve(params);
1390
+ });
1391
+ });
1392
+ };
1393
+ function createJsPdf(options) {
1394
+ var pdf = new jsPDF({
1395
+ orientation: (options === null || options === void 0 ? void 0 : options.orientation) === 'portrait' ? 'p' : 'l',
1396
+ unit: 'mm',
1397
+ compress: true,
1398
+ format: options.format,
1399
+ });
1400
+ Object.defineProperty(window, 'devicePixelRatio', {
1401
+ get: function () {
1402
+ return 300 / 96;
1403
+ },
1404
+ });
1405
+ return new Promise(function (resolve) {
1406
+ var _b;
1407
+ //Render map image
1408
+ pdf.addImage(options.renderMap.getCanvas().toDataURL('image/png'), 'png', 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight(), undefined, 'FAST');
1409
+ // remove DOM Elements
1410
+ options.renderMap.remove();
1411
+ (_b = options.hiddenContainer.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(options.hiddenContainer);
1412
+ var params = __assign(__assign({}, options), { pdf: pdf, downloadPdf: function (_options) { return downloadPdf(__assign(__assign({}, params), _options)); }, formData: new FormData() });
1413
+ resolve(params);
1414
+ });
1357
1415
  }
1358
- function determineInsertionPoint(props, mapHook) {
1359
- var _a;
1360
- if (props === null || props === void 0 ? void 0 : props.insertBeforeLayer)
1361
- return props.insertBeforeLayer;
1362
- if (props === null || props === void 0 ? void 0 : props.insertBeforeFirstSymbolLayer)
1363
- return (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.firstSymbolLayer;
1364
- return undefined;
1416
+ function downloadPdf(options) {
1417
+ options.pdf.save('Map.pdf');
1418
+ return new Promise(function (resolve) {
1419
+ resolve(__assign({}, options));
1420
+ });
1365
1421
  }
1366
- function useLayer(props) {
1367
- var _a;
1368
- var mapHook = useMap({
1369
- mapId: props.mapId,
1370
- waitForLayer: props.insertBeforeLayer,
1371
- });
1372
- var layerTypeRef = useRef('');
1373
- var layerPaintConfRef = useRef('');
1374
- var layerLayoutConfRef = useRef('');
1375
- var _b = useState(), layer = _b[0], setLayer = _b[1];
1376
- var layerId = useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
1377
- var createLayer = useCallback(function () {
1378
- var _a, _b, _c, _d, _e, _f, _g;
1379
- if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
1380
- return;
1381
- if (mapHook.map.map.getLayer(layerId.current)) {
1382
- mapHook.cleanup();
1383
- }
1384
- 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)) {
1385
- mapHook.map.map.removeSource(layerId.current);
1386
- }
1387
- if (typeof props.options.source === 'string') {
1388
- if (props.options.source === '' || !mapHook.map.map.getSource(props.options.source)) {
1389
- return;
1390
- }
1391
- }
1392
- if (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
1393
- !props.geojson &&
1394
- !((_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) &&
1395
- ((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.type) !== 'background') {
1396
- return;
1397
- }
1398
- if (typeof props.options.type === 'undefined') {
1399
- return;
1400
- }
1401
- try {
1402
- mapHook.map.addLayer(__assign(__assign(__assign({}, props.options), determineSource(props)), { id: layerId.current }), determineInsertionPoint(props, mapHook), mapHook.componentId);
1403
- }
1404
- catch (error) {
1405
- console.error('Failed to add layer:', error);
1406
- }
1407
- setLayer(function () { var _a; return (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current); });
1408
- if (typeof props.onHover !== 'undefined') {
1409
- mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
1410
- }
1411
- if (typeof props.onClick !== 'undefined') {
1412
- mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
1413
- }
1414
- if (typeof props.onLeave !== 'undefined') {
1415
- mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
1416
- }
1417
- // recreate layer if style has changed
1418
- var styledataEventHandler = function () {
1419
- var _a;
1420
- if (!((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
1421
- createLayer();
1422
- }
1423
- };
1424
- mapHook.map.on('styledata', styledataEventHandler, mapHook.componentId);
1425
- var addSourceHandler = function (_ev, _wrapper, _a) {
1426
- var _b;
1427
- var source_id = _a.source_id;
1428
- if (mapHook.map &&
1429
- typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
1430
- props.options.source === source_id) {
1431
- createLayer();
1432
- }
1433
- };
1434
- mapHook.map.wrapper.on('addsource', addSourceHandler, mapHook.componentId);
1435
- layerPaintConfRef.current = JSON.stringify((_f = props.options) === null || _f === void 0 ? void 0 : _f.paint);
1436
- layerLayoutConfRef.current = JSON.stringify((_g = props.options) === null || _g === void 0 ? void 0 : _g.layout);
1437
- layerTypeRef.current = props.options.type;
1438
- }, [props, mapHook]);
1439
- useEffect(function () {
1440
- var _a, _b, _c, _d, _e;
1441
- if (!mapHook.map)
1442
- return;
1443
- if (!props.geojson && !props.options.source && ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.type) !== 'background')
1444
- return;
1445
- if (((_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.cancelled) === false &&
1446
- ((_e = (_d = (_c = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.getLayer) === null || _e === void 0 ? void 0 : _e.call(_d, layerId.current)) &&
1447
- (legalLayerTypes.indexOf(props.options.type) === -1 ||
1448
- (legalLayerTypes.indexOf(props.options.type) !== -1 &&
1449
- props.options.type === layerTypeRef.current))) {
1450
- return;
1451
- }
1452
- createLayer();
1453
- }, [mapHook.map, mapHook.mapIsReady, props, createLayer]);
1454
- useEffect(function () {
1455
- var _a, _b, _c, _d, _e, _f;
1456
- if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true || !((_d = (_c = (_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getSource) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)))
1457
- return;
1458
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1459
- //@ts-ignore setData only exists on GeoJsonSource
1460
- (_f = (_e = mapHook.map.map.getSource(layerId.current)) === null || _e === void 0 ? void 0 : _e.setData) === null || _f === void 0 ? void 0 : _f.call(_e, props.geojson);
1461
- }, [props.geojson, mapHook.map, props.options.type]);
1462
- useEffect(function () {
1463
- var _a, _b, _c, _d, _e, _f;
1464
- if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
1465
- !mapHook.map ||
1466
- !((_d = (_c = (_b = 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)) ||
1467
- props.options.type !== layerTypeRef.current)
1468
- return;
1469
- var key;
1470
- var layoutString = JSON.stringify(props.options.layout);
1471
- if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
1472
- var oldLayout = JSON.parse(layerLayoutConfRef.current);
1473
- for (key in props.options.layout) {
1474
- if (((_e = props.options.layout) === null || _e === void 0 ? void 0 : _e[key]) &&
1475
- props.options.layout[key] !== oldLayout[key]) {
1476
- mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
1477
- }
1478
- }
1479
- layerLayoutConfRef.current = layoutString;
1480
- }
1481
- var paintString = JSON.stringify(props.options.paint);
1482
- if (paintString !== layerPaintConfRef.current) {
1483
- var oldPaint = JSON.parse(layerPaintConfRef.current);
1484
- for (key in props.options.paint) {
1485
- if (((_f = props.options.paint) === null || _f === void 0 ? void 0 : _f[key]) &&
1486
- props.options.paint[key] !== oldPaint[key]) {
1487
- mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
1488
- }
1489
- }
1490
- layerPaintConfRef.current = paintString;
1491
- }
1492
- }, [props.options, mapHook.map]);
1493
- useEffect(function () {
1494
- if (!props.insertBeforeLayer ||
1495
- !mapHook.map ||
1496
- !mapHook.map.getLayer(props.insertBeforeLayer) ||
1497
- !mapHook.map.getLayer(layerId.current))
1498
- return;
1499
- mapHook.map.moveLayer(layerId.current, props.insertBeforeLayer);
1500
- }, [mapHook.map, props.insertBeforeLayer]);
1501
- useEffect(function () {
1502
- return function () {
1503
- mapHook.cleanup();
1504
- };
1505
- }, []);
1506
- useEffect(function () {
1507
- var _a;
1508
- if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' || !mapHook.map) {
1509
- return;
1510
- }
1511
- var findSourceHandler = function () {
1512
- var _a, _b, _c;
1513
- if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) === 'string' &&
1514
- ((_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)) &&
1515
- !mapHook.map.getLayer(layerId.current)) {
1516
- createLayer();
1517
- }
1518
- };
1519
- mapHook.map.on('sourcedataloading', findSourceHandler);
1520
- var addSourceHandler = function (_ev, _wrapper, _a) {
1521
- var _b;
1522
- var source_id = _a.source_id;
1523
- if (mapHook.map &&
1524
- typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
1525
- props.options.source === source_id) {
1526
- createLayer();
1527
- }
1528
- };
1529
- mapHook.map.wrapper.on('addsource', addSourceHandler);
1530
- return function () {
1531
- if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
1532
- mapHook.map.off('sourcedataloading', findSourceHandler);
1533
- mapHook.map.wrapper.off('addsource', addSourceHandler);
1534
- }
1535
- };
1536
- }, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
1537
- return {
1538
- map: mapHook.map,
1539
- layer: layer,
1540
- layerId: layerId.current,
1541
- componentId: mapHook.componentId,
1542
- mapHook: mapHook,
1543
- };
1544
- }
1545
- useLayer.defaultProps = {};
1546
-
1547
- var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
1548
- switch (type) {
1549
- case 'fill':
1550
- if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.fill) {
1551
- return defaultPaintOverrides.fill;
1552
- }
1553
- return {
1554
- 'fill-color': 'rgba(10,240,256,0.6)',
1555
- 'fill-outline-color': 'rgba(20,230,256,0.8)',
1556
- };
1557
- case 'line':
1558
- if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
1559
- return defaultPaintOverrides.line;
1560
- }
1561
- return {
1562
- 'line-color': 'rgb(203,211,2)',
1563
- 'line-width': 5,
1564
- 'line-blur': 0,
1565
- };
1566
- case 'circle':
1567
- if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.circle) {
1568
- return defaultPaintOverrides.circle;
1569
- }
1570
- return {
1571
- 'circle-color': 'rgba(10,240,256,0.8)',
1572
- 'circle-stroke-color': '#fff',
1573
- 'circle-stroke-width': 2,
1574
- 'circle-radius': 4,
1575
- };
1576
- default:
1577
- return {};
1578
- }
1579
- };
1580
-
1581
- var mapGeometryTypesToLayerTypes = {
1582
- Position: "circle",
1583
- Point: "circle",
1584
- MultiPoint: "circle",
1585
- LineString: "line",
1586
- MultiLineString: "line",
1587
- Polygon: "fill",
1588
- MultiPolygon: "fill",
1589
- GeometryCollection: "circle",
1590
- };
1591
- var getDefaulLayerTypeByGeometry = function (geojson) {
1592
- var _a;
1593
- if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
1594
- return (mapGeometryTypesToLayerTypes === null || mapGeometryTypesToLayerTypes === void 0 ? void 0 : mapGeometryTypesToLayerTypes[(_a = geojson === null || geojson === void 0 ? void 0 : geojson.geometry) === null || _a === void 0 ? void 0 : _a.type])
1595
- ? mapGeometryTypesToLayerTypes[geojson.geometry.type]
1596
- : "circle";
1597
- }
1598
- if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
1599
- if (geojson.features.length) {
1600
- return getDefaulLayerTypeByGeometry(geojson.features[0]);
1601
- }
1602
- return "circle";
1603
- }
1604
- return "fill";
1605
- };
1606
-
1607
- function useSource(props) {
1608
- var _a;
1609
- var mapHook = useMap({
1610
- mapId: props.mapId,
1611
- });
1612
- var _b = useState(), source = _b[0], setSource = _b[1];
1613
- var sourceId = useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
1614
- var removeSource = useCallback(function () {
1615
- var _a, _b;
1616
- if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
1617
- for (var _i = 0, _c = Object.entries(mapHook.map.map.style._layers); _i < _c.length; _i++) {
1618
- var _d = _c[_i], layerId = _d[0], layer = _d[1];
1619
- if (layer.source === sourceId.current) {
1620
- mapHook.map.removeLayer(layerId);
1621
- }
1622
- }
1623
- if (mapHook.map.getSource(sourceId.current)) {
1624
- mapHook.map.removeSource(sourceId.current);
1625
- }
1626
- }
1627
- }, [mapHook.map]);
1628
- var createSource = useCallback(function () {
1629
- var _a;
1630
- if (!mapHook.map)
1631
- return;
1632
- if (props.source.type === 'geojson' && !props.source.data)
1633
- return;
1634
- if (mapHook.map.map.getSource(sourceId.current)) {
1635
- removeSource();
1636
- }
1637
- (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source));
1638
- setSource(mapHook.map.map.getSource(sourceId.current));
1639
- }, [props, mapHook, removeSource]);
1640
- useEffect(function () {
1641
- var _a, _b, _c, _d;
1642
- if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(sourceId.current)))
1643
- return;
1644
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1645
- //@ts-ignore setData only exists on GeoJsonSource
1646
- (_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);
1647
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1648
- //@ts-ignore data only exists on GeoJsonSource
1649
- }, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
1650
- useEffect(function () {
1651
- var _a, _b, _c;
1652
- 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)
1653
- return;
1654
- sourceId.current = props.sourceId;
1655
- createSource();
1656
- }, [mapHook.map, props, createSource]);
1657
- useEffect(function () {
1658
- if (!mapHook.map)
1659
- return;
1660
- var checkSourceHandler = function () {
1661
- var _a, _b;
1662
- if (!((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getSource) === null || _b === void 0 ? void 0 : _b.call(_a, props.sourceId))) {
1663
- createSource();
1664
- }
1665
- };
1666
- mapHook.map.on('styledata', checkSourceHandler);
1667
- return function () {
1668
- if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
1669
- mapHook.map.off('styledata', checkSourceHandler);
1670
- }
1671
- };
1672
- }, [mapHook.map, createSource]);
1673
- //cleanup
1674
- useEffect(function () {
1675
- return function () {
1676
- removeSource();
1677
- };
1678
- }, [removeSource]);
1679
- return {
1680
- map: mapHook.map,
1681
- source: source,
1682
- componentId: mapHook.componentId,
1683
- mapHook: mapHook,
1684
- };
1685
- }
1686
-
1687
- /**
1688
- * Adds source and layer to display GeoJSON data on the map.
1689
- *
1690
- * @component
1691
- */
1692
- var MlGeoJsonLayer = function (props) {
1693
- var _a, _b, _c, _d, _e, _f, _g, _h;
1694
- var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
1695
- var layerId = useRef(props.layerId || 'MlGeoJsonLayer-' + v4());
1696
- var labelLayerId = "label-".concat(layerId.current);
1697
- useEffect(function () {
1698
- if (!props.layerId) {
1699
- layerId.current = 'MlGeoJsonLayer-' + v4();
1700
- }
1701
- else {
1702
- layerId.current = props.layerId;
1703
- }
1704
- }, [props.layerId]);
1705
- useSource({
1706
- mapId: props.mapId,
1707
- sourceId: 'source-' + layerId.current,
1708
- source: __assign({ type: 'geojson', data: props.geojson }, (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'undefined' &&
1709
- typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string'
1710
- ? props.options.source
1711
- : {})),
1712
- });
1713
- useLayer({
1714
- mapId: props.mapId,
1715
- layerId: layerId.current,
1716
- options: __assign(__assign({}, props.options), { source: 'source-' + layerId.current, paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.layout), type: layerType }),
1717
- insertBeforeLayer: props.insertBeforeLayer,
1718
- onHover: props.onHover,
1719
- onClick: props.onClick,
1720
- onLeave: props.onLeave,
1721
- });
1722
- // Label useLayer hook can't be called conditionally.
1723
- // Using it with geojson and options.source undefined will cause it to return without creating a layer.
1724
- useLayer({
1725
- mapId: props.mapId,
1726
- 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 : {})), (((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_f = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _f === void 0 ? void 0 : _f.layout) ? props.labelOptions.layout : {})), (((_g = props === null || props === void 0 ? void 0 : props.layout) === null || _g === void 0 ? void 0 : _g.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_h = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _h === void 0 ? void 0 : _h.paint) ? props.labelOptions.paint : {})) }),
1727
- });
1728
- return React__default.createElement(React__default.Fragment, null);
1729
- };
1730
-
1731
- // Determine the GeoJSON-Feature-Type
1732
- function determineFeatureType(coordinates) {
1733
- if (Array.isArray(coordinates)) {
1734
- if (coordinates.length === 2 &&
1735
- typeof coordinates[0] === 'number' &&
1736
- typeof coordinates[1] === 'number') {
1737
- return 'Point';
1738
- }
1739
- else if (Array.isArray(coordinates[0])) {
1740
- if (coordinates.every(function (coord) {
1741
- return Array.isArray(coord) &&
1742
- coord.length === 2 &&
1743
- typeof coord[0] === 'number' &&
1744
- typeof coord[1] === 'number';
1745
- })) {
1746
- return 'LineString';
1747
- }
1748
- else if (coordinates.every(function (coord) { return Array.isArray(coord) && Array.isArray(coord[0]); })) {
1749
- // an array of arrays can be a multi-linestring or polygon,
1750
- // if the first and last coordinate is the same, it is a polygon
1751
- if (coordinates[0][0][0] === coordinates[0][coordinates[0].length - 1][0] &&
1752
- coordinates[0][0][1] === coordinates[0][coordinates[0].length - 1][1]) {
1753
- return 'Polygon';
1754
- }
1755
- else {
1756
- return 'MultiLineString';
1757
- }
1758
- }
1759
- }
1760
- }
1761
- throw new Error('Invalid coordinate structure for a GeoJSON feature type determination.');
1762
- }
1763
- // Create GeoJSON-Features
1764
- function createGeoJSONFeature(coordinates) {
1765
- var featureType = determineFeatureType(coordinates);
1766
- return {
1767
- type: 'Feature',
1768
- geometry: {
1769
- type: featureType,
1770
- coordinates: coordinates,
1771
- },
1772
- properties: {},
1773
- };
1774
- }
1775
-
1776
- var SearchContext = React__default.createContext({});
1777
- var SearchContextProvider = function (_a) {
1778
- var children = _a.children, searchIndex = _a.searchIndex, renderOption = _a.renderOption, searchFieldLabel = _a.searchFieldLabel, fields = _a.fields;
1779
- var _b = useState(undefined), searchIndexInstance = _b[0], setSearchIndexInstance = _b[1];
1780
- var _c = useState(undefined), searchTerm = _c[0], setSearchTerm = _c[1];
1781
- var _d = useState([]), searchResults = _d[0], setSearchResults = _d[1];
1782
- var _e = useState([]), searchResultsArray = _e[0], setSearchResultsArray = _e[1];
1783
- var _f = useState(undefined), selectedResult = _f[0], setSelectedResult = _f[1];
1784
- var _g = useState(), feature = _g[0], setFeature = _g[1];
1785
- var mapHook = useMap({
1786
- mapId: undefined,
1787
- });
1788
- useEffect(function () {
1789
- setSearchIndexInstance(elasticlunr.Index.load(searchIndex));
1790
- }, [searchIndex]);
1791
- var getBoundingBox = function (geometry) {
1792
- var _a;
1793
- if (((_a = geometry.geometry.coordinates) === null || _a === void 0 ? void 0 : _a.length) === 2) {
1794
- geometry = turf.buffer(geometry, 1, {
1795
- units: 'kilometers',
1796
- });
1797
- }
1798
- return turf.bbox(geometry);
1799
- };
1800
- useEffect(function () {
1801
- if (searchTerm && searchIndexInstance) {
1802
- var results = searchIndexInstance.search(searchTerm.toString(), { fields: fields });
1803
- var maxResults = 10;
1804
- var resultsLimited = results
1805
- .filter(function (result) { return result !== undefined; })
1806
- .slice(0, maxResults)
1807
- .map(function (result) {
1808
- var propertyNames = Object.keys(fields);
1809
- propertyNames.forEach(function () {
1810
- if (searchIndexInstance.documentStore.getDoc(result.ref)) {
1811
- result = searchIndexInstance.documentStore.getDoc(result.ref);
1812
- }
1813
- });
1814
- return result;
1815
- });
1816
- setSearchResults(resultsLimited);
1817
- }
1818
- }, [searchTerm, searchIndexInstance, fields]);
1819
- useEffect(function () {
1820
- if (selectedResult && mapHook.map) {
1821
- if (typeof selectedResult === 'object' && 'COORDINATES' in selectedResult) {
1822
- var createdFeature = createGeoJSONFeature(selectedResult.COORDINATES);
1823
- var bbox = getBoundingBox(createdFeature);
1824
- setFeature(createdFeature);
1825
- mapHook.map.fitBounds(bbox);
1826
- }
1827
- }
1828
- }, [selectedResult, mapHook.map]);
1829
- var value = {
1830
- searchTerm: searchTerm,
1831
- setSearchTerm: setSearchTerm,
1832
- searchResults: searchResults,
1833
- setSearchResults: setSearchResults,
1834
- searchResultsArray: searchResultsArray,
1835
- setSearchResultsArray: setSearchResultsArray,
1836
- selectedResult: selectedResult,
1837
- setSelectedResult: setSelectedResult,
1838
- searchIndex: searchIndex,
1839
- fields: fields,
1840
- searchIndexInstance: searchIndexInstance,
1841
- renderOption: renderOption,
1842
- searchFieldLabel: searchFieldLabel,
1843
- };
1844
- return (React__default.createElement(React__default.Fragment, null,
1845
- React__default.createElement(SearchContext.Provider, { value: value },
1846
- " ",
1847
- children),
1848
- feature && React__default.createElement(MlGeoJsonLayer, { geojson: feature })));
1849
- };
1850
-
1851
- function debounce(func, wait) {
1852
- var timeout;
1853
- return function executedFunction(e) {
1854
- var later = function () {
1855
- clearTimeout(timeout);
1856
- func(e);
1857
- };
1858
- clearTimeout(timeout);
1859
- timeout = setTimeout(later, wait);
1860
- };
1861
- }
1862
- function SearchForm() {
1863
- var searchContext = useContext(SearchContext);
1864
- function formatObjectProperties(input) {
1865
- if (!input)
1866
- return '';
1867
- if (typeof input === 'object') {
1868
- return processObject(input);
1869
- }
1870
- if (typeof input === 'string' &&
1871
- (input.trim().startsWith('{') || input.trim().startsWith('['))) {
1872
- try {
1873
- var parsed = JSON.parse(input);
1874
- if (Array.isArray(parsed)) {
1875
- return parsed.map(processObject).join('; ');
1876
- }
1877
- else {
1878
- return processObject(parsed);
1879
- }
1880
- }
1881
- catch (error) {
1882
- console.error('Error parsing JSON:', error);
1883
- return '';
1884
- }
1885
- }
1886
- else if (typeof input === 'string') {
1887
- return input;
1888
- }
1889
- console.error('Invalid input type.');
1890
- return '';
1891
- }
1892
- function processObject(obj) {
1893
- var keys = searchContext.searchIndex.fields;
1894
- var filteredKeys = Object.keys(obj).filter(function (key) { return keys.includes(key); });
1895
- return filteredKeys.map(function (key) { return obj[key]; }).join(', ');
1896
- }
1897
- var debouncedHandleInput = useCallback(debounce(function (e) {
1898
- searchContext.setSearchTerm(e.target.value);
1899
- }, 200), [searchContext]);
1900
- return (React__default.createElement(React__default.Fragment, null,
1901
- React__default.createElement(Autocomplete, { options: (searchContext === null || searchContext === void 0 ? void 0 : searchContext.searchResults) || [], noOptionsText: "Keine Optionen verf\u00FCgbar.", onSelect: debouncedHandleInput, value: formatObjectProperties(searchContext === null || searchContext === void 0 ? void 0 : searchContext.selectedResult) || null, isOptionEqualToValue: function (option) { return option === (searchContext === null || searchContext === void 0 ? void 0 : searchContext.selectedResult); }, getOptionLabel: function (option) { return formatObjectProperties(option); }, onChange: function (_, newValue) {
1902
- searchContext === null || searchContext === void 0 ? void 0 : searchContext.setSelectedResult(newValue !== null && newValue !== void 0 ? newValue : undefined);
1903
- }, renderOption: searchContext === null || searchContext === void 0 ? void 0 : searchContext.renderOption, sx: { width: 250 }, renderInput: function (params) {
1904
- return React__default.createElement(TextField, __assign({}, params, { label: searchContext === null || searchContext === void 0 ? void 0 : searchContext.searchFieldLabel }));
1905
- } })));
1906
- }
1907
-
1908
- /**
1909
- * Component template
1910
- *
1911
- */
1912
- var MlClientSearch = function (_a) {
1913
- var searchIndex = _a.searchIndex, fields = _a.fields, renderOption = _a.renderOption, searchFieldLabel = _a.searchFieldLabel;
1914
- return (React__default.createElement(React__default.Fragment, null,
1915
- React__default.createElement(SearchContextProvider, { searchIndex: searchIndex, fields: fields, renderOption: renderOption, searchFieldLabel: searchFieldLabel },
1916
- React__default.createElement(SearchForm, null))));
1917
- };
1918
- MlClientSearch.defaultProps = {};
1919
-
1920
- /**
1921
- * Component description
1922
- *
1923
- */
1924
- var MlComponentTemplate = function (props) {
1925
- var mapHook = useMap({
1926
- mapId: props.mapId,
1927
- });
1928
- console.log(mapHook.componentId + " remove this log");
1929
- return React__default.createElement(React__default.Fragment, null);
1930
- };
1931
- MlComponentTemplate.defaultProps = {
1932
- mapId: undefined,
1933
- };
1934
-
1935
- var createExport = function (options) {
1936
- var width = options.width;
1937
- var height = options.height;
1938
- // Create map container
1939
- var hiddenContainer = document.createElement('div');
1940
- hiddenContainer.className = 'hidden-map';
1941
- hiddenContainer.style.width = '0px';
1942
- hiddenContainer.style.height = '0px';
1943
- hiddenContainer.style.overflow = 'hidden';
1944
- document.body.appendChild(hiddenContainer);
1945
- var container = document.createElement('div');
1946
- container.style.width = width + 'px';
1947
- container.style.height = height + 'px';
1948
- hiddenContainer.appendChild(container);
1949
- var style = options.map.map.getStyle();
1950
- var _loop_1 = function (name_1) {
1951
- var src = style.sources[name_1];
1952
- Object.keys(src).forEach(function (key) {
1953
- // delete property if value is undefined.
1954
- // for instance, raster-dem might have undefined value in "url" and "bounds"
1955
- if (!src[key]) {
1956
- delete src[key];
1957
- }
1958
- });
1959
- };
1960
- // delete undefined source properties
1961
- for (var name_1 in style.sources) {
1962
- _loop_1(name_1);
1963
- }
1964
- // Create a new MapLibre-gl instance
1965
- var renderMap = new Map({
1966
- container: container,
1967
- center: options.map.map.getCenter(),
1968
- zoom: options.map.map.getZoom(),
1969
- bearing: 0,
1970
- pitch: 0,
1971
- interactive: false,
1972
- preserveDrawingBuffer: true,
1973
- fadeDuration: 0,
1974
- attributionControl: false,
1975
- style: style,
1976
- });
1977
- var bboxCamera = renderMap._cameraForBoxAndBearing([options.bboxUnrotated[0], options.bboxUnrotated[1]], [options.bboxUnrotated[2], options.bboxUnrotated[3]], options.bearing + options.map.map.getBearing());
1978
- renderMap._fitInternal(bboxCamera);
1979
- return new Promise(function (resolve) {
1980
- console.log('before idle');
1981
- renderMap.once('idle', function () {
1982
- var params = __assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer, createPdf: function (_options) {
1983
- return createJsPdf(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
1984
- }, createPng: function (_options) {
1985
- return createPng(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
1986
- } });
1987
- resolve(params);
1988
- });
1989
- });
1990
- };
1991
- function createJsPdf(options) {
1992
- var pdf = new jsPDF({
1993
- orientation: (options === null || options === void 0 ? void 0 : options.orientation) === 'portrait' ? 'p' : 'l',
1994
- unit: 'mm',
1995
- compress: true,
1996
- format: options.format,
1997
- });
1998
- Object.defineProperty(window, 'devicePixelRatio', {
1999
- get: function () {
2000
- return 300 / 96;
2001
- },
2002
- });
2003
- return new Promise(function (resolve) {
2004
- var _b;
2005
- //Render map image
2006
- pdf.addImage(options.renderMap.getCanvas().toDataURL('image/png'), 'png', 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight(), undefined, 'FAST');
2007
- // remove DOM Elements
2008
- options.renderMap.remove();
2009
- (_b = options.hiddenContainer.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(options.hiddenContainer);
2010
- var params = __assign(__assign({}, options), { pdf: pdf, downloadPdf: function (_options) { return downloadPdf(__assign(__assign({}, params), _options)); }, formData: new FormData() });
2011
- resolve(params);
2012
- });
2013
- }
2014
- function downloadPdf(options) {
2015
- options.pdf.save('Map.pdf');
2016
- return new Promise(function (resolve) {
2017
- resolve(__assign({}, options));
2018
- });
2019
- }
2020
- function createPng(options) {
2021
- return new Promise(function (resolve) {
2022
- var png = options.renderMap.getCanvas().toDataURL('image/png');
2023
- var params = __assign(__assign({}, options), { png: png, downloadPng: function (_options) { return downloadPng(__assign(__assign({}, params), _options)); } });
2024
- resolve(params);
2025
- });
2026
- }
2027
- function downloadPng(options) {
2028
- var _a = document.createElement('a');
2029
- _a.download = (options === null || options === void 0 ? void 0 : options.name) ? options.name + '.png' : 'map.png';
2030
- _a.href = options.png;
2031
- document.body.appendChild(_a);
2032
- _a.click();
2033
- document.body.removeChild(_a);
2034
- return new Promise(function (resolve) {
2035
- resolve(__assign({}, options));
2036
- });
2037
- }
2038
-
2039
- function useExportMap(props) {
2040
- var mapHook = useMap({ mapId: props.mapId });
2041
- var _createExport = useMemo(function () {
2042
- if (mapHook.map) {
2043
- return function (options) {
2044
- return createExport(__assign({ map: mapHook.map }, options));
2045
- };
2046
- }
2047
- return;
2048
- }, [mapHook.map]);
2049
- return {
2050
- createExport: _createExport,
2051
- };
2052
- }
2053
-
2054
- /**
2055
- * Renders a button that will create a PDF version of the current map view (dimensions adjusted to fit Din A4 Paper).
2056
- */
2057
- var MlCreatePdfButton = function (props) {
1422
+ function createPng(options) {
1423
+ return new Promise(function (resolve) {
1424
+ var png = options.renderMap.getCanvas().toDataURL('image/png');
1425
+ var params = __assign(__assign({}, options), { png: png, downloadPng: function (_options) { return downloadPng(__assign(__assign({}, params), _options)); } });
1426
+ resolve(params);
1427
+ });
1428
+ }
1429
+ function downloadPng(options) {
1430
+ var _a = document.createElement('a');
1431
+ _a.download = (options === null || options === void 0 ? void 0 : options.name) ? options.name + '.png' : 'map.png';
1432
+ _a.href = options.png;
1433
+ document.body.appendChild(_a);
1434
+ _a.click();
1435
+ document.body.removeChild(_a);
1436
+ return new Promise(function (resolve) {
1437
+ resolve(__assign({}, options));
1438
+ });
1439
+ }
1440
+
1441
+ function useExportMap(props) {
1442
+ var mapHook = useMap({ mapId: props.mapId });
1443
+ var _createExport = useMemo(function () {
1444
+ if (mapHook.map) {
1445
+ return function (options) {
1446
+ return createExport(__assign({ map: mapHook.map }, options));
1447
+ };
1448
+ }
1449
+ return;
1450
+ }, [mapHook.map]);
1451
+ return {
1452
+ createExport: _createExport,
1453
+ };
1454
+ }
1455
+
1456
+ /**
1457
+ * Renders a button that will create a PDF version of the current map view (dimensions adjusted to fit Din A4 Paper).
1458
+ */
1459
+ var MlCreatePdfButton = function (props) {
2058
1460
  var mapHook = useMap({
2059
1461
  mapId: props.mapId,
2060
1462
  });
@@ -2880,48 +2282,272 @@ var useFeatureEditor = function (props) {
2880
2282
  mapHook.map.on('mouseup', changeHandler);
2881
2283
  mapHook.map.on('touchend', changeHandler);
2882
2284
  return function () {
2883
- if (!mapHook.map)
2884
- return;
2885
- mapHook.map.map.off('mouseup', changeHandler);
2886
- mapHook.map.map.off('touchend', changeHandler);
2285
+ if (!mapHook.map)
2286
+ return;
2287
+ mapHook.map.map.off('mouseup', changeHandler);
2288
+ mapHook.map.map.off('touchend', changeHandler);
2289
+ };
2290
+ }, [drawToolsReady, mapHook.map]);
2291
+ useEffect(function () {
2292
+ var _a;
2293
+ if (draw.current && ((_a = props.geojson) === null || _a === void 0 ? void 0 : _a.geometry)) {
2294
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2295
+ // @ts-ignore
2296
+ draw.current.set({ type: 'FeatureCollection', features: [props.geojson] });
2297
+ }
2298
+ }, [props.geojson, drawToolsReady]);
2299
+ useEffect(function () {
2300
+ var _a, _b, _c, _d;
2301
+ if (props.mode && draw.current && ((_b = (_a = draw.current) === null || _a === void 0 ? void 0 : _a.getMode) === null || _b === void 0 ? void 0 : _b.call(_a)) !== props.mode) {
2302
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2303
+ // @ts-ignore
2304
+ (_d = (_c = draw.current) === null || _c === void 0 ? void 0 : _c.changeMode) === null || _d === void 0 ? void 0 : _d.call(_c, props.mode);
2305
+ if (props.mode !== 'simple_select' && props.mode !== 'direct_select') {
2306
+ draw.current.set({ type: 'FeatureCollection', features: [] });
2307
+ }
2308
+ }
2309
+ }, [props.mode, mapHook.map]);
2310
+ return {
2311
+ feature: feature,
2312
+ drawToolsReady: drawToolsReady,
2313
+ draw: draw.current,
2314
+ };
2315
+ };
2316
+
2317
+ var MlFeatureEditor = function (props) {
2318
+ useFeatureEditor({
2319
+ mode: props.mode,
2320
+ geojson: props.geojson,
2321
+ onChange: props.onChange,
2322
+ onFinish: props.onFinish,
2323
+ mapId: props.mapId,
2324
+ });
2325
+ return (React__default.createElement(React__default.Fragment, null));
2326
+ };
2327
+
2328
+ var legalLayerTypes = [
2329
+ 'fill',
2330
+ 'line',
2331
+ 'symbol',
2332
+ 'circle',
2333
+ 'heatmap',
2334
+ 'fill-extrusion',
2335
+ 'raster',
2336
+ 'hillshade',
2337
+ 'background',
2338
+ ];
2339
+ function determineSource(props) {
2340
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2341
+ if (typeof props.options.source === 'string') {
2342
+ return {
2343
+ source: props.options.source,
2344
+ };
2345
+ }
2346
+ else if (props.geojson &&
2347
+ (!((_a = props.options) === null || _a === void 0 ? void 0 : _a.source) ||
2348
+ (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
2349
+ ((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.attribution) &&
2350
+ !((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.source) === null || _f === void 0 ? void 0 : _f.type)))) {
2351
+ return {
2352
+ source: {
2353
+ type: 'geojson',
2354
+ data: props.geojson || '',
2355
+ attribution: typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'string' && ((_h = props.options.source) === null || _h === void 0 ? void 0 : _h.attribution)
2356
+ ? (_j = props.options.source) === null || _j === void 0 ? void 0 : _j.attribution
2357
+ : '',
2358
+ },
2359
+ };
2360
+ }
2361
+ return {};
2362
+ }
2363
+ function determineInsertionPoint(props, mapHook) {
2364
+ var _a;
2365
+ if (props === null || props === void 0 ? void 0 : props.insertBeforeLayer)
2366
+ return props.insertBeforeLayer;
2367
+ if (props === null || props === void 0 ? void 0 : props.insertBeforeFirstSymbolLayer)
2368
+ return (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.firstSymbolLayer;
2369
+ return undefined;
2370
+ }
2371
+ function useLayer(props) {
2372
+ var _a;
2373
+ var mapHook = useMap({
2374
+ mapId: props.mapId,
2375
+ waitForLayer: props.insertBeforeLayer,
2376
+ });
2377
+ var layerTypeRef = useRef('');
2378
+ var layerPaintConfRef = useRef('');
2379
+ var layerLayoutConfRef = useRef('');
2380
+ var _b = useState(), layer = _b[0], setLayer = _b[1];
2381
+ var layerId = useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
2382
+ var createLayer = useCallback(function () {
2383
+ var _a, _b, _c, _d, _e, _f, _g;
2384
+ if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
2385
+ return;
2386
+ if (mapHook.map.map.getLayer(layerId.current)) {
2387
+ mapHook.cleanup();
2388
+ }
2389
+ 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)) {
2390
+ mapHook.map.map.removeSource(layerId.current);
2391
+ }
2392
+ if (typeof props.options.source === 'string') {
2393
+ if (props.options.source === '' || !mapHook.map.map.getSource(props.options.source)) {
2394
+ return;
2395
+ }
2396
+ }
2397
+ if (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
2398
+ !props.geojson &&
2399
+ !((_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) &&
2400
+ ((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.type) !== 'background') {
2401
+ return;
2402
+ }
2403
+ if (typeof props.options.type === 'undefined') {
2404
+ return;
2405
+ }
2406
+ try {
2407
+ mapHook.map.addLayer(__assign(__assign(__assign({}, props.options), determineSource(props)), { id: layerId.current }), determineInsertionPoint(props, mapHook), mapHook.componentId);
2408
+ }
2409
+ catch (error) {
2410
+ console.error('Failed to add layer:', error);
2411
+ }
2412
+ setLayer(function () { var _a; return (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current); });
2413
+ if (typeof props.onHover !== 'undefined') {
2414
+ mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
2415
+ }
2416
+ if (typeof props.onClick !== 'undefined') {
2417
+ mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
2418
+ }
2419
+ if (typeof props.onLeave !== 'undefined') {
2420
+ mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
2421
+ }
2422
+ // recreate layer if style has changed
2423
+ var styledataEventHandler = function () {
2424
+ var _a;
2425
+ if (!((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
2426
+ createLayer();
2427
+ }
2428
+ };
2429
+ mapHook.map.on('styledata', styledataEventHandler, mapHook.componentId);
2430
+ var addSourceHandler = function (_ev, _wrapper, _a) {
2431
+ var _b;
2432
+ var source_id = _a.source_id;
2433
+ if (mapHook.map &&
2434
+ typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
2435
+ props.options.source === source_id) {
2436
+ createLayer();
2437
+ }
2438
+ };
2439
+ mapHook.map.wrapper.on('addsource', addSourceHandler, mapHook.componentId);
2440
+ layerPaintConfRef.current = JSON.stringify((_f = props.options) === null || _f === void 0 ? void 0 : _f.paint);
2441
+ layerLayoutConfRef.current = JSON.stringify((_g = props.options) === null || _g === void 0 ? void 0 : _g.layout);
2442
+ layerTypeRef.current = props.options.type;
2443
+ }, [props, mapHook]);
2444
+ useEffect(function () {
2445
+ var _a, _b, _c, _d, _e;
2446
+ if (!mapHook.map)
2447
+ return;
2448
+ if (!props.geojson && !props.options.source && ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.type) !== 'background')
2449
+ return;
2450
+ if (((_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.cancelled) === false &&
2451
+ ((_e = (_d = (_c = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.getLayer) === null || _e === void 0 ? void 0 : _e.call(_d, layerId.current)) &&
2452
+ (legalLayerTypes.indexOf(props.options.type) === -1 ||
2453
+ (legalLayerTypes.indexOf(props.options.type) !== -1 &&
2454
+ props.options.type === layerTypeRef.current))) {
2455
+ return;
2456
+ }
2457
+ createLayer();
2458
+ }, [mapHook.map, mapHook.mapIsReady, props, createLayer]);
2459
+ useEffect(function () {
2460
+ var _a, _b, _c, _d, _e, _f;
2461
+ if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true || !((_d = (_c = (_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getSource) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)))
2462
+ return;
2463
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2464
+ //@ts-ignore setData only exists on GeoJsonSource
2465
+ (_f = (_e = mapHook.map.map.getSource(layerId.current)) === null || _e === void 0 ? void 0 : _e.setData) === null || _f === void 0 ? void 0 : _f.call(_e, props.geojson);
2466
+ }, [props.geojson, mapHook.map, props.options.type]);
2467
+ useEffect(function () {
2468
+ var _a, _b, _c, _d, _e, _f;
2469
+ if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
2470
+ !mapHook.map ||
2471
+ !((_d = (_c = (_b = 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)) ||
2472
+ props.options.type !== layerTypeRef.current)
2473
+ return;
2474
+ var key;
2475
+ var layoutString = JSON.stringify(props.options.layout);
2476
+ if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
2477
+ var oldLayout = JSON.parse(layerLayoutConfRef.current);
2478
+ for (key in props.options.layout) {
2479
+ if (((_e = props.options.layout) === null || _e === void 0 ? void 0 : _e[key]) &&
2480
+ props.options.layout[key] !== oldLayout[key]) {
2481
+ mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
2482
+ }
2483
+ }
2484
+ layerLayoutConfRef.current = layoutString;
2485
+ }
2486
+ var paintString = JSON.stringify(props.options.paint);
2487
+ if (paintString !== layerPaintConfRef.current) {
2488
+ var oldPaint = JSON.parse(layerPaintConfRef.current);
2489
+ for (key in props.options.paint) {
2490
+ if (((_f = props.options.paint) === null || _f === void 0 ? void 0 : _f[key]) &&
2491
+ props.options.paint[key] !== oldPaint[key]) {
2492
+ mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
2493
+ }
2494
+ }
2495
+ layerPaintConfRef.current = paintString;
2496
+ }
2497
+ }, [props.options, mapHook.map]);
2498
+ useEffect(function () {
2499
+ if (!props.insertBeforeLayer ||
2500
+ !mapHook.map ||
2501
+ !mapHook.map.getLayer(props.insertBeforeLayer) ||
2502
+ !mapHook.map.getLayer(layerId.current))
2503
+ return;
2504
+ mapHook.map.moveLayer(layerId.current, props.insertBeforeLayer);
2505
+ }, [mapHook.map, props.insertBeforeLayer]);
2506
+ useEffect(function () {
2507
+ return function () {
2508
+ mapHook.cleanup();
2887
2509
  };
2888
- }, [drawToolsReady, mapHook.map]);
2510
+ }, []);
2889
2511
  useEffect(function () {
2890
2512
  var _a;
2891
- if (draw.current && ((_a = props.geojson) === null || _a === void 0 ? void 0 : _a.geometry)) {
2892
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2893
- // @ts-ignore
2894
- draw.current.set({ type: 'FeatureCollection', features: [props.geojson] });
2513
+ if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' || !mapHook.map) {
2514
+ return;
2895
2515
  }
2896
- }, [props.geojson, drawToolsReady]);
2897
- useEffect(function () {
2898
- var _a, _b, _c, _d;
2899
- if (props.mode && draw.current && ((_b = (_a = draw.current) === null || _a === void 0 ? void 0 : _a.getMode) === null || _b === void 0 ? void 0 : _b.call(_a)) !== props.mode) {
2900
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2901
- // @ts-ignore
2902
- (_d = (_c = draw.current) === null || _c === void 0 ? void 0 : _c.changeMode) === null || _d === void 0 ? void 0 : _d.call(_c, props.mode);
2903
- if (props.mode !== 'simple_select' && props.mode !== 'direct_select') {
2904
- draw.current.set({ type: 'FeatureCollection', features: [] });
2516
+ var findSourceHandler = function () {
2517
+ var _a, _b, _c;
2518
+ if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) === 'string' &&
2519
+ ((_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)) &&
2520
+ !mapHook.map.getLayer(layerId.current)) {
2521
+ createLayer();
2905
2522
  }
2906
- }
2907
- }, [props.mode, mapHook.map]);
2523
+ };
2524
+ mapHook.map.on('sourcedataloading', findSourceHandler);
2525
+ var addSourceHandler = function (_ev, _wrapper, _a) {
2526
+ var _b;
2527
+ var source_id = _a.source_id;
2528
+ if (mapHook.map &&
2529
+ typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
2530
+ props.options.source === source_id) {
2531
+ createLayer();
2532
+ }
2533
+ };
2534
+ mapHook.map.wrapper.on('addsource', addSourceHandler);
2535
+ return function () {
2536
+ if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
2537
+ mapHook.map.off('sourcedataloading', findSourceHandler);
2538
+ mapHook.map.wrapper.off('addsource', addSourceHandler);
2539
+ }
2540
+ };
2541
+ }, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
2908
2542
  return {
2909
- feature: feature,
2910
- drawToolsReady: drawToolsReady,
2911
- draw: draw.current,
2543
+ map: mapHook.map,
2544
+ layer: layer,
2545
+ layerId: layerId.current,
2546
+ componentId: mapHook.componentId,
2547
+ mapHook: mapHook,
2912
2548
  };
2913
- };
2914
-
2915
- var MlFeatureEditor = function (props) {
2916
- useFeatureEditor({
2917
- mode: props.mode,
2918
- geojson: props.geojson,
2919
- onChange: props.onChange,
2920
- onFinish: props.onFinish,
2921
- mapId: props.mapId,
2922
- });
2923
- return (React__default.createElement(React__default.Fragment, null));
2924
- };
2549
+ }
2550
+ useLayer.defaultProps = {};
2925
2551
 
2926
2552
  /**
2927
2553
  * Adds a fill extrusion layer to the MapLibre instance reference by props.mapId
@@ -2959,6 +2585,190 @@ MlFillExtrusionLayer.defaultProps = {
2959
2585
  },
2960
2586
  };
2961
2587
 
2588
+ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
2589
+ switch (type) {
2590
+ case 'fill':
2591
+ if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.fill) {
2592
+ return defaultPaintOverrides.fill;
2593
+ }
2594
+ return {
2595
+ 'fill-color': 'rgba(10,240,256,0.6)',
2596
+ 'fill-outline-color': 'rgba(20,230,256,0.8)',
2597
+ };
2598
+ case 'line':
2599
+ if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
2600
+ return defaultPaintOverrides.line;
2601
+ }
2602
+ return {
2603
+ 'line-color': 'rgb(203,211,2)',
2604
+ 'line-width': 5,
2605
+ 'line-blur': 0,
2606
+ };
2607
+ case 'circle':
2608
+ if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.circle) {
2609
+ return defaultPaintOverrides.circle;
2610
+ }
2611
+ return {
2612
+ 'circle-color': 'rgba(10,240,256,0.8)',
2613
+ 'circle-stroke-color': '#fff',
2614
+ 'circle-stroke-width': 2,
2615
+ 'circle-radius': 4,
2616
+ };
2617
+ default:
2618
+ return {};
2619
+ }
2620
+ };
2621
+
2622
+ var mapGeometryTypesToLayerTypes = {
2623
+ Position: "circle",
2624
+ Point: "circle",
2625
+ MultiPoint: "circle",
2626
+ LineString: "line",
2627
+ MultiLineString: "line",
2628
+ Polygon: "fill",
2629
+ MultiPolygon: "fill",
2630
+ GeometryCollection: "circle",
2631
+ };
2632
+ var getDefaulLayerTypeByGeometry = function (geojson) {
2633
+ var _a;
2634
+ if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
2635
+ return (mapGeometryTypesToLayerTypes === null || mapGeometryTypesToLayerTypes === void 0 ? void 0 : mapGeometryTypesToLayerTypes[(_a = geojson === null || geojson === void 0 ? void 0 : geojson.geometry) === null || _a === void 0 ? void 0 : _a.type])
2636
+ ? mapGeometryTypesToLayerTypes[geojson.geometry.type]
2637
+ : "circle";
2638
+ }
2639
+ if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
2640
+ if (geojson.features.length) {
2641
+ return getDefaulLayerTypeByGeometry(geojson.features[0]);
2642
+ }
2643
+ return "circle";
2644
+ }
2645
+ return "fill";
2646
+ };
2647
+
2648
+ function useSource(props) {
2649
+ var _a;
2650
+ var mapHook = useMap({
2651
+ mapId: props.mapId,
2652
+ });
2653
+ var _b = useState(), source = _b[0], setSource = _b[1];
2654
+ var sourceId = useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
2655
+ var removeSource = useCallback(function () {
2656
+ var _a, _b;
2657
+ if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
2658
+ for (var _i = 0, _c = Object.entries(mapHook.map.map.style._layers); _i < _c.length; _i++) {
2659
+ var _d = _c[_i], layerId = _d[0], layer = _d[1];
2660
+ if (layer.source === sourceId.current) {
2661
+ mapHook.map.removeLayer(layerId);
2662
+ }
2663
+ }
2664
+ if (mapHook.map.getSource(sourceId.current)) {
2665
+ mapHook.map.removeSource(sourceId.current);
2666
+ }
2667
+ }
2668
+ }, [mapHook.map]);
2669
+ var createSource = useCallback(function () {
2670
+ var _a;
2671
+ if (!mapHook.map)
2672
+ return;
2673
+ if (props.source.type === 'geojson' && !props.source.data)
2674
+ return;
2675
+ if (mapHook.map.map.getSource(sourceId.current)) {
2676
+ removeSource();
2677
+ }
2678
+ (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source));
2679
+ setSource(mapHook.map.map.getSource(sourceId.current));
2680
+ }, [props, mapHook, removeSource]);
2681
+ useEffect(function () {
2682
+ var _a, _b, _c, _d;
2683
+ if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(sourceId.current)))
2684
+ return;
2685
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2686
+ //@ts-ignore setData only exists on GeoJsonSource
2687
+ (_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);
2688
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2689
+ //@ts-ignore data only exists on GeoJsonSource
2690
+ }, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
2691
+ useEffect(function () {
2692
+ var _a, _b, _c;
2693
+ 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)
2694
+ return;
2695
+ sourceId.current = props.sourceId;
2696
+ createSource();
2697
+ }, [mapHook.map, props, createSource]);
2698
+ useEffect(function () {
2699
+ if (!mapHook.map)
2700
+ return;
2701
+ var checkSourceHandler = function () {
2702
+ var _a, _b;
2703
+ if (!((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getSource) === null || _b === void 0 ? void 0 : _b.call(_a, props.sourceId))) {
2704
+ createSource();
2705
+ }
2706
+ };
2707
+ mapHook.map.on('styledata', checkSourceHandler);
2708
+ return function () {
2709
+ if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
2710
+ mapHook.map.off('styledata', checkSourceHandler);
2711
+ }
2712
+ };
2713
+ }, [mapHook.map, createSource]);
2714
+ //cleanup
2715
+ useEffect(function () {
2716
+ return function () {
2717
+ removeSource();
2718
+ };
2719
+ }, [removeSource]);
2720
+ return {
2721
+ map: mapHook.map,
2722
+ source: source,
2723
+ componentId: mapHook.componentId,
2724
+ mapHook: mapHook,
2725
+ };
2726
+ }
2727
+
2728
+ /**
2729
+ * Adds source and layer to display GeoJSON data on the map.
2730
+ *
2731
+ * @component
2732
+ */
2733
+ var MlGeoJsonLayer = function (props) {
2734
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2735
+ var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
2736
+ var layerId = useRef(props.layerId || 'MlGeoJsonLayer-' + v4());
2737
+ var labelLayerId = "label-".concat(layerId.current);
2738
+ useEffect(function () {
2739
+ if (!props.layerId) {
2740
+ layerId.current = 'MlGeoJsonLayer-' + v4();
2741
+ }
2742
+ else {
2743
+ layerId.current = props.layerId;
2744
+ }
2745
+ }, [props.layerId]);
2746
+ useSource({
2747
+ mapId: props.mapId,
2748
+ sourceId: 'source-' + layerId.current,
2749
+ source: __assign({ type: 'geojson', data: props.geojson }, (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'undefined' &&
2750
+ typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string'
2751
+ ? props.options.source
2752
+ : {})),
2753
+ });
2754
+ useLayer({
2755
+ mapId: props.mapId,
2756
+ layerId: layerId.current,
2757
+ options: __assign(__assign({ source: 'source-' + layerId.current }, props.options), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.layout), type: layerType }),
2758
+ insertBeforeLayer: props.insertBeforeLayer,
2759
+ onHover: props.onHover,
2760
+ onClick: props.onClick,
2761
+ onLeave: props.onLeave,
2762
+ });
2763
+ // Label useLayer hook can't be called conditionally.
2764
+ // Using it with geojson and options.source undefined will cause it to return without creating a layer.
2765
+ useLayer({
2766
+ mapId: props.mapId,
2767
+ 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 : {})), (((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_f = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _f === void 0 ? void 0 : _f.layout) ? props.labelOptions.layout : {})), (((_g = props === null || props === void 0 ? void 0 : props.layout) === null || _g === void 0 ? void 0 : _g.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_h = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _h === void 0 ? void 0 : _h.paint) ? props.labelOptions.paint : {})) }),
2768
+ });
2769
+ return React__default.createElement(React__default.Fragment, null);
2770
+ };
2771
+
2962
2772
  /**
2963
2773
  * Adds a button that makes the map follow the users GPS position using
2964
2774
  * navigator.geolocation.watchPosition if activated
@@ -21311,5 +21121,5 @@ SpeedDial.defaultProps = {
21311
21121
  mapId: undefined,
21312
21122
  };
21313
21123
 
21314
- export { AddLayerButton, AddLayerPopup, CSVProtocolHandler, PaintPropsColorPicker as ColorPicker, ConfirmDialog, GeoJsonContext, GeoJsonLayerForm, GeoJsonProvider, GruvboxStyle, LayerContext, LayerContextProvider, LayerList, LayerListFolder, LayerListItem, LayerListItemFactory, LayerListItemVectorLayer, LayerPropertyForm, LayerTypeForm, MapComponentsProvider, MapContext, MapLibreGlWrapper, MapLibreMap, MedievalKingdomStyle, MlCenterPosition, MlClientSearch, MlComponentTemplate, MlCreatePdfButton, MlCreatePdfForm, MlFeatureEditor, MlFillExtrusionLayer, MlFollowGps, MlGeoJsonLayer, MlGpxViewer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlMarker, MlMeasureTool, MlMultiMeasureTool, MlNavigationCompass, MlNavigationTools, MlOrderLayers, PdfPreview as MlPdfPreview, MlScaleReference, MlShareMapState, MlSketchTool, MlSpatialElevationProfile, MlTemporalController, MlTerrainLayer, MlTransitionGeoJsonLayer, MlVectorTileLayer, MlWmsFeatureInfoPopup, MlWmsLayer, MlWmsLoader, MonokaiStyle, OSMProtocolHandler, OceanicNextStyle, PdfContext, PdfForm, SelectStyleButton, SelectStylePopup, Sidebar, SimpleDataContext, SimpleDataProvider, SolarizedStyle, SpeedDial, TopToolbar, TopojsonProtocolHandler, UploadButton, WmsLayerForm, XMLProtocolHandler, convertCsv, convertOSM, convertTopojson, convertXML, getTheme, useAddImage, useAddProtocol, useCameraFollowPath, useExportMap, useFeatureEditor, useFilterData, useGpx, useLayer, useLayerContext, useLayerEvent, useLayerFilter, LayerHoverPopup as useLayerHoverPopup, useMap, useMapState, useSource, useWms };
21124
+ export { AddLayerButton, AddLayerPopup, CSVProtocolHandler, PaintPropsColorPicker as ColorPicker, ConfirmDialog, GeoJsonContext, GeoJsonLayerForm, GeoJsonProvider, GruvboxStyle, LayerContext, LayerContextProvider, LayerList, LayerListFolder, LayerListItem, LayerListItemFactory, LayerListItemVectorLayer, LayerPropertyForm, LayerTypeForm, MapComponentsProvider, MapContext, MapLibreGlWrapper, MapLibreMap, MedievalKingdomStyle, MlCenterPosition, MlComponentTemplate, MlCreatePdfButton, MlCreatePdfForm, MlFeatureEditor, MlFillExtrusionLayer, MlFollowGps, MlGeoJsonLayer, MlGpxViewer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlMarker, MlMeasureTool, MlMultiMeasureTool, MlNavigationCompass, MlNavigationTools, MlOrderLayers, PdfPreview as MlPdfPreview, MlScaleReference, MlShareMapState, MlSketchTool, MlSpatialElevationProfile, MlTemporalController, MlTerrainLayer, MlTransitionGeoJsonLayer, MlVectorTileLayer, MlWmsFeatureInfoPopup, MlWmsLayer, MlWmsLoader, MonokaiStyle, OSMProtocolHandler, OceanicNextStyle, PdfContext, PdfForm, SelectStyleButton, SelectStylePopup, Sidebar, SimpleDataContext, SimpleDataProvider, SolarizedStyle, SpeedDial, TopToolbar, TopojsonProtocolHandler, UploadButton, WmsLayerForm, XMLProtocolHandler, convertCsv, convertOSM, convertTopojson, convertXML, getTheme, useAddImage, useAddProtocol, useCameraFollowPath, useExportMap, useFeatureEditor, useFilterData, useGpx, useLayer, useLayerContext, useLayerEvent, useLayerFilter, LayerHoverPopup as useLayerHoverPopup, useMap, useMapState, useSource, useWms };
21315
21125
  //# sourceMappingURL=index.esm.js.map