@mapcomponents/react-maplibre 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs.js +236 -110
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +237 -111
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/MlComponentTemplate/MlComponentTemplate.stories_.d.ts +14 -0
- package/dist/src/components/MlMarker/MlMarker.d.ts +21 -26
- package/dist/src/hooks/useFeatureEditor/utils/FeatureEditorStyle.d.ts +28 -0
- package/package.json +29 -29
package/dist/index.esm.js
CHANGED
|
@@ -9,7 +9,7 @@ import FilterCenterFocusIcon from '@mui/icons-material/FilterCenterFocus';
|
|
|
9
9
|
import PrinterIcon from '@mui/icons-material/Print';
|
|
10
10
|
import Button$1 from '@mui/material/Button';
|
|
11
11
|
import jsPDF from 'jspdf';
|
|
12
|
-
import ReactDOM from 'react-dom';
|
|
12
|
+
import ReactDOM, { createPortal } from 'react-dom';
|
|
13
13
|
import Moveable from 'react-moveable';
|
|
14
14
|
import * as turf from '@turf/turf';
|
|
15
15
|
import { point, circle, lineArc, bbox, booleanContains, bboxPolygon, featureCollection, distance, lineOffset } from '@turf/turf';
|
|
@@ -41,7 +41,6 @@ import ControlPointIcon from '@mui/icons-material/ControlPoint';
|
|
|
41
41
|
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
|
|
42
42
|
import Divider from '@mui/material/Divider';
|
|
43
43
|
import syncMove from '@mapbox/mapbox-gl-sync-move';
|
|
44
|
-
import Paper$1 from '@mui/material/Paper';
|
|
45
44
|
import * as xmldom from '@xmldom/xmldom';
|
|
46
45
|
import { featureCollection as featureCollection$1, lineString, polygon } from '@turf/helpers';
|
|
47
46
|
import WMSCapabilities from 'wms-capabilities';
|
|
@@ -2069,7 +2068,8 @@ function featureEditorStyle() {
|
|
|
2069
2068
|
},
|
|
2070
2069
|
paint: {
|
|
2071
2070
|
'line-color': '#009EE0',
|
|
2072
|
-
'line-width':
|
|
2071
|
+
'line-width': 10,
|
|
2072
|
+
'line-opacity': 0.2,
|
|
2073
2073
|
},
|
|
2074
2074
|
},
|
|
2075
2075
|
{
|
|
@@ -2081,7 +2081,7 @@ function featureEditorStyle() {
|
|
|
2081
2081
|
'line-join': 'round',
|
|
2082
2082
|
},
|
|
2083
2083
|
paint: {
|
|
2084
|
-
'line-color':
|
|
2084
|
+
'line-color': '#009EE0',
|
|
2085
2085
|
'line-dasharray': [0.2, 2],
|
|
2086
2086
|
'line-width': 2,
|
|
2087
2087
|
},
|
|
@@ -2094,7 +2094,7 @@ function featureEditorStyle() {
|
|
|
2094
2094
|
'circle-radius': mediaIsMobile ? 5 : 4,
|
|
2095
2095
|
'circle-color': '#ffffff',
|
|
2096
2096
|
'circle-stroke-color': '#009EE0',
|
|
2097
|
-
'circle-stroke-width': 1
|
|
2097
|
+
'circle-stroke-width': 1,
|
|
2098
2098
|
},
|
|
2099
2099
|
},
|
|
2100
2100
|
{
|
|
@@ -2114,7 +2114,7 @@ function featureEditorStyle() {
|
|
|
2114
2114
|
'circle-radius': mediaIsMobile ? 7 : 5,
|
|
2115
2115
|
'circle-color': '#ffffff',
|
|
2116
2116
|
'circle-stroke-color': '#009EE0',
|
|
2117
|
-
'circle-stroke-width': 1
|
|
2117
|
+
'circle-stroke-width': 1,
|
|
2118
2118
|
},
|
|
2119
2119
|
},
|
|
2120
2120
|
{
|
|
@@ -2631,15 +2631,21 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
|
2631
2631
|
return defaultPaintOverrides.fill;
|
|
2632
2632
|
}
|
|
2633
2633
|
return {
|
|
2634
|
-
'fill-color': 'rgba(10,240,256,0.6)',
|
|
2635
|
-
'fill-outline-color': 'rgba(20,230,256,0.8)',
|
|
2634
|
+
// 'fill-color': 'rgba(10,240,256,0.6)',
|
|
2635
|
+
// 'fill-outline-color': 'rgba(20,230,256,0.8)',
|
|
2636
|
+
'fill-color': '#009EE0',
|
|
2637
|
+
'fill-outline-color': '#009EE0',
|
|
2636
2638
|
};
|
|
2637
2639
|
case 'line':
|
|
2638
2640
|
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
|
|
2641
|
+
console.log(defaultPaintOverrides.line);
|
|
2639
2642
|
return defaultPaintOverrides.line;
|
|
2640
2643
|
}
|
|
2641
2644
|
return {
|
|
2642
|
-
'line-color': 'rgb(203,211,2)',
|
|
2645
|
+
// // 'line-color': 'rgb(203,211,2)',
|
|
2646
|
+
// 'line-width': 5,
|
|
2647
|
+
// 'line-blur': 0,
|
|
2648
|
+
'line-color': '#009EE0',
|
|
2643
2649
|
'line-width': 5,
|
|
2644
2650
|
'line-blur': 0,
|
|
2645
2651
|
};
|
|
@@ -2648,10 +2654,14 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
|
2648
2654
|
return defaultPaintOverrides.circle;
|
|
2649
2655
|
}
|
|
2650
2656
|
return {
|
|
2651
|
-
'circle-color': 'rgba(10,240,256,0.8)',
|
|
2657
|
+
// 'circle-color': 'rgba(10,240,256,0.8)',
|
|
2658
|
+
// 'circle-stroke-color': '#fff',
|
|
2659
|
+
// 'circle-stroke-width': 2,
|
|
2660
|
+
// 'circle-radius': 4,
|
|
2661
|
+
'circle-color': '#009EE0',
|
|
2652
2662
|
'circle-stroke-color': '#fff',
|
|
2653
2663
|
'circle-stroke-width': 2,
|
|
2654
|
-
'circle-radius':
|
|
2664
|
+
'circle-radius': 5,
|
|
2655
2665
|
};
|
|
2656
2666
|
default:
|
|
2657
2667
|
return {};
|
|
@@ -4580,76 +4590,130 @@ var MlTransitionGeoJsonLayer = function (props) {
|
|
|
4580
4590
|
React__default.createElement(MlGeoJsonLayer, __assign({}, restProps, { geojson: displayGeojson }))));
|
|
4581
4591
|
};
|
|
4582
4592
|
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4593
|
+
var getBoxTransform = function (anchor) {
|
|
4594
|
+
if (anchor === void 0) { anchor = 'top'; }
|
|
4595
|
+
switch (anchor) {
|
|
4596
|
+
case 'bottom':
|
|
4597
|
+
return 'translate(-50%, 0%)';
|
|
4598
|
+
case 'left':
|
|
4599
|
+
return 'translate(-100%, -50%)';
|
|
4600
|
+
case 'right':
|
|
4601
|
+
return 'translate(0%, -50%)';
|
|
4602
|
+
case 'top-left':
|
|
4603
|
+
return 'translate(-100%, -100%)';
|
|
4604
|
+
case 'top-right':
|
|
4605
|
+
return 'translate(0%, -100%)';
|
|
4606
|
+
case 'bottom-left':
|
|
4607
|
+
return 'translate(-100%, 0%)';
|
|
4608
|
+
case 'bottom-right':
|
|
4609
|
+
return 'translate(0%, 0%)';
|
|
4610
|
+
default:
|
|
4611
|
+
case 'top':
|
|
4612
|
+
return 'translate(-50%, -100%)';
|
|
4613
|
+
}
|
|
4614
|
+
};
|
|
4615
|
+
function getBoxMargins(anchor, offset, style) {
|
|
4616
|
+
var w = parseInt(String((style === null || style === void 0 ? void 0 : style.width) || 14), 10);
|
|
4617
|
+
var h = parseInt(String((style === null || style === void 0 ? void 0 : style.height) || 14), 10);
|
|
4618
|
+
var m = {};
|
|
4619
|
+
switch (anchor) {
|
|
4620
|
+
case 'bottom':
|
|
4621
|
+
m.marginTop = "".concat(offset, "px");
|
|
4622
|
+
break;
|
|
4623
|
+
case 'left':
|
|
4624
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4625
|
+
break;
|
|
4626
|
+
case 'right':
|
|
4627
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4628
|
+
break;
|
|
4629
|
+
case 'top-left':
|
|
4630
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4631
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4632
|
+
break;
|
|
4633
|
+
case 'top-right':
|
|
4634
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4635
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4636
|
+
break;
|
|
4637
|
+
case 'bottom-left':
|
|
4638
|
+
m.marginTop = "".concat(offset, "px");
|
|
4639
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4640
|
+
break;
|
|
4641
|
+
case 'bottom-right':
|
|
4642
|
+
m.marginTop = "".concat(offset, "px");
|
|
4643
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4644
|
+
break;
|
|
4645
|
+
case 'top':
|
|
4646
|
+
default:
|
|
4647
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4648
|
+
break;
|
|
4649
|
+
}
|
|
4650
|
+
return m;
|
|
4651
|
+
}
|
|
4652
|
+
var MlMarker = function (_a) {
|
|
4653
|
+
var _b = _a.passEventsThrough, passEventsThrough = _b === void 0 ? true : _b, _c = _a.contentOffset, contentOffset = _c === void 0 ? 5 : _c, props = __rest(_a, ["passEventsThrough", "contentOffset"]);
|
|
4587
4654
|
var mapHook = useMap({
|
|
4588
4655
|
mapId: props.mapId,
|
|
4589
4656
|
waitForLayer: props.insertBeforeLayer,
|
|
4590
4657
|
});
|
|
4591
|
-
var
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
});
|
|
4595
|
-
var iframe = useRef(null);
|
|
4596
|
-
var _a = useState({
|
|
4597
|
-
width: "400px",
|
|
4598
|
-
height: "500px",
|
|
4599
|
-
}), iframeDimensions = _a[0], setIframeDimensions = _a[1];
|
|
4600
|
-
var _b = useState(), markerPixelPos = _b[0], setMarkerPixelPos = _b[1];
|
|
4601
|
-
useEffect(function () {
|
|
4602
|
-
var _a, _b;
|
|
4603
|
-
if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.project))
|
|
4604
|
-
return;
|
|
4605
|
-
var _pixelPos = mapHook.map.map.project([props.lng, props.lat]);
|
|
4606
|
-
setMarkerPixelPos(_pixelPos);
|
|
4607
|
-
}, [mapHook.map, props.lng, props.lat, mapState.viewport]);
|
|
4658
|
+
var _d = useState(null), marker = _d[0], setMarker = _d[1];
|
|
4659
|
+
var container = useRef(null);
|
|
4660
|
+
var iframeRef = useRef(null);
|
|
4608
4661
|
useEffect(function () {
|
|
4609
|
-
|
|
4610
|
-
if (!mapHook.map ||
|
|
4611
|
-
!((_d = (_c = (_b = (_a = iframe.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.scrollHeight))
|
|
4662
|
+
if (!mapHook.map)
|
|
4612
4663
|
return;
|
|
4613
|
-
|
|
4614
|
-
var
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4664
|
+
container.current = document.createElement('div');
|
|
4665
|
+
var defaultMarkerStyle = {
|
|
4666
|
+
width: '12px',
|
|
4667
|
+
height: '12px',
|
|
4668
|
+
background: 'linear-gradient(135deg, rgb(186, 208, 218) 0%, rgb(96, 209, 253) 100%)',
|
|
4669
|
+
border: '1px solid rgba(255, 255, 255, 0.7)',
|
|
4670
|
+
boxShadow: '0 2px 6px rgba(90, 0, 0, 0.2), 0 0 0 2px rgba(240, 147, 251, 0.2)',
|
|
4671
|
+
borderRadius: '50%',
|
|
4672
|
+
};
|
|
4673
|
+
var markerStyle = __assign(__assign({}, defaultMarkerStyle), props.markerStyle);
|
|
4674
|
+
var maplibreMarker = new maplibregl.Marker({
|
|
4675
|
+
element: container.current,
|
|
4676
|
+
anchor: 'center',
|
|
4677
|
+
})
|
|
4678
|
+
.setLngLat([props.lng, props.lat])
|
|
4679
|
+
.addTo(mapHook.map.map);
|
|
4680
|
+
setMarker(maplibreMarker);
|
|
4681
|
+
var markerDot = document.createElement('div');
|
|
4682
|
+
Object.entries(markerStyle).forEach(function (_a) {
|
|
4683
|
+
var key = _a[0], value = _a[1];
|
|
4684
|
+
markerDot.style.setProperty(key.replace(/([A-Z])/g, '-$1').toLowerCase(), String(value));
|
|
4621
4685
|
});
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4686
|
+
container.current.appendChild(markerDot);
|
|
4687
|
+
return function () {
|
|
4688
|
+
var _a;
|
|
4689
|
+
markerDot.remove();
|
|
4690
|
+
maplibreMarker.remove();
|
|
4691
|
+
(_a = container.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
4692
|
+
};
|
|
4693
|
+
}, [mapHook.map, props.lng, props.lat, props.markerStyle, props.anchor]);
|
|
4694
|
+
useEffect(function () {
|
|
4695
|
+
if (marker) {
|
|
4696
|
+
marker.setLngLat([props.lng, props.lat]);
|
|
4697
|
+
}
|
|
4698
|
+
}, [marker, props.lng, props.lat]);
|
|
4699
|
+
function handleIframeLoad() {
|
|
4700
|
+
var _a, _b, _c;
|
|
4701
|
+
var iframeDoc = (_b = (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
|
|
4702
|
+
if (iframeDoc && ((_c = iframeRef.current) === null || _c === void 0 ? void 0 : _c.parentElement)) {
|
|
4703
|
+
var scrollHeight = iframeDoc.documentElement.scrollHeight;
|
|
4704
|
+
iframeRef.current.parentElement.style.height = "".concat(scrollHeight, "px");
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
return (container.current &&
|
|
4708
|
+
createPortal(React__default.createElement(Box$1, { sx: __assign(__assign(__assign({ position: 'absolute', display: 'flex', width: '300px', maxHeight: '500px', opacity: passEventsThrough ? 1 : 0.7, zIndex: -1, transform: getBoxTransform(props.anchor) }, getBoxMargins(props.anchor, contentOffset, props.markerStyle)), { pointerEvents: passEventsThrough ? 'none' : 'auto', '&:hover': {
|
|
4645
4709
|
opacity: 1,
|
|
4646
|
-
},
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4710
|
+
} }), props.containerStyle) },
|
|
4711
|
+
React__default.createElement("iframe", { ref: iframeRef, onLoad: handleIframeLoad, style: __assign({ width: '100%', borderStyle: 'none' }, props.iframeStyle), srcDoc: "<div>\n\t<style>\n\t\tbody {\n\t\t\t".concat(Object.entries(props.iframeBodyStyle || {})
|
|
4712
|
+
.map(function (_a) {
|
|
4713
|
+
var key = _a[0], val = _a[1];
|
|
4714
|
+
return "".concat(key.replace(/([A-Z])/g, '-$1').toLowerCase(), ": ").concat(val, ";");
|
|
4715
|
+
})
|
|
4716
|
+
.join(' '), "\n\t\t}\n\t</style>\n\t").concat(props.content || '', "\n</div>"), sandbox: "allow-same-origin allow-popups-to-escape-sandbox allow-scripts", title: mapHook.componentId })), container.current));
|
|
4653
4717
|
};
|
|
4654
4718
|
|
|
4655
4719
|
/**
|
|
@@ -6928,37 +6992,53 @@ var sketchTools = [
|
|
|
6928
6992
|
*
|
|
6929
6993
|
*/
|
|
6930
6994
|
var MlSketchTool = function (props) {
|
|
6931
|
-
var _a, _b;
|
|
6932
6995
|
var mapHook = useMap({
|
|
6933
6996
|
mapId: props.mapId,
|
|
6934
6997
|
waitForLayer: props.insertBeforeLayer,
|
|
6935
6998
|
});
|
|
6936
|
-
var
|
|
6937
|
-
var
|
|
6999
|
+
var _a = useState(), hoveredGeometry = _a[0], setHoveredGeometry = _a[1];
|
|
7000
|
+
var _b = useState({
|
|
6938
7001
|
activeGeometryIndex: undefined,
|
|
6939
7002
|
selectedGeoJson: undefined,
|
|
6940
7003
|
geometries: [],
|
|
6941
7004
|
drawMode: undefined,
|
|
6942
|
-
}), sketchState =
|
|
7005
|
+
}), sketchState = _b[0], setSketchState = _b[1];
|
|
7006
|
+
console.log(sketchState);
|
|
6943
7007
|
useEffect(function () {
|
|
6944
7008
|
if (!(typeof props.onChange === 'function'))
|
|
6945
7009
|
return;
|
|
6946
7010
|
props.onChange(sketchState);
|
|
6947
7011
|
}, [sketchState, props.onChange]);
|
|
6948
7012
|
var buttonStyle = __assign({}, props.buttonStyleOverride);
|
|
7013
|
+
// const buttonClickHandler = (buttonDrawMode: keyof MapboxDraw.Modes) => {
|
|
7014
|
+
// setSketchState((_state) => ({
|
|
7015
|
+
// drawMode: _state.drawMode !== buttonDrawMode ? buttonDrawMode : undefined,
|
|
7016
|
+
// geometries: _state.geometries,
|
|
7017
|
+
// activeGeometryIndex: undefined,
|
|
7018
|
+
// selectedGeoJson: undefined,
|
|
7019
|
+
// }));
|
|
7020
|
+
// };
|
|
6949
7021
|
var buttonClickHandler = function (buttonDrawMode) {
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
activeGeometryIndex: undefined,
|
|
6954
|
-
|
|
6955
|
-
|
|
7022
|
+
var modeRef = undefined;
|
|
7023
|
+
setSketchState(function (prevState) {
|
|
7024
|
+
modeRef = prevState.drawMode;
|
|
7025
|
+
return __assign(__assign({}, prevState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined });
|
|
7026
|
+
});
|
|
7027
|
+
requestAnimationFrame(function () {
|
|
7028
|
+
setSketchState(function (prevState) {
|
|
7029
|
+
if ((modeRef === 'draw_polygon' || modeRef === 'draw_line_string') &&
|
|
7030
|
+
buttonDrawMode === 'draw_point') {
|
|
7031
|
+
return __assign(__assign({}, prevState), { drawMode: undefined });
|
|
7032
|
+
}
|
|
7033
|
+
return __assign(__assign({}, prevState), { drawMode: buttonDrawMode });
|
|
7034
|
+
});
|
|
7035
|
+
});
|
|
6956
7036
|
};
|
|
6957
7037
|
var removeGeoJson = function (geoJson) {
|
|
6958
7038
|
setSketchState(function (_sketchState) {
|
|
6959
7039
|
var _geometries = __spreadArray([], _sketchState.geometries, true);
|
|
6960
7040
|
_geometries.splice(_geometries.indexOf(geoJson), 1);
|
|
6961
|
-
return __assign(__assign({}, _sketchState), { geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
|
|
7041
|
+
return __assign(__assign({}, _sketchState), { drawMode: undefined, geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
|
|
6962
7042
|
? _sketchState.activeGeometryIndex - 1
|
|
6963
7043
|
: undefined });
|
|
6964
7044
|
});
|
|
@@ -6995,6 +7075,7 @@ var MlSketchTool = function (props) {
|
|
|
6995
7075
|
React__default.createElement(ButtonGroup, null,
|
|
6996
7076
|
React__default.createElement(SketchToolButtons, null))),
|
|
6997
7077
|
sketchState.drawMode && (React__default.createElement(MlFeatureEditor, { mode: sketchState.drawMode, geojson: sketchState.selectedGeoJson, onChange: function (feature) {
|
|
7078
|
+
console.log(feature);
|
|
6998
7079
|
if (!(feature === null || feature === void 0 ? void 0 : feature[0]))
|
|
6999
7080
|
return;
|
|
7000
7081
|
setSketchState(function (_sketchState) {
|
|
@@ -7013,6 +7094,24 @@ var MlSketchTool = function (props) {
|
|
|
7013
7094
|
else {
|
|
7014
7095
|
_geometries[_sketchState.activeGeometryIndex] = feature[0];
|
|
7015
7096
|
}
|
|
7097
|
+
// Check if the geometry type is point and if the coordinates have changed to exit draw mode after editing
|
|
7098
|
+
var changedPoint = function () {
|
|
7099
|
+
var _a, _b, _c, _d;
|
|
7100
|
+
if (_sketchState.selectedGeoJson &&
|
|
7101
|
+
typeof _sketchState.activeGeometryIndex !== 'undefined' &&
|
|
7102
|
+
_sketchState.geometries[_sketchState.activeGeometryIndex] &&
|
|
7103
|
+
_sketchState.geometries[_sketchState.activeGeometryIndex].geometry.type ===
|
|
7104
|
+
'Point') {
|
|
7105
|
+
var selectedCoords = (_b = (_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 : _b.coordinates;
|
|
7106
|
+
var activeCoords = (_d = (_c = _sketchState.geometries[_sketchState.activeGeometryIndex]) === null || _c === void 0 ? void 0 : _c.geometry) === null || _d === void 0 ? void 0 : _d.coordinates;
|
|
7107
|
+
// Compare coordinates
|
|
7108
|
+
return JSON.stringify(selectedCoords) !== JSON.stringify(activeCoords);
|
|
7109
|
+
}
|
|
7110
|
+
return false;
|
|
7111
|
+
};
|
|
7112
|
+
if (changedPoint()) {
|
|
7113
|
+
_sketchState.drawMode = undefined;
|
|
7114
|
+
}
|
|
7016
7115
|
return __assign(__assign({}, _sketchState), { geometries: _geometries });
|
|
7017
7116
|
});
|
|
7018
7117
|
}, onFinish: function () {
|
|
@@ -7032,46 +7131,73 @@ var MlSketchTool = function (props) {
|
|
|
7032
7131
|
}, onMouseLeave: function () {
|
|
7033
7132
|
setHoveredGeometry(undefined);
|
|
7034
7133
|
} },
|
|
7035
|
-
React__default.createElement(LayerListItem, { listItemSx: buttonStyle, configurable: true, layerComponent: React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: el, layerId: String(el.id)
|
|
7134
|
+
React__default.createElement(LayerListItem, { listItemSx: buttonStyle, configurable: true, layerComponent: React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: el, layerId: String(el.id), defaultPaintOverrides: {
|
|
7135
|
+
fill: { 'fill-opacity': 0.5 },
|
|
7136
|
+
} }), type: 'layer', name: String(el.id), description: el.geometry.type }),
|
|
7036
7137
|
React__default.createElement(Box, { sx: {
|
|
7037
7138
|
padding: '3px 30px',
|
|
7038
7139
|
} },
|
|
7039
7140
|
React__default.createElement(ButtonGroup, { size: "small" },
|
|
7040
|
-
React__default.createElement(
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
? el.geometry.
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7141
|
+
React__default.createElement(Tooltip$1, { title: "Center" },
|
|
7142
|
+
React__default.createElement(Button, { sx: __assign({ color: function (theme) { return theme.palette.primary.main; }, backgroundColor: function (theme) { return theme.palette.navigation.navColor; } }, buttonStyle), onClick: function () {
|
|
7143
|
+
var _a;
|
|
7144
|
+
(_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.map.setCenter(el.geometry.type === 'Point'
|
|
7145
|
+
? el.geometry.coordinates
|
|
7146
|
+
: turf.centerOfMass(el).geometry.coordinates);
|
|
7147
|
+
} },
|
|
7148
|
+
React__default.createElement(GpsFixedIcon, null))),
|
|
7149
|
+
React__default.createElement(Tooltip$1, { title: "Edit" },
|
|
7150
|
+
React__default.createElement(Button, { sx: __assign({ color: function (theme) {
|
|
7151
|
+
var _a;
|
|
7152
|
+
if (sketchState.drawMode === 'simple_select' &&
|
|
7153
|
+
((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
|
|
7154
|
+
return theme.palette.navigation.navColor;
|
|
7155
|
+
}
|
|
7156
|
+
else {
|
|
7157
|
+
return theme.palette.primary.main;
|
|
7158
|
+
}
|
|
7159
|
+
}, backgroundColor: function (theme) {
|
|
7160
|
+
var _a;
|
|
7161
|
+
if (sketchState.drawMode === 'simple_select' &&
|
|
7162
|
+
((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
|
|
7163
|
+
return theme.palette.primary.main;
|
|
7164
|
+
}
|
|
7165
|
+
else {
|
|
7166
|
+
return theme.palette.navigation.navColor;
|
|
7167
|
+
}
|
|
7168
|
+
} }, buttonStyle), onClick: function () {
|
|
7169
|
+
setSketchState(function (_sketchState) {
|
|
7170
|
+
var _a;
|
|
7171
|
+
var newDrawMode = _sketchState.drawMode === 'simple_select' &&
|
|
7172
|
+
((_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id
|
|
7173
|
+
? undefined
|
|
7174
|
+
: 'simple_select';
|
|
7175
|
+
return __assign(__assign({}, _sketchState), { selectedGeoJson: el, activeGeometryIndex: _sketchState.geometries.indexOf(el), drawMode: newDrawMode });
|
|
7176
|
+
});
|
|
7177
|
+
} },
|
|
7178
|
+
React__default.createElement(EditIcon, null))),
|
|
7179
|
+
React__default.createElement(Tooltip$1, { title: "Delete" },
|
|
7180
|
+
React__default.createElement(Button, { sx: __assign({ color: function (theme) { return theme.palette.primary.main; }, backgroundColor: function (theme) { return theme.palette.navigation.navColor; } }, buttonStyle), onClick: function () {
|
|
7181
|
+
removeGeoJson(el);
|
|
7182
|
+
setHoveredGeometry(undefined);
|
|
7183
|
+
} },
|
|
7184
|
+
React__default.createElement(DeleteIcon, null))))))))); }),
|
|
7056
7185
|
hoveredGeometry && (React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, layerId: 'highlightBorder', defaultPaintOverrides: {
|
|
7057
7186
|
circle: {
|
|
7058
|
-
'circle-color': '#
|
|
7059
|
-
'circle-opacity': 0.
|
|
7187
|
+
'circle-color': '#000000',
|
|
7188
|
+
'circle-opacity': 0.2,
|
|
7060
7189
|
'circle-radius': 10,
|
|
7061
7190
|
},
|
|
7062
7191
|
line: {
|
|
7063
|
-
'line-color': '#
|
|
7064
|
-
'line-opacity': 0.
|
|
7192
|
+
'line-color': '#000000',
|
|
7193
|
+
'line-opacity': 0.2,
|
|
7065
7194
|
'line-width': 10,
|
|
7066
7195
|
},
|
|
7067
7196
|
fill: {
|
|
7068
|
-
'fill-color': '#
|
|
7069
|
-
'fill-opacity': 0.
|
|
7197
|
+
'fill-color': '#000000',
|
|
7198
|
+
'fill-opacity': 0.2,
|
|
7070
7199
|
},
|
|
7071
|
-
} })))
|
|
7072
|
-
sketchState.drawMode === 'simple_select' && (React__default.createElement(Typography, { sx: { fontSize: '0.6em' } },
|
|
7073
|
-
"Edit ", (_b = (_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 :
|
|
7074
|
-
_b.type))));
|
|
7200
|
+
} })))));
|
|
7075
7201
|
};
|
|
7076
7202
|
MlSketchTool.defaultProps = {
|
|
7077
7203
|
mapId: undefined,
|