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