@mapcomponents/react-maplibre 1.0.4 → 1.0.6
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/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs.js +674 -826
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +677 -828
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
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
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
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
|
-
|
|
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
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
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
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
});
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
var
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
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
|
});
|
|
@@ -2836,116 +2238,373 @@ function featureEditorStyle() {
|
|
|
2836
2238
|
'circle-radius': mediaIsMobile ? 8.5 : 6.5,
|
|
2837
2239
|
'circle-color': '#404040',
|
|
2838
2240
|
},
|
|
2839
|
-
},
|
|
2840
|
-
];
|
|
2841
|
-
return featureEditorStyle;
|
|
2241
|
+
},
|
|
2242
|
+
];
|
|
2243
|
+
return featureEditorStyle;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
/**
|
|
2247
|
+
* GeoJson Feature editor that allows to create or manipulate GeoJson data
|
|
2248
|
+
*/
|
|
2249
|
+
var useFeatureEditor = function (props) {
|
|
2250
|
+
var draw = React.useRef();
|
|
2251
|
+
var mapHook = useMap({
|
|
2252
|
+
mapId: props.mapId,
|
|
2253
|
+
waitForLayer: props.insertBeforeLayer,
|
|
2254
|
+
});
|
|
2255
|
+
var drawToolsInitialized = React.useRef(false);
|
|
2256
|
+
var _a = React.useState(false), drawToolsReady = _a[0], setDrawToolsReady = _a[1];
|
|
2257
|
+
var _b = React.useState(), feature = _b[0], setFeature = _b[1];
|
|
2258
|
+
var style = featureEditorStyle();
|
|
2259
|
+
var modeChangeHandler = React.useCallback(function (e) {
|
|
2260
|
+
console.log('MlFeatureEditor mode change to ' + e.mode);
|
|
2261
|
+
//setDrawMode(e.mode);
|
|
2262
|
+
if (typeof props.onFinish === 'function' && e.mode === 'simple_select') {
|
|
2263
|
+
props.onFinish();
|
|
2264
|
+
}
|
|
2265
|
+
}, [props.onFinish]);
|
|
2266
|
+
React.useEffect(function () {
|
|
2267
|
+
var _a;
|
|
2268
|
+
if (mapHook.map && !drawToolsInitialized.current) {
|
|
2269
|
+
drawToolsInitialized.current = true;
|
|
2270
|
+
if (mapHook.map.map.style &&
|
|
2271
|
+
mapHook.map.map.getSource('mapbox-gl-draw-cold') &&
|
|
2272
|
+
draw.current) {
|
|
2273
|
+
// remove old Mapbox-gl-Draw from Mapbox instance when hot-reloading this component during development
|
|
2274
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2275
|
+
// @ts-ignore
|
|
2276
|
+
(_a = draw.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
2277
|
+
}
|
|
2278
|
+
draw.current = new MapboxDraw({
|
|
2279
|
+
displayControlsDefault: false,
|
|
2280
|
+
defaultMode: props.mode || 'simple_select',
|
|
2281
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2282
|
+
// @ts-ignore
|
|
2283
|
+
modes: Object.assign({}, MapboxDraw.modes),
|
|
2284
|
+
userProperties: true,
|
|
2285
|
+
styles: style,
|
|
2286
|
+
});
|
|
2287
|
+
mapHook.map.addControl(draw.current, 'top-left', mapHook.componentId);
|
|
2288
|
+
mapHook.map.on('draw.modechange', modeChangeHandler, mapHook.componentId);
|
|
2289
|
+
setDrawToolsReady(true);
|
|
2290
|
+
}
|
|
2291
|
+
}, [mapHook.map, props, drawToolsInitialized, modeChangeHandler]);
|
|
2292
|
+
React.useEffect(function () {
|
|
2293
|
+
if (!mapHook.map || !drawToolsReady)
|
|
2294
|
+
return;
|
|
2295
|
+
var changeHandler = function () {
|
|
2296
|
+
var _a, _b;
|
|
2297
|
+
if (draw.current) {
|
|
2298
|
+
// update drawnFeatures state object
|
|
2299
|
+
var currentFeatureCollection = (_b = (_a = draw.current).getAll) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
2300
|
+
setFeature(currentFeatureCollection === null || currentFeatureCollection === void 0 ? void 0 : currentFeatureCollection.features);
|
|
2301
|
+
if (typeof props.onChange === 'function') {
|
|
2302
|
+
props.onChange(currentFeatureCollection === null || currentFeatureCollection === void 0 ? void 0 : currentFeatureCollection.features);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
mapHook.map.on('mouseup', changeHandler);
|
|
2307
|
+
mapHook.map.on('touchend', changeHandler);
|
|
2308
|
+
return function () {
|
|
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 {};
|
|
2842
2386
|
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
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;
|
|
2849
2397
|
var mapHook = useMap({
|
|
2850
2398
|
mapId: props.mapId,
|
|
2851
2399
|
waitForLayer: props.insertBeforeLayer,
|
|
2852
2400
|
});
|
|
2853
|
-
var
|
|
2854
|
-
var
|
|
2855
|
-
var
|
|
2856
|
-
var
|
|
2857
|
-
var
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
if (
|
|
2861
|
-
|
|
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();
|
|
2862
2412
|
}
|
|
2863
|
-
|
|
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
|
+
// recreate layer if style has changed
|
|
2438
|
+
var styledataEventHandler = function () {
|
|
2439
|
+
var _a;
|
|
2440
|
+
if (!((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
|
|
2441
|
+
createLayer();
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
mapHook.map.on('styledata', styledataEventHandler, mapHook.componentId);
|
|
2445
|
+
var addSourceHandler = function (_ev, _wrapper, _a) {
|
|
2446
|
+
var _b;
|
|
2447
|
+
var source_id = _a.source_id;
|
|
2448
|
+
if (mapHook.map &&
|
|
2449
|
+
typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
|
|
2450
|
+
props.options.source === source_id) {
|
|
2451
|
+
createLayer();
|
|
2452
|
+
}
|
|
2453
|
+
};
|
|
2454
|
+
mapHook.map.wrapper.on('addsource', addSourceHandler, mapHook.componentId);
|
|
2455
|
+
layerPaintConfRef.current = JSON.stringify((_f = props.options) === null || _f === void 0 ? void 0 : _f.paint);
|
|
2456
|
+
layerLayoutConfRef.current = JSON.stringify((_g = props.options) === null || _g === void 0 ? void 0 : _g.layout);
|
|
2457
|
+
layerTypeRef.current = props.options.type;
|
|
2458
|
+
}, [props, mapHook]);
|
|
2864
2459
|
React.useEffect(function () {
|
|
2865
|
-
var _a;
|
|
2866
|
-
if (mapHook.map
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2460
|
+
var _a, _b, _c, _d, _e;
|
|
2461
|
+
if (!mapHook.map)
|
|
2462
|
+
return;
|
|
2463
|
+
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')
|
|
2464
|
+
return;
|
|
2465
|
+
if (((_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.cancelled) === false &&
|
|
2466
|
+
((_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)) &&
|
|
2467
|
+
(legalLayerTypes.indexOf(props.options.type) === -1 ||
|
|
2468
|
+
(legalLayerTypes.indexOf(props.options.type) !== -1 &&
|
|
2469
|
+
props.options.type === layerTypeRef.current))) {
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
createLayer();
|
|
2473
|
+
}, [mapHook.map, mapHook.mapIsReady, props, createLayer]);
|
|
2474
|
+
React.useEffect(function () {
|
|
2475
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2476
|
+
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)))
|
|
2477
|
+
return;
|
|
2478
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2479
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
2480
|
+
(_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);
|
|
2481
|
+
}, [props.geojson, mapHook.map, props.options.type]);
|
|
2482
|
+
React.useEffect(function () {
|
|
2483
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2484
|
+
if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
|
|
2485
|
+
!mapHook.map ||
|
|
2486
|
+
!((_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)) ||
|
|
2487
|
+
props.options.type !== layerTypeRef.current)
|
|
2488
|
+
return;
|
|
2489
|
+
var key;
|
|
2490
|
+
var layoutString = JSON.stringify(props.options.layout);
|
|
2491
|
+
if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
|
|
2492
|
+
var oldLayout = JSON.parse(layerLayoutConfRef.current);
|
|
2493
|
+
for (key in props.options.layout) {
|
|
2494
|
+
if (((_e = props.options.layout) === null || _e === void 0 ? void 0 : _e[key]) &&
|
|
2495
|
+
props.options.layout[key] !== oldLayout[key]) {
|
|
2496
|
+
mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
|
|
2497
|
+
}
|
|
2875
2498
|
}
|
|
2876
|
-
|
|
2877
|
-
displayControlsDefault: false,
|
|
2878
|
-
defaultMode: props.mode || 'simple_select',
|
|
2879
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2880
|
-
// @ts-ignore
|
|
2881
|
-
modes: Object.assign({}, MapboxDraw.modes),
|
|
2882
|
-
userProperties: true,
|
|
2883
|
-
styles: style,
|
|
2884
|
-
});
|
|
2885
|
-
mapHook.map.addControl(draw.current, 'top-left', mapHook.componentId);
|
|
2886
|
-
mapHook.map.on('draw.modechange', modeChangeHandler, mapHook.componentId);
|
|
2887
|
-
setDrawToolsReady(true);
|
|
2499
|
+
layerLayoutConfRef.current = layoutString;
|
|
2888
2500
|
}
|
|
2889
|
-
|
|
2501
|
+
var paintString = JSON.stringify(props.options.paint);
|
|
2502
|
+
if (paintString !== layerPaintConfRef.current) {
|
|
2503
|
+
var oldPaint = JSON.parse(layerPaintConfRef.current);
|
|
2504
|
+
for (key in props.options.paint) {
|
|
2505
|
+
if (((_f = props.options.paint) === null || _f === void 0 ? void 0 : _f[key]) &&
|
|
2506
|
+
props.options.paint[key] !== oldPaint[key]) {
|
|
2507
|
+
mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
layerPaintConfRef.current = paintString;
|
|
2511
|
+
}
|
|
2512
|
+
}, [props.options, mapHook.map]);
|
|
2513
|
+
React.useEffect(function () {
|
|
2514
|
+
if (!props.insertBeforeLayer ||
|
|
2515
|
+
!mapHook.map ||
|
|
2516
|
+
!mapHook.map.getLayer(props.insertBeforeLayer) ||
|
|
2517
|
+
!mapHook.map.getLayer(layerId.current))
|
|
2518
|
+
return;
|
|
2519
|
+
mapHook.map.moveLayer(layerId.current, props.insertBeforeLayer);
|
|
2520
|
+
}, [mapHook.map, props.insertBeforeLayer]);
|
|
2521
|
+
React.useEffect(function () {
|
|
2522
|
+
return function () {
|
|
2523
|
+
mapHook.cleanup();
|
|
2524
|
+
};
|
|
2525
|
+
}, []);
|
|
2526
|
+
React.useEffect(function () {
|
|
2527
|
+
var _a;
|
|
2528
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'string' || !mapHook.map) {
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
var findSourceHandler = function () {
|
|
2532
|
+
var _a, _b, _c;
|
|
2533
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) === 'string' &&
|
|
2534
|
+
((_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)) &&
|
|
2535
|
+
!mapHook.map.getLayer(layerId.current)) {
|
|
2536
|
+
createLayer();
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
mapHook.map.on('sourcedataloading', findSourceHandler);
|
|
2540
|
+
var addSourceHandler = function (_ev, _wrapper, _a) {
|
|
2541
|
+
var _b;
|
|
2542
|
+
var source_id = _a.source_id;
|
|
2543
|
+
if (mapHook.map &&
|
|
2544
|
+
typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) === 'string' &&
|
|
2545
|
+
props.options.source === source_id) {
|
|
2546
|
+
createLayer();
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
mapHook.map.wrapper.on('addsource', addSourceHandler);
|
|
2550
|
+
return function () {
|
|
2551
|
+
if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
|
|
2552
|
+
mapHook.map.off('sourcedataloading', findSourceHandler);
|
|
2553
|
+
mapHook.map.wrapper.off('addsource', addSourceHandler);
|
|
2554
|
+
}
|
|
2555
|
+
};
|
|
2556
|
+
}, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
|
|
2557
|
+
// Reload onClick-handlers when they change
|
|
2890
2558
|
React.useEffect(function () {
|
|
2891
|
-
|
|
2559
|
+
var _a, _b, _c;
|
|
2560
|
+
if (!props.onClick || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2892
2561
|
return;
|
|
2893
|
-
var
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
if (typeof props.onChange === 'function') {
|
|
2900
|
-
props.onChange(currentFeatureCollection === null || currentFeatureCollection === void 0 ? void 0 : currentFeatureCollection.features);
|
|
2901
|
-
}
|
|
2562
|
+
var onClickHandler = props.onClick;
|
|
2563
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('click', layerId.current, onClickHandler);
|
|
2564
|
+
return function () {
|
|
2565
|
+
var _a;
|
|
2566
|
+
if (onClickHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2567
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('click', layerId.current, onClickHandler);
|
|
2902
2568
|
}
|
|
2903
2569
|
};
|
|
2904
|
-
|
|
2905
|
-
|
|
2570
|
+
}, [mapHook.map, props.onClick]);
|
|
2571
|
+
// Reload onHover-handlers when they change
|
|
2572
|
+
React.useEffect(function () {
|
|
2573
|
+
var _a, _b, _c;
|
|
2574
|
+
if (!props.onHover || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2575
|
+
return;
|
|
2576
|
+
var onHoverHandler = props.onHover;
|
|
2577
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('mousemove', layerId.current, onHoverHandler);
|
|
2906
2578
|
return function () {
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2579
|
+
var _a;
|
|
2580
|
+
if (onHoverHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2581
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('mousemove', layerId.current, onHoverHandler);
|
|
2582
|
+
}
|
|
2911
2583
|
};
|
|
2912
|
-
}, [
|
|
2913
|
-
|
|
2914
|
-
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] });
|
|
2919
|
-
}
|
|
2920
|
-
}, [props.geojson, drawToolsReady]);
|
|
2584
|
+
}, [mapHook.map, props.onHover]);
|
|
2585
|
+
// Reload onLeave-handlers when they change
|
|
2921
2586
|
React.useEffect(function () {
|
|
2922
|
-
var _a, _b, _c
|
|
2923
|
-
if (props.
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2587
|
+
var _a, _b, _c;
|
|
2588
|
+
if (!props.onLeave || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2589
|
+
return;
|
|
2590
|
+
var onLeaveHandler = props.onLeave;
|
|
2591
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('mouseleave', layerId.current, onLeaveHandler);
|
|
2592
|
+
return function () {
|
|
2593
|
+
var _a;
|
|
2594
|
+
if (onLeaveHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2595
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('mouseleave', layerId.current, onLeaveHandler);
|
|
2929
2596
|
}
|
|
2930
|
-
}
|
|
2931
|
-
}, [
|
|
2597
|
+
};
|
|
2598
|
+
}, [mapHook.map, props.onLeave]);
|
|
2932
2599
|
return {
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2600
|
+
map: mapHook.map,
|
|
2601
|
+
layer: layer,
|
|
2602
|
+
layerId: layerId.current,
|
|
2603
|
+
componentId: mapHook.componentId,
|
|
2604
|
+
mapHook: mapHook,
|
|
2936
2605
|
};
|
|
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
|
-
};
|
|
2606
|
+
}
|
|
2607
|
+
useLayer.defaultProps = {};
|
|
2949
2608
|
|
|
2950
2609
|
/**
|
|
2951
2610
|
* Adds a fill extrusion layer to the MapLibre instance reference by props.mapId
|
|
@@ -2983,6 +2642,196 @@ MlFillExtrusionLayer.defaultProps = {
|
|
|
2983
2642
|
},
|
|
2984
2643
|
};
|
|
2985
2644
|
|
|
2645
|
+
var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
2646
|
+
switch (type) {
|
|
2647
|
+
case 'fill':
|
|
2648
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.fill) {
|
|
2649
|
+
return defaultPaintOverrides.fill;
|
|
2650
|
+
}
|
|
2651
|
+
return {
|
|
2652
|
+
'fill-color': 'rgba(10,240,256,0.6)',
|
|
2653
|
+
'fill-outline-color': 'rgba(20,230,256,0.8)',
|
|
2654
|
+
};
|
|
2655
|
+
case 'line':
|
|
2656
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
|
|
2657
|
+
return defaultPaintOverrides.line;
|
|
2658
|
+
}
|
|
2659
|
+
return {
|
|
2660
|
+
'line-color': 'rgb(203,211,2)',
|
|
2661
|
+
'line-width': 5,
|
|
2662
|
+
'line-blur': 0,
|
|
2663
|
+
};
|
|
2664
|
+
case 'circle':
|
|
2665
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.circle) {
|
|
2666
|
+
return defaultPaintOverrides.circle;
|
|
2667
|
+
}
|
|
2668
|
+
return {
|
|
2669
|
+
'circle-color': 'rgba(10,240,256,0.8)',
|
|
2670
|
+
'circle-stroke-color': '#fff',
|
|
2671
|
+
'circle-stroke-width': 2,
|
|
2672
|
+
'circle-radius': 4,
|
|
2673
|
+
};
|
|
2674
|
+
default:
|
|
2675
|
+
return {};
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2679
|
+
var mapGeometryTypesToLayerTypes = {
|
|
2680
|
+
Position: "circle",
|
|
2681
|
+
Point: "circle",
|
|
2682
|
+
MultiPoint: "circle",
|
|
2683
|
+
LineString: "line",
|
|
2684
|
+
MultiLineString: "line",
|
|
2685
|
+
Polygon: "fill",
|
|
2686
|
+
MultiPolygon: "fill",
|
|
2687
|
+
GeometryCollection: "circle",
|
|
2688
|
+
};
|
|
2689
|
+
var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
2690
|
+
var _a;
|
|
2691
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
|
|
2692
|
+
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])
|
|
2693
|
+
? mapGeometryTypesToLayerTypes[geojson.geometry.type]
|
|
2694
|
+
: "circle";
|
|
2695
|
+
}
|
|
2696
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
|
|
2697
|
+
if (geojson.features.length) {
|
|
2698
|
+
return getDefaulLayerTypeByGeometry(geojson.features[0]);
|
|
2699
|
+
}
|
|
2700
|
+
return "circle";
|
|
2701
|
+
}
|
|
2702
|
+
return "fill";
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
function useSource(props) {
|
|
2706
|
+
var _a;
|
|
2707
|
+
var mapHook = useMap({
|
|
2708
|
+
mapId: props.mapId,
|
|
2709
|
+
});
|
|
2710
|
+
var _b = React.useState(), source = _b[0], setSource = _b[1];
|
|
2711
|
+
var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
|
|
2712
|
+
var removeSource = React.useCallback(function () {
|
|
2713
|
+
var _a, _b;
|
|
2714
|
+
if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
|
|
2715
|
+
for (var _i = 0, _c = Object.entries(mapHook.map.map.style._layers); _i < _c.length; _i++) {
|
|
2716
|
+
var _d = _c[_i], layerId = _d[0], layer = _d[1];
|
|
2717
|
+
if (layer.source === sourceId.current) {
|
|
2718
|
+
mapHook.map.removeLayer(layerId);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
if (mapHook.map.getSource(sourceId.current)) {
|
|
2722
|
+
mapHook.map.removeSource(sourceId.current);
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
}, [mapHook.map]);
|
|
2726
|
+
var createSource = React.useCallback(function () {
|
|
2727
|
+
var _a;
|
|
2728
|
+
if (!mapHook.map)
|
|
2729
|
+
return;
|
|
2730
|
+
if (props.source.type === 'geojson' && !props.source.data)
|
|
2731
|
+
return;
|
|
2732
|
+
if (mapHook.map.map.getSource(sourceId.current)) {
|
|
2733
|
+
removeSource();
|
|
2734
|
+
}
|
|
2735
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source));
|
|
2736
|
+
setSource(mapHook.map.map.getSource(sourceId.current));
|
|
2737
|
+
}, [props, mapHook, removeSource]);
|
|
2738
|
+
React.useEffect(function () {
|
|
2739
|
+
var _a, _b, _c, _d;
|
|
2740
|
+
if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(sourceId.current)))
|
|
2741
|
+
return;
|
|
2742
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2743
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
2744
|
+
(_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);
|
|
2745
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2746
|
+
//@ts-ignore data only exists on GeoJsonSource
|
|
2747
|
+
}, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
|
|
2748
|
+
React.useEffect(function () {
|
|
2749
|
+
var _a, _b, _c;
|
|
2750
|
+
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)
|
|
2751
|
+
return;
|
|
2752
|
+
sourceId.current = props.sourceId;
|
|
2753
|
+
createSource();
|
|
2754
|
+
}, [mapHook.map, props, createSource]);
|
|
2755
|
+
React.useEffect(function () {
|
|
2756
|
+
if (!mapHook.map)
|
|
2757
|
+
return;
|
|
2758
|
+
var checkSourceHandler = function () {
|
|
2759
|
+
var _a, _b;
|
|
2760
|
+
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))) {
|
|
2761
|
+
createSource();
|
|
2762
|
+
}
|
|
2763
|
+
};
|
|
2764
|
+
mapHook.map.on('styledata', checkSourceHandler);
|
|
2765
|
+
return function () {
|
|
2766
|
+
if (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) {
|
|
2767
|
+
mapHook.map.off('styledata', checkSourceHandler);
|
|
2768
|
+
}
|
|
2769
|
+
};
|
|
2770
|
+
}, [mapHook.map, createSource]);
|
|
2771
|
+
//cleanup
|
|
2772
|
+
React.useEffect(function () {
|
|
2773
|
+
return function () {
|
|
2774
|
+
removeSource();
|
|
2775
|
+
};
|
|
2776
|
+
}, [removeSource]);
|
|
2777
|
+
return {
|
|
2778
|
+
map: mapHook.map,
|
|
2779
|
+
source: source,
|
|
2780
|
+
componentId: mapHook.componentId,
|
|
2781
|
+
mapHook: mapHook,
|
|
2782
|
+
};
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
/**
|
|
2786
|
+
* Adds source and layer to display GeoJSON data on the map.
|
|
2787
|
+
*
|
|
2788
|
+
* @component
|
|
2789
|
+
*/
|
|
2790
|
+
var MlGeoJsonLayer = function (props) {
|
|
2791
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2792
|
+
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
2793
|
+
var layerId = React.useRef(props.layerId || 'MlGeoJsonLayer-' + uuid.v4());
|
|
2794
|
+
var labelLayerId = "label-".concat(layerId.current);
|
|
2795
|
+
React.useEffect(function () {
|
|
2796
|
+
if (!props.layerId) {
|
|
2797
|
+
layerId.current = 'MlGeoJsonLayer-' + uuid.v4();
|
|
2798
|
+
}
|
|
2799
|
+
else {
|
|
2800
|
+
layerId.current = props.layerId;
|
|
2801
|
+
}
|
|
2802
|
+
}, [props.layerId]);
|
|
2803
|
+
useSource({
|
|
2804
|
+
mapId: props.mapId,
|
|
2805
|
+
sourceId: 'source-' + layerId.current,
|
|
2806
|
+
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' &&
|
|
2807
|
+
typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string'
|
|
2808
|
+
? props.options.source
|
|
2809
|
+
: {})),
|
|
2810
|
+
});
|
|
2811
|
+
useLayer({
|
|
2812
|
+
mapId: props.mapId,
|
|
2813
|
+
layerId: layerId.current,
|
|
2814
|
+
options: __assign(__assign({}, (typeof ((_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) !== 'undefined' &&
|
|
2815
|
+
typeof ((_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.source) === 'string'
|
|
2816
|
+
? { source: props.options.source }
|
|
2817
|
+
: { source: 'source-' + layerId.current })), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_f = props === null || props === void 0 ? void 0 : props.options) === null || _f === void 0 ? void 0 : _f.layout), type: layerType }),
|
|
2818
|
+
insertBeforeLayer: props.insertBeforeLayer,
|
|
2819
|
+
onHover: props.onHover,
|
|
2820
|
+
onClick: props.onClick,
|
|
2821
|
+
onLeave: props.onLeave,
|
|
2822
|
+
});
|
|
2823
|
+
// Label useLayer hook can't be called conditionally.
|
|
2824
|
+
// Using it with geojson and options.source undefined will cause it to return without creating a layer.
|
|
2825
|
+
useLayer({
|
|
2826
|
+
mapId: props.mapId,
|
|
2827
|
+
options: __assign(__assign(__assign(__assign(__assign({}, (typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'undefined' &&
|
|
2828
|
+
typeof ((_h = props === null || props === void 0 ? void 0 : props.options) === null || _h === void 0 ? void 0 : _h.source) === 'string'
|
|
2829
|
+
? { source: props.options.source }
|
|
2830
|
+
: { source: 'source-' + layerId.current })), { id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }), ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), (((_j = props === null || props === void 0 ? void 0 : props.options) === null || _j === void 0 ? void 0 : _j.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_k = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _k === void 0 ? void 0 : _k.layout) ? props.labelOptions.layout : {})), (((_l = props === null || props === void 0 ? void 0 : props.layout) === null || _l === void 0 ? void 0 : _l.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_m = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _m === void 0 ? void 0 : _m.paint) ? props.labelOptions.paint : {})) }),
|
|
2831
|
+
});
|
|
2832
|
+
return React.createElement(React.Fragment, null);
|
|
2833
|
+
};
|
|
2834
|
+
|
|
2986
2835
|
/**
|
|
2987
2836
|
* Adds a button that makes the map follow the users GPS position using
|
|
2988
2837
|
* navigator.geolocation.watchPosition if activated
|
|
@@ -21359,7 +21208,6 @@ exports.MapLibreGlWrapper = MapLibreGlWrapper;
|
|
|
21359
21208
|
exports.MapLibreMap = MapLibreMap;
|
|
21360
21209
|
exports.MedievalKingdomStyle = MedievalKingdomStyle;
|
|
21361
21210
|
exports.MlCenterPosition = MlCenterPosition;
|
|
21362
|
-
exports.MlClientSearch = MlClientSearch;
|
|
21363
21211
|
exports.MlComponentTemplate = MlComponentTemplate;
|
|
21364
21212
|
exports.MlCreatePdfButton = MlCreatePdfButton;
|
|
21365
21213
|
exports.MlCreatePdfForm = MlCreatePdfForm;
|