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