@mapcomponents/react-maplibre 1.2.0 → 1.3.1
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 +23 -0
- package/dist/index.cjs.js +330 -157
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +332 -159
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/MlComponentTemplate/MlComponentTemplate.stories_.d.ts +14 -0
- package/dist/src/components/MlGpxViewer/util/GeoJsonProvider.d.ts +1 -1
- package/dist/src/components/MlMarker/MlMarker.d.ts +21 -26
- package/dist/src/components/MlNavigationTools/MlNavigationTools.d.ts +1 -1
- package/dist/src/components/MlSketchTool/MlSketchTool.d.ts +8 -0
- package/dist/src/components/MlWmsLoader/MlWmsLoader.d.ts +1 -1
- package/dist/src/ui_components/LayerList/LayerList.d.ts +1 -1
- package/dist/src/ui_components/LayerList/LayerListFolder.d.ts +3 -3
- package/dist/src/ui_components/LayerList/LayerListItem.d.ts +4 -4
- package/dist/src/ui_components/LayerTree/LayerTreeListItem.d.ts +1 -1
- package/dist/src/util/Instructions.d.ts +1 -1
- package/package.json +33 -30
package/dist/index.cjs.js
CHANGED
|
@@ -41,7 +41,6 @@ var ControlPointIcon = require('@mui/icons-material/ControlPoint');
|
|
|
41
41
|
var RemoveCircleOutlineIcon = require('@mui/icons-material/RemoveCircleOutline');
|
|
42
42
|
var Divider = require('@mui/material/Divider');
|
|
43
43
|
var syncMove = require('@mapbox/mapbox-gl-sync-move');
|
|
44
|
-
var Paper = require('@mui/material/Paper');
|
|
45
44
|
var xmldom = require('@xmldom/xmldom');
|
|
46
45
|
var helpers = require('@turf/helpers');
|
|
47
46
|
var WMSCapabilities = require('wms-capabilities');
|
|
@@ -128,7 +127,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
128
127
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
129
128
|
PERFORMANCE OF THIS SOFTWARE.
|
|
130
129
|
***************************************************************************** */
|
|
131
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
130
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
var __assign = function() {
|
|
@@ -165,8 +164,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
function __generator(thisArg, body) {
|
|
168
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
169
|
-
return g =
|
|
167
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
168
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
170
169
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
171
170
|
function step(op) {
|
|
172
171
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -2093,7 +2092,7 @@ function featureEditorStyle() {
|
|
|
2093
2092
|
},
|
|
2094
2093
|
paint: {
|
|
2095
2094
|
'line-color': '#009EE0',
|
|
2096
|
-
'line-width':
|
|
2095
|
+
'line-width': 4,
|
|
2097
2096
|
},
|
|
2098
2097
|
},
|
|
2099
2098
|
{
|
|
@@ -2105,7 +2104,7 @@ function featureEditorStyle() {
|
|
|
2105
2104
|
'line-join': 'round',
|
|
2106
2105
|
},
|
|
2107
2106
|
paint: {
|
|
2108
|
-
'line-color':
|
|
2107
|
+
'line-color': '#009EE0',
|
|
2109
2108
|
'line-dasharray': [0.2, 2],
|
|
2110
2109
|
'line-width': 2,
|
|
2111
2110
|
},
|
|
@@ -2118,7 +2117,7 @@ function featureEditorStyle() {
|
|
|
2118
2117
|
'circle-radius': mediaIsMobile ? 5 : 4,
|
|
2119
2118
|
'circle-color': '#ffffff',
|
|
2120
2119
|
'circle-stroke-color': '#009EE0',
|
|
2121
|
-
'circle-stroke-width': 1
|
|
2120
|
+
'circle-stroke-width': 1,
|
|
2122
2121
|
},
|
|
2123
2122
|
},
|
|
2124
2123
|
{
|
|
@@ -2138,7 +2137,7 @@ function featureEditorStyle() {
|
|
|
2138
2137
|
'circle-radius': mediaIsMobile ? 7 : 5,
|
|
2139
2138
|
'circle-color': '#ffffff',
|
|
2140
2139
|
'circle-stroke-color': '#009EE0',
|
|
2141
|
-
'circle-stroke-width': 1
|
|
2140
|
+
'circle-stroke-width': 1,
|
|
2142
2141
|
},
|
|
2143
2142
|
},
|
|
2144
2143
|
{
|
|
@@ -2655,16 +2654,22 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
|
2655
2654
|
return defaultPaintOverrides.fill;
|
|
2656
2655
|
}
|
|
2657
2656
|
return {
|
|
2658
|
-
'fill-color': 'rgba(10,240,256,0.6)',
|
|
2659
|
-
'fill-outline-color': 'rgba(20,230,256,0.8)',
|
|
2657
|
+
// 'fill-color': 'rgba(10,240,256,0.6)',
|
|
2658
|
+
// 'fill-outline-color': 'rgba(20,230,256,0.8)',
|
|
2659
|
+
'fill-color': '#009EE0',
|
|
2660
|
+
'fill-outline-color': '#009EE0'
|
|
2660
2661
|
};
|
|
2661
2662
|
case 'line':
|
|
2662
2663
|
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
|
|
2664
|
+
console.log(defaultPaintOverrides.line);
|
|
2663
2665
|
return defaultPaintOverrides.line;
|
|
2664
2666
|
}
|
|
2665
2667
|
return {
|
|
2666
|
-
'line-color': 'rgb(203,211,2)',
|
|
2667
|
-
'line-width': 5,
|
|
2668
|
+
// // 'line-color': 'rgb(203,211,2)',
|
|
2669
|
+
// 'line-width': 5,
|
|
2670
|
+
// 'line-blur': 0,
|
|
2671
|
+
'line-color': '#009EE0',
|
|
2672
|
+
'line-width': 4,
|
|
2668
2673
|
'line-blur': 0,
|
|
2669
2674
|
};
|
|
2670
2675
|
case 'circle':
|
|
@@ -2672,10 +2677,14 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
|
2672
2677
|
return defaultPaintOverrides.circle;
|
|
2673
2678
|
}
|
|
2674
2679
|
return {
|
|
2675
|
-
'circle-color': 'rgba(10,240,256,0.8)',
|
|
2680
|
+
// 'circle-color': 'rgba(10,240,256,0.8)',
|
|
2681
|
+
// 'circle-stroke-color': '#fff',
|
|
2682
|
+
// 'circle-stroke-width': 2,
|
|
2683
|
+
// 'circle-radius': 4,
|
|
2684
|
+
'circle-color': '#009EE0',
|
|
2676
2685
|
'circle-stroke-color': '#fff',
|
|
2677
2686
|
'circle-stroke-width': 2,
|
|
2678
|
-
'circle-radius':
|
|
2687
|
+
'circle-radius': 5,
|
|
2679
2688
|
};
|
|
2680
2689
|
default:
|
|
2681
2690
|
return {};
|
|
@@ -4377,6 +4386,23 @@ MlLayerSwipe.defaultProps = {
|
|
|
4377
4386
|
buttonStyle: {},
|
|
4378
4387
|
};
|
|
4379
4388
|
|
|
4389
|
+
function _arrayLikeToArray(r, a) {
|
|
4390
|
+
(null == a || a > r.length) && (a = r.length);
|
|
4391
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4392
|
+
return n;
|
|
4393
|
+
}
|
|
4394
|
+
function _arrayWithoutHoles(r) {
|
|
4395
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
4396
|
+
}
|
|
4397
|
+
function _iterableToArray(r) {
|
|
4398
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
4399
|
+
}
|
|
4400
|
+
function _nonIterableSpread() {
|
|
4401
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
4402
|
+
}
|
|
4403
|
+
function _toConsumableArray(r) {
|
|
4404
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
4405
|
+
}
|
|
4380
4406
|
function _typeof(o) {
|
|
4381
4407
|
"@babel/helpers - typeof";
|
|
4382
4408
|
|
|
@@ -4386,33 +4412,15 @@ function _typeof(o) {
|
|
|
4386
4412
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
4387
4413
|
}, _typeof(o);
|
|
4388
4414
|
}
|
|
4389
|
-
function
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
}
|
|
4395
|
-
function _iterableToArray(iter) {
|
|
4396
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
4397
|
-
}
|
|
4398
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
4399
|
-
if (!o) return;
|
|
4400
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
4401
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
4402
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
4403
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
4404
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
4405
|
-
}
|
|
4406
|
-
function _arrayLikeToArray(arr, len) {
|
|
4407
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
4408
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
4409
|
-
return arr2;
|
|
4410
|
-
}
|
|
4411
|
-
function _nonIterableSpread() {
|
|
4412
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
4415
|
+
function _unsupportedIterableToArray(r, a) {
|
|
4416
|
+
if (r) {
|
|
4417
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
4418
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
4419
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
4420
|
+
}
|
|
4413
4421
|
}
|
|
4414
4422
|
|
|
4415
|
-
var
|
|
4423
|
+
var _showNextTransitionSegment2 = function _showNextTransitionSegment(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson) {
|
|
4416
4424
|
var _arguments = arguments;
|
|
4417
4425
|
if (typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !== "undefined") {
|
|
4418
4426
|
// if at last transition step set to target geojson
|
|
@@ -4425,7 +4433,7 @@ var _showNextTransitionSegment = function _showNextTransitionSegment(props, map,
|
|
|
4425
4433
|
currentTransitionStepRef.current++;
|
|
4426
4434
|
if (transitionInProgressRef.current && currentTransitionStepRef.current < transitionGeojsonDataRef.current.length) {
|
|
4427
4435
|
transitionTimeoutRef.current = setTimeout(function () {
|
|
4428
|
-
return
|
|
4436
|
+
return _showNextTransitionSegment2.apply(void 0, _toConsumableArray(_arguments));
|
|
4429
4437
|
}, msPerStep);
|
|
4430
4438
|
} else {
|
|
4431
4439
|
if (typeof props.onTransitionEnd === "function") {
|
|
@@ -4515,7 +4523,7 @@ var _transitionToGeojson = function _transitionToGeojson(props, transitionGeojso
|
|
|
4515
4523
|
currentTransitionStepRef.current = 1;
|
|
4516
4524
|
transitionInProgressRef.current = true;
|
|
4517
4525
|
transitionTimeoutRef.current = setTimeout(function () {
|
|
4518
|
-
return
|
|
4526
|
+
return _showNextTransitionSegment2(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson);
|
|
4519
4527
|
}, msPerStep);
|
|
4520
4528
|
};
|
|
4521
4529
|
var createTransitionSteps = function createTransitionSteps(linestringCoordinates, perStepDistance, stepCnt) {
|
|
@@ -4604,76 +4612,130 @@ var MlTransitionGeoJsonLayer = function (props) {
|
|
|
4604
4612
|
React.createElement(MlGeoJsonLayer, __assign({}, restProps, { geojson: displayGeojson }))));
|
|
4605
4613
|
};
|
|
4606
4614
|
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4615
|
+
var getBoxTransform = function (anchor) {
|
|
4616
|
+
if (anchor === void 0) { anchor = 'top'; }
|
|
4617
|
+
switch (anchor) {
|
|
4618
|
+
case 'bottom':
|
|
4619
|
+
return 'translate(-50%, 0%)';
|
|
4620
|
+
case 'left':
|
|
4621
|
+
return 'translate(-100%, -50%)';
|
|
4622
|
+
case 'right':
|
|
4623
|
+
return 'translate(0%, -50%)';
|
|
4624
|
+
case 'top-left':
|
|
4625
|
+
return 'translate(-100%, -100%)';
|
|
4626
|
+
case 'top-right':
|
|
4627
|
+
return 'translate(0%, -100%)';
|
|
4628
|
+
case 'bottom-left':
|
|
4629
|
+
return 'translate(-100%, 0%)';
|
|
4630
|
+
case 'bottom-right':
|
|
4631
|
+
return 'translate(0%, 0%)';
|
|
4632
|
+
default:
|
|
4633
|
+
case 'top':
|
|
4634
|
+
return 'translate(-50%, -100%)';
|
|
4635
|
+
}
|
|
4636
|
+
};
|
|
4637
|
+
function getBoxMargins(anchor, offset, style) {
|
|
4638
|
+
var w = parseInt(String((style === null || style === void 0 ? void 0 : style.width) || 14), 10);
|
|
4639
|
+
var h = parseInt(String((style === null || style === void 0 ? void 0 : style.height) || 14), 10);
|
|
4640
|
+
var m = {};
|
|
4641
|
+
switch (anchor) {
|
|
4642
|
+
case 'bottom':
|
|
4643
|
+
m.marginTop = "".concat(offset, "px");
|
|
4644
|
+
break;
|
|
4645
|
+
case 'left':
|
|
4646
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4647
|
+
break;
|
|
4648
|
+
case 'right':
|
|
4649
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4650
|
+
break;
|
|
4651
|
+
case 'top-left':
|
|
4652
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4653
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4654
|
+
break;
|
|
4655
|
+
case 'top-right':
|
|
4656
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4657
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4658
|
+
break;
|
|
4659
|
+
case 'bottom-left':
|
|
4660
|
+
m.marginTop = "".concat(offset, "px");
|
|
4661
|
+
m.marginLeft = "-".concat(offset, "px");
|
|
4662
|
+
break;
|
|
4663
|
+
case 'bottom-right':
|
|
4664
|
+
m.marginTop = "".concat(offset, "px");
|
|
4665
|
+
m.marginLeft = "".concat(w + offset, "px");
|
|
4666
|
+
break;
|
|
4667
|
+
case 'top':
|
|
4668
|
+
default:
|
|
4669
|
+
m.marginTop = "-".concat(h + offset, "px");
|
|
4670
|
+
break;
|
|
4671
|
+
}
|
|
4672
|
+
return m;
|
|
4673
|
+
}
|
|
4674
|
+
var MlMarker = function (_a) {
|
|
4675
|
+
var _b = _a.passEventsThrough, passEventsThrough = _b === void 0 ? true : _b, _c = _a.contentOffset, contentOffset = _c === void 0 ? 5 : _c, props = __rest(_a, ["passEventsThrough", "contentOffset"]);
|
|
4611
4676
|
var mapHook = useMap({
|
|
4612
4677
|
mapId: props.mapId,
|
|
4613
4678
|
waitForLayer: props.insertBeforeLayer,
|
|
4614
4679
|
});
|
|
4615
|
-
var
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
});
|
|
4619
|
-
var iframe = React.useRef(null);
|
|
4620
|
-
var _a = React.useState({
|
|
4621
|
-
width: "400px",
|
|
4622
|
-
height: "500px",
|
|
4623
|
-
}), iframeDimensions = _a[0], setIframeDimensions = _a[1];
|
|
4624
|
-
var _b = React.useState(), markerPixelPos = _b[0], setMarkerPixelPos = _b[1];
|
|
4680
|
+
var _d = React.useState(null), marker = _d[0], setMarker = _d[1];
|
|
4681
|
+
var container = React.useRef(null);
|
|
4682
|
+
var iframeRef = React.useRef(null);
|
|
4625
4683
|
React.useEffect(function () {
|
|
4626
|
-
|
|
4627
|
-
if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.project))
|
|
4628
|
-
return;
|
|
4629
|
-
var _pixelPos = mapHook.map.map.project([props.lng, props.lat]);
|
|
4630
|
-
setMarkerPixelPos(_pixelPos);
|
|
4631
|
-
}, [mapHook.map, props.lng, props.lat, mapState.viewport]);
|
|
4632
|
-
React.useEffect(function () {
|
|
4633
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
4634
|
-
if (!mapHook.map ||
|
|
4635
|
-
!((_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))
|
|
4684
|
+
if (!mapHook.map)
|
|
4636
4685
|
return;
|
|
4637
|
-
|
|
4638
|
-
var
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4686
|
+
container.current = document.createElement('div');
|
|
4687
|
+
var defaultMarkerStyle = {
|
|
4688
|
+
width: '12px',
|
|
4689
|
+
height: '12px',
|
|
4690
|
+
background: 'linear-gradient(135deg, rgb(186, 208, 218) 0%, rgb(96, 209, 253) 100%)',
|
|
4691
|
+
border: '1px solid rgba(255, 255, 255, 0.7)',
|
|
4692
|
+
boxShadow: '0 2px 6px rgba(90, 0, 0, 0.2), 0 0 0 2px rgba(240, 147, 251, 0.2)',
|
|
4693
|
+
borderRadius: '50%',
|
|
4694
|
+
};
|
|
4695
|
+
var markerStyle = __assign(__assign({}, defaultMarkerStyle), props.markerStyle);
|
|
4696
|
+
var maplibreMarker = new maplibregl.Marker({
|
|
4697
|
+
element: container.current,
|
|
4698
|
+
anchor: 'center',
|
|
4699
|
+
})
|
|
4700
|
+
.setLngLat([props.lng, props.lat])
|
|
4701
|
+
.addTo(mapHook.map.map);
|
|
4702
|
+
setMarker(maplibreMarker);
|
|
4703
|
+
var markerDot = document.createElement('div');
|
|
4704
|
+
Object.entries(markerStyle).forEach(function (_a) {
|
|
4705
|
+
var key = _a[0], value = _a[1];
|
|
4706
|
+
markerDot.style.setProperty(key.replace(/([A-Z])/g, '-$1').toLowerCase(), String(value));
|
|
4645
4707
|
});
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4708
|
+
container.current.appendChild(markerDot);
|
|
4709
|
+
return function () {
|
|
4710
|
+
var _a;
|
|
4711
|
+
markerDot.remove();
|
|
4712
|
+
maplibreMarker.remove();
|
|
4713
|
+
(_a = container.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
4714
|
+
};
|
|
4715
|
+
}, [mapHook.map, props.lng, props.lat, props.markerStyle, props.anchor]);
|
|
4716
|
+
React.useEffect(function () {
|
|
4717
|
+
if (marker) {
|
|
4718
|
+
marker.setLngLat([props.lng, props.lat]);
|
|
4719
|
+
}
|
|
4720
|
+
}, [marker, props.lng, props.lat]);
|
|
4721
|
+
function handleIframeLoad() {
|
|
4722
|
+
var _a, _b, _c;
|
|
4723
|
+
var iframeDoc = (_b = (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
|
|
4724
|
+
if (iframeDoc && ((_c = iframeRef.current) === null || _c === void 0 ? void 0 : _c.parentElement)) {
|
|
4725
|
+
var scrollHeight = iframeDoc.documentElement.scrollHeight;
|
|
4726
|
+
iframeRef.current.parentElement.style.height = "".concat(scrollHeight, "px");
|
|
4727
|
+
}
|
|
4728
|
+
}
|
|
4729
|
+
return (container.current &&
|
|
4730
|
+
ReactDOM.createPortal(React.createElement(material.Box, { 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': {
|
|
4669
4731
|
opacity: 1,
|
|
4670
|
-
},
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4732
|
+
} }), props.containerStyle) },
|
|
4733
|
+
React.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 || {})
|
|
4734
|
+
.map(function (_a) {
|
|
4735
|
+
var key = _a[0], val = _a[1];
|
|
4736
|
+
return "".concat(key.replace(/([A-Z])/g, '-$1').toLowerCase(), ": ").concat(val, ";");
|
|
4737
|
+
})
|
|
4738
|
+
.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));
|
|
4677
4739
|
};
|
|
4678
4740
|
|
|
4679
4741
|
/**
|
|
@@ -6952,41 +7014,61 @@ var sketchTools = [
|
|
|
6952
7014
|
*
|
|
6953
7015
|
*/
|
|
6954
7016
|
var MlSketchTool = function (props) {
|
|
6955
|
-
var _a, _b;
|
|
6956
7017
|
var mapHook = useMap({
|
|
6957
7018
|
mapId: props.mapId,
|
|
6958
7019
|
waitForLayer: props.insertBeforeLayer,
|
|
6959
7020
|
});
|
|
6960
|
-
var
|
|
6961
|
-
var
|
|
7021
|
+
var _a = React.useState(), hoveredGeometry = _a[0], setHoveredGeometry = _a[1];
|
|
7022
|
+
var _b = React.useState({
|
|
6962
7023
|
activeGeometryIndex: undefined,
|
|
6963
7024
|
selectedGeoJson: undefined,
|
|
6964
7025
|
geometries: [],
|
|
6965
7026
|
drawMode: undefined,
|
|
6966
|
-
}), sketchState =
|
|
7027
|
+
}), sketchState = _b[0], setSketchState = _b[1];
|
|
7028
|
+
console.log(sketchState);
|
|
6967
7029
|
React.useEffect(function () {
|
|
6968
7030
|
if (!(typeof props.onChange === 'function'))
|
|
6969
7031
|
return;
|
|
6970
7032
|
props.onChange(sketchState);
|
|
6971
7033
|
}, [sketchState, props.onChange]);
|
|
6972
7034
|
var buttonStyle = __assign({}, props.buttonStyleOverride);
|
|
7035
|
+
// const buttonClickHandler = (buttonDrawMode: keyof MapboxDraw.Modes) => {
|
|
7036
|
+
// setSketchState((_state) => ({
|
|
7037
|
+
// drawMode: _state.drawMode !== buttonDrawMode ? buttonDrawMode : undefined,
|
|
7038
|
+
// geometries: _state.geometries,
|
|
7039
|
+
// activeGeometryIndex: undefined,
|
|
7040
|
+
// selectedGeoJson: undefined,
|
|
7041
|
+
// }));
|
|
7042
|
+
// };
|
|
6973
7043
|
var buttonClickHandler = function (buttonDrawMode) {
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
activeGeometryIndex: undefined,
|
|
6978
|
-
|
|
6979
|
-
|
|
7044
|
+
var modeRef = undefined;
|
|
7045
|
+
setSketchState(function (prevState) {
|
|
7046
|
+
modeRef = prevState.drawMode;
|
|
7047
|
+
return __assign(__assign({}, prevState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined });
|
|
7048
|
+
});
|
|
7049
|
+
requestAnimationFrame(function () {
|
|
7050
|
+
setSketchState(function (prevState) {
|
|
7051
|
+
if ((modeRef === 'draw_polygon' || modeRef === 'draw_line_string') &&
|
|
7052
|
+
buttonDrawMode === 'draw_point') {
|
|
7053
|
+
return __assign(__assign({}, prevState), { drawMode: undefined });
|
|
7054
|
+
}
|
|
7055
|
+
return __assign(__assign({}, prevState), { drawMode: buttonDrawMode });
|
|
7056
|
+
});
|
|
7057
|
+
});
|
|
6980
7058
|
};
|
|
6981
7059
|
var removeGeoJson = function (geoJson) {
|
|
6982
7060
|
setSketchState(function (_sketchState) {
|
|
6983
7061
|
var _geometries = __spreadArray([], _sketchState.geometries, true);
|
|
6984
7062
|
_geometries.splice(_geometries.indexOf(geoJson), 1);
|
|
6985
|
-
return __assign(__assign({}, _sketchState), { geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
|
|
7063
|
+
return __assign(__assign({}, _sketchState), { drawMode: undefined, geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
|
|
6986
7064
|
? _sketchState.activeGeometryIndex - 1
|
|
6987
7065
|
: undefined });
|
|
6988
7066
|
});
|
|
6989
7067
|
};
|
|
7068
|
+
var handleCheckboxChange = function (event) {
|
|
7069
|
+
var _a;
|
|
7070
|
+
(_a = props.onShowInstructionChange) === null || _a === void 0 ? void 0 : _a.call(props, event.target.checked);
|
|
7071
|
+
};
|
|
6990
7072
|
var SketchToolButtons = function () {
|
|
6991
7073
|
return (React.createElement(React.Fragment, null, sketchTools.map(function (el) {
|
|
6992
7074
|
var stateColor = function (theme) {
|
|
@@ -7018,7 +7100,11 @@ var MlSketchTool = function (props) {
|
|
|
7018
7100
|
} },
|
|
7019
7101
|
React.createElement(ButtonGroup, null,
|
|
7020
7102
|
React.createElement(SketchToolButtons, null))),
|
|
7103
|
+
React.createElement(system.Box, { sx: { marginTop: '10px' } },
|
|
7104
|
+
React.createElement(material.FormGroup, null,
|
|
7105
|
+
React.createElement(material.FormControlLabel, { control: React.createElement(material.Checkbox, { size: "small", checked: props.showInstruction, onChange: handleCheckboxChange }), label: "Show instructions" }))),
|
|
7021
7106
|
sketchState.drawMode && (React.createElement(MlFeatureEditor, { mode: sketchState.drawMode, geojson: sketchState.selectedGeoJson, onChange: function (feature) {
|
|
7107
|
+
console.log(feature);
|
|
7022
7108
|
if (!(feature === null || feature === void 0 ? void 0 : feature[0]))
|
|
7023
7109
|
return;
|
|
7024
7110
|
setSketchState(function (_sketchState) {
|
|
@@ -7037,65 +7123,152 @@ var MlSketchTool = function (props) {
|
|
|
7037
7123
|
else {
|
|
7038
7124
|
_geometries[_sketchState.activeGeometryIndex] = feature[0];
|
|
7039
7125
|
}
|
|
7126
|
+
// Check if the geometry type is point and if the coordinates have changed to exit draw mode after editing
|
|
7127
|
+
var changedPoint = function () {
|
|
7128
|
+
var _a, _b, _c, _d;
|
|
7129
|
+
if (_sketchState.selectedGeoJson &&
|
|
7130
|
+
typeof _sketchState.activeGeometryIndex !== 'undefined' &&
|
|
7131
|
+
_sketchState.geometries[_sketchState.activeGeometryIndex] &&
|
|
7132
|
+
_sketchState.geometries[_sketchState.activeGeometryIndex].geometry.type ===
|
|
7133
|
+
'Point') {
|
|
7134
|
+
var selectedCoords = (_b = (_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 : _b.coordinates;
|
|
7135
|
+
var activeCoords = (_d = (_c = _sketchState.geometries[_sketchState.activeGeometryIndex]) === null || _c === void 0 ? void 0 : _c.geometry) === null || _d === void 0 ? void 0 : _d.coordinates;
|
|
7136
|
+
// Compare coordinates
|
|
7137
|
+
return JSON.stringify(selectedCoords) !== JSON.stringify(activeCoords);
|
|
7138
|
+
}
|
|
7139
|
+
return false;
|
|
7140
|
+
};
|
|
7141
|
+
if (changedPoint()) {
|
|
7142
|
+
_sketchState.drawMode = undefined;
|
|
7143
|
+
}
|
|
7040
7144
|
return __assign(__assign({}, _sketchState), { geometries: _geometries });
|
|
7041
7145
|
});
|
|
7042
7146
|
}, onFinish: function () {
|
|
7043
7147
|
setSketchState(function (_sketchState) { return (__assign(__assign({}, _sketchState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined })); });
|
|
7044
7148
|
} })),
|
|
7045
7149
|
React.createElement(List, { sx: { zIndex: 105, marginBottom: '-10px' } },
|
|
7046
|
-
sketchState.geometries.map(function (el) {
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
React.createElement(system.Box, {
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
React.createElement(system.Box, { sx: {
|
|
7061
|
-
padding: '3px 30px',
|
|
7150
|
+
sketchState.geometries.map(function (el, index) {
|
|
7151
|
+
var _a, _b, _c;
|
|
7152
|
+
return (React.createElement(React.Fragment, null,
|
|
7153
|
+
React.createElement(system.Box, { key: el.id, sx: { display: 'flex', flexDirection: 'column' } },
|
|
7154
|
+
React.createElement("br", null),
|
|
7155
|
+
React.createElement(system.Box, { flexDirection: 'row', sx: {
|
|
7156
|
+
'&:hover': {
|
|
7157
|
+
backgroundColor: 'rgb(177, 177, 177, 0.2)',
|
|
7158
|
+
},
|
|
7159
|
+
marginTop: '25px',
|
|
7160
|
+
}, onMouseOver: function () {
|
|
7161
|
+
setHoveredGeometry(el);
|
|
7162
|
+
}, onMouseLeave: function () {
|
|
7163
|
+
setHoveredGeometry(undefined);
|
|
7062
7164
|
} },
|
|
7063
|
-
React.createElement(
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7165
|
+
!((_a = el.properties) === null || _a === void 0 ? void 0 : _a.customName) && (React.createElement("input", { type: "text", value: ((_b = el.properties) === null || _b === void 0 ? void 0 : _b.name) || '', placeholder: "Assign name", onChange: function (e) {
|
|
7166
|
+
var newName = e.target.value;
|
|
7167
|
+
setSketchState(function (_sketchState) {
|
|
7168
|
+
var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
|
|
7169
|
+
if (!updatedGeometries[index].properties) {
|
|
7170
|
+
updatedGeometries[index].properties = {};
|
|
7171
|
+
}
|
|
7172
|
+
updatedGeometries[index].properties.name = newName;
|
|
7173
|
+
return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
|
|
7174
|
+
});
|
|
7175
|
+
}, style: {
|
|
7176
|
+
padding: '5px',
|
|
7177
|
+
border: '1px solid #ccc',
|
|
7178
|
+
borderRadius: '4px',
|
|
7179
|
+
outline: 'none',
|
|
7180
|
+
}, onFocus: function (e) { return (e.target.style.borderColor = '#009ee0'); }, onBlur: function (e) {
|
|
7181
|
+
e.target.style.borderColor = '#ccc';
|
|
7182
|
+
setSketchState(function (_sketchState) {
|
|
7183
|
+
var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
|
|
7184
|
+
if (!updatedGeometries[index].properties) {
|
|
7185
|
+
updatedGeometries[index].properties = {};
|
|
7186
|
+
}
|
|
7187
|
+
updatedGeometries[index].properties.customName = true;
|
|
7188
|
+
return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
|
|
7189
|
+
});
|
|
7190
|
+
} })),
|
|
7191
|
+
React.createElement(LayerListItem, { listItemSx: buttonStyle, configurable: true, layerComponent: React.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: el, layerId: String(el.id), defaultPaintOverrides: {
|
|
7192
|
+
fill: { 'fill-opacity': 0.5 },
|
|
7193
|
+
} }), type: 'layer', name: React.createElement(material.Typography, { onClick: function () {
|
|
7194
|
+
setSketchState(function (_sketchState) {
|
|
7195
|
+
var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
|
|
7196
|
+
if (!updatedGeometries[index].properties) {
|
|
7197
|
+
updatedGeometries[index].properties = {};
|
|
7198
|
+
}
|
|
7199
|
+
updatedGeometries[index].properties.customName = false;
|
|
7200
|
+
return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
|
|
7201
|
+
});
|
|
7202
|
+
}, sx: {
|
|
7203
|
+
cursor: 'pointer',
|
|
7204
|
+
overflow: 'hidden',
|
|
7205
|
+
whiteSpace: 'nowrap',
|
|
7206
|
+
} }, ((_c = el.properties) === null || _c === void 0 ? void 0 : _c.name) || String(el.id)), description: el.geometry.type }),
|
|
7207
|
+
React.createElement(system.Box, { sx: {
|
|
7208
|
+
padding: '3px 30px',
|
|
7209
|
+
} },
|
|
7210
|
+
React.createElement(ButtonGroup, { size: "small" },
|
|
7211
|
+
React.createElement(Tooltip, { title: "Center" },
|
|
7212
|
+
React.createElement(material.Button, { sx: __assign({ color: function (theme) { return theme.palette.primary.main; }, backgroundColor: function (theme) { return theme.palette.navigation.navColor; } }, buttonStyle), onClick: function () {
|
|
7213
|
+
var _a;
|
|
7214
|
+
(_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.map.setCenter(el.geometry.type === 'Point'
|
|
7215
|
+
? el.geometry.coordinates
|
|
7216
|
+
: turf__namespace.centerOfMass(el).geometry.coordinates);
|
|
7217
|
+
} },
|
|
7218
|
+
React.createElement(GpsFixedIcon, null))),
|
|
7219
|
+
React.createElement(Tooltip, { title: "Edit" },
|
|
7220
|
+
React.createElement(material.Button, { sx: __assign({ color: function (theme) {
|
|
7221
|
+
var _a;
|
|
7222
|
+
if (sketchState.drawMode === 'simple_select' &&
|
|
7223
|
+
((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
|
|
7224
|
+
return theme.palette.navigation.navColor;
|
|
7225
|
+
}
|
|
7226
|
+
else {
|
|
7227
|
+
return theme.palette.primary.main;
|
|
7228
|
+
}
|
|
7229
|
+
}, backgroundColor: function (theme) {
|
|
7230
|
+
var _a;
|
|
7231
|
+
if (sketchState.drawMode === 'simple_select' &&
|
|
7232
|
+
((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
|
|
7233
|
+
return theme.palette.primary.main;
|
|
7234
|
+
}
|
|
7235
|
+
else {
|
|
7236
|
+
return theme.palette.navigation.navColor;
|
|
7237
|
+
}
|
|
7238
|
+
} }, buttonStyle), onClick: function () {
|
|
7239
|
+
setSketchState(function (_sketchState) {
|
|
7240
|
+
var _a;
|
|
7241
|
+
var newDrawMode = _sketchState.drawMode === 'simple_select' &&
|
|
7242
|
+
((_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id
|
|
7243
|
+
? undefined
|
|
7244
|
+
: 'simple_select';
|
|
7245
|
+
return __assign(__assign({}, _sketchState), { selectedGeoJson: el, activeGeometryIndex: _sketchState.geometries.indexOf(el), drawMode: newDrawMode });
|
|
7246
|
+
});
|
|
7247
|
+
} },
|
|
7248
|
+
React.createElement(EditIcon, null))),
|
|
7249
|
+
React.createElement(Tooltip, { title: "Delete" },
|
|
7250
|
+
React.createElement(material.Button, { sx: __assign({ color: function (theme) { return theme.palette.primary.main; }, backgroundColor: function (theme) { return theme.palette.navigation.navColor; } }, buttonStyle), onClick: function () {
|
|
7251
|
+
removeGeoJson(el);
|
|
7252
|
+
setHoveredGeometry(undefined);
|
|
7253
|
+
} },
|
|
7254
|
+
React.createElement(DeleteIcon, null)))))))));
|
|
7255
|
+
}),
|
|
7080
7256
|
hoveredGeometry && (React.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, layerId: 'highlightBorder', defaultPaintOverrides: {
|
|
7081
7257
|
circle: {
|
|
7082
|
-
'circle-color': '#
|
|
7083
|
-
'circle-opacity': 0.
|
|
7258
|
+
'circle-color': '#000000',
|
|
7259
|
+
'circle-opacity': 0.2,
|
|
7084
7260
|
'circle-radius': 10,
|
|
7085
7261
|
},
|
|
7086
7262
|
line: {
|
|
7087
|
-
'line-color': '#
|
|
7088
|
-
'line-opacity': 0.
|
|
7263
|
+
'line-color': '#000000',
|
|
7264
|
+
'line-opacity': 0.2,
|
|
7089
7265
|
'line-width': 10,
|
|
7090
7266
|
},
|
|
7091
7267
|
fill: {
|
|
7092
|
-
'fill-color': '#
|
|
7093
|
-
'fill-opacity': 0.
|
|
7268
|
+
'fill-color': '#000000',
|
|
7269
|
+
'fill-opacity': 0.2,
|
|
7094
7270
|
},
|
|
7095
|
-
} })))
|
|
7096
|
-
sketchState.drawMode === 'simple_select' && (React.createElement(material.Typography, { sx: { fontSize: '0.6em' } },
|
|
7097
|
-
"Edit ", (_b = (_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 :
|
|
7098
|
-
_b.type))));
|
|
7271
|
+
} })))));
|
|
7099
7272
|
};
|
|
7100
7273
|
MlSketchTool.defaultProps = {
|
|
7101
7274
|
mapId: undefined,
|