@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/dist/index.esm.js CHANGED
@@ -4,12 +4,12 @@ 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, 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, SwipeableDrawer, 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';
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, SwipeableDrawer, Tooltip, Snackbar, FormGroup, 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
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';
@@ -104,7 +103,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
104
103
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
105
104
  PERFORMANCE OF THIS SOFTWARE.
106
105
  ***************************************************************************** */
107
- /* global Reflect, Promise, SuppressedError, Symbol */
106
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
108
107
 
109
108
 
110
109
  var __assign = function() {
@@ -141,8 +140,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
141
140
  }
142
141
 
143
142
  function __generator(thisArg, body) {
144
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
145
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
143
+ 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);
144
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
146
145
  function verb(n) { return function (v) { return step([n, v]); }; }
147
146
  function step(op) {
148
147
  if (f) throw new TypeError("Generator is already executing.");
@@ -2069,7 +2068,7 @@ function featureEditorStyle() {
2069
2068
  },
2070
2069
  paint: {
2071
2070
  'line-color': '#009EE0',
2072
- 'line-width': 3,
2071
+ 'line-width': 4,
2073
2072
  },
2074
2073
  },
2075
2074
  {
@@ -2081,7 +2080,7 @@ function featureEditorStyle() {
2081
2080
  'line-join': 'round',
2082
2081
  },
2083
2082
  paint: {
2084
- 'line-color': "#009EE0",
2083
+ 'line-color': '#009EE0',
2085
2084
  'line-dasharray': [0.2, 2],
2086
2085
  'line-width': 2,
2087
2086
  },
@@ -2094,7 +2093,7 @@ function featureEditorStyle() {
2094
2093
  'circle-radius': mediaIsMobile ? 5 : 4,
2095
2094
  'circle-color': '#ffffff',
2096
2095
  'circle-stroke-color': '#009EE0',
2097
- 'circle-stroke-width': 1
2096
+ 'circle-stroke-width': 1,
2098
2097
  },
2099
2098
  },
2100
2099
  {
@@ -2114,7 +2113,7 @@ function featureEditorStyle() {
2114
2113
  'circle-radius': mediaIsMobile ? 7 : 5,
2115
2114
  'circle-color': '#ffffff',
2116
2115
  'circle-stroke-color': '#009EE0',
2117
- 'circle-stroke-width': 1
2116
+ 'circle-stroke-width': 1,
2118
2117
  },
2119
2118
  },
2120
2119
  {
@@ -2631,16 +2630,22 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
2631
2630
  return defaultPaintOverrides.fill;
2632
2631
  }
2633
2632
  return {
2634
- 'fill-color': 'rgba(10,240,256,0.6)',
2635
- 'fill-outline-color': 'rgba(20,230,256,0.8)',
2633
+ // 'fill-color': 'rgba(10,240,256,0.6)',
2634
+ // 'fill-outline-color': 'rgba(20,230,256,0.8)',
2635
+ 'fill-color': '#009EE0',
2636
+ 'fill-outline-color': '#009EE0'
2636
2637
  };
2637
2638
  case 'line':
2638
2639
  if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
2640
+ console.log(defaultPaintOverrides.line);
2639
2641
  return defaultPaintOverrides.line;
2640
2642
  }
2641
2643
  return {
2642
- 'line-color': 'rgb(203,211,2)',
2643
- 'line-width': 5,
2644
+ // // 'line-color': 'rgb(203,211,2)',
2645
+ // 'line-width': 5,
2646
+ // 'line-blur': 0,
2647
+ 'line-color': '#009EE0',
2648
+ 'line-width': 4,
2644
2649
  'line-blur': 0,
2645
2650
  };
2646
2651
  case 'circle':
@@ -2648,10 +2653,14 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
2648
2653
  return defaultPaintOverrides.circle;
2649
2654
  }
2650
2655
  return {
2651
- 'circle-color': 'rgba(10,240,256,0.8)',
2656
+ // 'circle-color': 'rgba(10,240,256,0.8)',
2657
+ // 'circle-stroke-color': '#fff',
2658
+ // 'circle-stroke-width': 2,
2659
+ // 'circle-radius': 4,
2660
+ 'circle-color': '#009EE0',
2652
2661
  'circle-stroke-color': '#fff',
2653
2662
  'circle-stroke-width': 2,
2654
- 'circle-radius': 4,
2663
+ 'circle-radius': 5,
2655
2664
  };
2656
2665
  default:
2657
2666
  return {};
@@ -4353,6 +4362,23 @@ MlLayerSwipe.defaultProps = {
4353
4362
  buttonStyle: {},
4354
4363
  };
4355
4364
 
4365
+ function _arrayLikeToArray(r, a) {
4366
+ (null == a || a > r.length) && (a = r.length);
4367
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4368
+ return n;
4369
+ }
4370
+ function _arrayWithoutHoles(r) {
4371
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
4372
+ }
4373
+ function _iterableToArray(r) {
4374
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
4375
+ }
4376
+ function _nonIterableSpread() {
4377
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4378
+ }
4379
+ function _toConsumableArray(r) {
4380
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
4381
+ }
4356
4382
  function _typeof(o) {
4357
4383
  "@babel/helpers - typeof";
4358
4384
 
@@ -4362,33 +4388,15 @@ function _typeof(o) {
4362
4388
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
4363
4389
  }, _typeof(o);
4364
4390
  }
4365
- function _toConsumableArray(arr) {
4366
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
4367
- }
4368
- function _arrayWithoutHoles(arr) {
4369
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
4370
- }
4371
- function _iterableToArray(iter) {
4372
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
4373
- }
4374
- function _unsupportedIterableToArray(o, minLen) {
4375
- if (!o) return;
4376
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
4377
- var n = Object.prototype.toString.call(o).slice(8, -1);
4378
- if (n === "Object" && o.constructor) n = o.constructor.name;
4379
- if (n === "Map" || n === "Set") return Array.from(o);
4380
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
4381
- }
4382
- function _arrayLikeToArray(arr, len) {
4383
- if (len == null || len > arr.length) len = arr.length;
4384
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
4385
- return arr2;
4386
- }
4387
- function _nonIterableSpread() {
4388
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4391
+ function _unsupportedIterableToArray(r, a) {
4392
+ if (r) {
4393
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
4394
+ var t = {}.toString.call(r).slice(8, -1);
4395
+ 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;
4396
+ }
4389
4397
  }
4390
4398
 
4391
- var _showNextTransitionSegment = function _showNextTransitionSegment(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson) {
4399
+ var _showNextTransitionSegment2 = function _showNextTransitionSegment(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson) {
4392
4400
  var _arguments = arguments;
4393
4401
  if (typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !== "undefined") {
4394
4402
  // if at last transition step set to target geojson
@@ -4401,7 +4409,7 @@ var _showNextTransitionSegment = function _showNextTransitionSegment(props, map,
4401
4409
  currentTransitionStepRef.current++;
4402
4410
  if (transitionInProgressRef.current && currentTransitionStepRef.current < transitionGeojsonDataRef.current.length) {
4403
4411
  transitionTimeoutRef.current = setTimeout(function () {
4404
- return _showNextTransitionSegment.apply(void 0, _toConsumableArray(_arguments));
4412
+ return _showNextTransitionSegment2.apply(void 0, _toConsumableArray(_arguments));
4405
4413
  }, msPerStep);
4406
4414
  } else {
4407
4415
  if (typeof props.onTransitionEnd === "function") {
@@ -4491,7 +4499,7 @@ var _transitionToGeojson = function _transitionToGeojson(props, transitionGeojso
4491
4499
  currentTransitionStepRef.current = 1;
4492
4500
  transitionInProgressRef.current = true;
4493
4501
  transitionTimeoutRef.current = setTimeout(function () {
4494
- return _showNextTransitionSegment(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson);
4502
+ return _showNextTransitionSegment2(props, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef, setDisplayGeojson);
4495
4503
  }, msPerStep);
4496
4504
  };
4497
4505
  var createTransitionSteps = function createTransitionSteps(linestringCoordinates, perStepDistance, stepCnt) {
@@ -4580,76 +4588,130 @@ var MlTransitionGeoJsonLayer = function (props) {
4580
4588
  React__default.createElement(MlGeoJsonLayer, __assign({}, restProps, { geojson: displayGeojson }))));
4581
4589
  };
4582
4590
 
4583
- /**
4584
- * Adds a marker to the map and displays the contents of the "content" property in an iframe next to it
4585
- */
4586
- var MlMarker = function (props) {
4591
+ var getBoxTransform = function (anchor) {
4592
+ if (anchor === void 0) { anchor = 'top'; }
4593
+ switch (anchor) {
4594
+ case 'bottom':
4595
+ return 'translate(-50%, 0%)';
4596
+ case 'left':
4597
+ return 'translate(-100%, -50%)';
4598
+ case 'right':
4599
+ return 'translate(0%, -50%)';
4600
+ case 'top-left':
4601
+ return 'translate(-100%, -100%)';
4602
+ case 'top-right':
4603
+ return 'translate(0%, -100%)';
4604
+ case 'bottom-left':
4605
+ return 'translate(-100%, 0%)';
4606
+ case 'bottom-right':
4607
+ return 'translate(0%, 0%)';
4608
+ default:
4609
+ case 'top':
4610
+ return 'translate(-50%, -100%)';
4611
+ }
4612
+ };
4613
+ function getBoxMargins(anchor, offset, style) {
4614
+ var w = parseInt(String((style === null || style === void 0 ? void 0 : style.width) || 14), 10);
4615
+ var h = parseInt(String((style === null || style === void 0 ? void 0 : style.height) || 14), 10);
4616
+ var m = {};
4617
+ switch (anchor) {
4618
+ case 'bottom':
4619
+ m.marginTop = "".concat(offset, "px");
4620
+ break;
4621
+ case 'left':
4622
+ m.marginLeft = "-".concat(offset, "px");
4623
+ break;
4624
+ case 'right':
4625
+ m.marginLeft = "".concat(w + offset, "px");
4626
+ break;
4627
+ case 'top-left':
4628
+ m.marginTop = "-".concat(h + offset, "px");
4629
+ m.marginLeft = "-".concat(offset, "px");
4630
+ break;
4631
+ case 'top-right':
4632
+ m.marginTop = "-".concat(h + offset, "px");
4633
+ m.marginLeft = "".concat(w + offset, "px");
4634
+ break;
4635
+ case 'bottom-left':
4636
+ m.marginTop = "".concat(offset, "px");
4637
+ m.marginLeft = "-".concat(offset, "px");
4638
+ break;
4639
+ case 'bottom-right':
4640
+ m.marginTop = "".concat(offset, "px");
4641
+ m.marginLeft = "".concat(w + offset, "px");
4642
+ break;
4643
+ case 'top':
4644
+ default:
4645
+ m.marginTop = "-".concat(h + offset, "px");
4646
+ break;
4647
+ }
4648
+ return m;
4649
+ }
4650
+ var MlMarker = function (_a) {
4651
+ 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
4652
  var mapHook = useMap({
4588
4653
  mapId: props.mapId,
4589
4654
  waitForLayer: props.insertBeforeLayer,
4590
4655
  });
4591
- var mapState = useMapState({
4592
- mapId: props.mapId,
4593
- watch: { viewport: true },
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];
4656
+ var _d = useState(null), marker = _d[0], setMarker = _d[1];
4657
+ var container = useRef(null);
4658
+ var iframeRef = useRef(null);
4601
4659
  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]);
4608
- useEffect(function () {
4609
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
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))
4660
+ if (!mapHook.map)
4612
4661
  return;
4613
- var mapHeight = mapHook.map.map._container.clientHeight;
4614
- var _pixelPos = mapHook.map.map.project([props.lng, props.lat]);
4615
- var pixelToBottom = mapHeight - _pixelPos.y;
4616
- var iframeHeight = (_h = (_g = (_f = (_e = iframe.current) === null || _e === void 0 ? void 0 : _e.contentWindow) === null || _f === void 0 ? void 0 : _f.document) === null || _g === void 0 ? void 0 : _g.body) === null || _h === void 0 ? void 0 : _h.scrollHeight;
4617
- var iframeWidth = (_m = (_l = (_k = (_j = iframe.current) === null || _j === void 0 ? void 0 : _j.contentWindow) === null || _k === void 0 ? void 0 : _k.document) === null || _l === void 0 ? void 0 : _l.body) === null || _m === void 0 ? void 0 : _m.scrollWidth;
4618
- setIframeDimensions({
4619
- width: iframeWidth + "px",
4620
- height: (pixelToBottom < iframeHeight ? pixelToBottom : iframeHeight) + "px",
4662
+ container.current = document.createElement('div');
4663
+ var defaultMarkerStyle = {
4664
+ width: '12px',
4665
+ height: '12px',
4666
+ background: 'linear-gradient(135deg, rgb(186, 208, 218) 0%, rgb(96, 209, 253) 100%)',
4667
+ border: '1px solid rgba(255, 255, 255, 0.7)',
4668
+ boxShadow: '0 2px 6px rgba(90, 0, 0, 0.2), 0 0 0 2px rgba(240, 147, 251, 0.2)',
4669
+ borderRadius: '50%',
4670
+ };
4671
+ var markerStyle = __assign(__assign({}, defaultMarkerStyle), props.markerStyle);
4672
+ var maplibreMarker = new maplibregl.Marker({
4673
+ element: container.current,
4674
+ anchor: 'center',
4675
+ })
4676
+ .setLngLat([props.lng, props.lat])
4677
+ .addTo(mapHook.map.map);
4678
+ setMarker(maplibreMarker);
4679
+ var markerDot = document.createElement('div');
4680
+ Object.entries(markerStyle).forEach(function (_a) {
4681
+ var key = _a[0], value = _a[1];
4682
+ markerDot.style.setProperty(key.replace(/([A-Z])/g, '-$1').toLowerCase(), String(value));
4621
4683
  });
4622
- }, [props.lng, props.lat, props.content]);
4623
- return (React__default.createElement(React__default.Fragment, null,
4624
- React__default.createElement(MlGeoJsonLayer, { geojson: {
4625
- type: "Feature",
4626
- geometry: {
4627
- type: "Point",
4628
- coordinates: [props.lng, props.lat],
4629
- },
4630
- properties: {},
4631
- }, paint: {
4632
- "circle-radius": 14,
4633
- "circle-color": "rgba(40,200,20,0.5)",
4634
- }, type: "circle", mapId: props.mapId }),
4635
- markerPixelPos && (React__default.createElement(Paper$1, { sx: {
4636
- opacity: 0.7,
4637
- position: "fixed",
4638
- display: "flex",
4639
- /** TODO: fix positioning delay when moving the map */
4640
- left: markerPixelPos.x,
4641
- top: markerPixelPos.y,
4642
- width: iframeDimensions.width,
4643
- height: iframeDimensions.height,
4644
- "&:hover": {
4684
+ container.current.appendChild(markerDot);
4685
+ return function () {
4686
+ var _a;
4687
+ markerDot.remove();
4688
+ maplibreMarker.remove();
4689
+ (_a = container.current) === null || _a === void 0 ? void 0 : _a.remove();
4690
+ };
4691
+ }, [mapHook.map, props.lng, props.lat, props.markerStyle, props.anchor]);
4692
+ useEffect(function () {
4693
+ if (marker) {
4694
+ marker.setLngLat([props.lng, props.lat]);
4695
+ }
4696
+ }, [marker, props.lng, props.lat]);
4697
+ function handleIframeLoad() {
4698
+ var _a, _b, _c;
4699
+ var iframeDoc = (_b = (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
4700
+ if (iframeDoc && ((_c = iframeRef.current) === null || _c === void 0 ? void 0 : _c.parentElement)) {
4701
+ var scrollHeight = iframeDoc.documentElement.scrollHeight;
4702
+ iframeRef.current.parentElement.style.height = "".concat(scrollHeight, "px");
4703
+ }
4704
+ }
4705
+ return (container.current &&
4706
+ 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
4707
  opacity: 1,
4646
- },
4647
- zIndex: -1,
4648
- } },
4649
- React__default.createElement("iframe", { style: { width: "100%" }, srcDoc: props.content, ref: iframe, sandbox: "allow-same-origin allow-popups-to-escape-sandbox", frameBorder: "0", title: mapHook.componentId })))));
4650
- };
4651
- MlMarker.defaultProps = {
4652
- mapId: undefined,
4708
+ } }), props.containerStyle) },
4709
+ 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 || {})
4710
+ .map(function (_a) {
4711
+ var key = _a[0], val = _a[1];
4712
+ return "".concat(key.replace(/([A-Z])/g, '-$1').toLowerCase(), ": ").concat(val, ";");
4713
+ })
4714
+ .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
4715
  };
4654
4716
 
4655
4717
  /**
@@ -6928,41 +6990,61 @@ var sketchTools = [
6928
6990
  *
6929
6991
  */
6930
6992
  var MlSketchTool = function (props) {
6931
- var _a, _b;
6932
6993
  var mapHook = useMap({
6933
6994
  mapId: props.mapId,
6934
6995
  waitForLayer: props.insertBeforeLayer,
6935
6996
  });
6936
- var _c = useState(), hoveredGeometry = _c[0], setHoveredGeometry = _c[1];
6937
- var _d = useState({
6997
+ var _a = useState(), hoveredGeometry = _a[0], setHoveredGeometry = _a[1];
6998
+ var _b = useState({
6938
6999
  activeGeometryIndex: undefined,
6939
7000
  selectedGeoJson: undefined,
6940
7001
  geometries: [],
6941
7002
  drawMode: undefined,
6942
- }), sketchState = _d[0], setSketchState = _d[1];
7003
+ }), sketchState = _b[0], setSketchState = _b[1];
7004
+ console.log(sketchState);
6943
7005
  useEffect(function () {
6944
7006
  if (!(typeof props.onChange === 'function'))
6945
7007
  return;
6946
7008
  props.onChange(sketchState);
6947
7009
  }, [sketchState, props.onChange]);
6948
7010
  var buttonStyle = __assign({}, props.buttonStyleOverride);
7011
+ // const buttonClickHandler = (buttonDrawMode: keyof MapboxDraw.Modes) => {
7012
+ // setSketchState((_state) => ({
7013
+ // drawMode: _state.drawMode !== buttonDrawMode ? buttonDrawMode : undefined,
7014
+ // geometries: _state.geometries,
7015
+ // activeGeometryIndex: undefined,
7016
+ // selectedGeoJson: undefined,
7017
+ // }));
7018
+ // };
6949
7019
  var buttonClickHandler = function (buttonDrawMode) {
6950
- setSketchState(function (_state) { return ({
6951
- drawMode: _state.drawMode !== buttonDrawMode ? buttonDrawMode : undefined,
6952
- geometries: _state.geometries,
6953
- activeGeometryIndex: undefined,
6954
- selectedGeoJson: undefined,
6955
- }); });
7020
+ var modeRef = undefined;
7021
+ setSketchState(function (prevState) {
7022
+ modeRef = prevState.drawMode;
7023
+ return __assign(__assign({}, prevState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined });
7024
+ });
7025
+ requestAnimationFrame(function () {
7026
+ setSketchState(function (prevState) {
7027
+ if ((modeRef === 'draw_polygon' || modeRef === 'draw_line_string') &&
7028
+ buttonDrawMode === 'draw_point') {
7029
+ return __assign(__assign({}, prevState), { drawMode: undefined });
7030
+ }
7031
+ return __assign(__assign({}, prevState), { drawMode: buttonDrawMode });
7032
+ });
7033
+ });
6956
7034
  };
6957
7035
  var removeGeoJson = function (geoJson) {
6958
7036
  setSketchState(function (_sketchState) {
6959
7037
  var _geometries = __spreadArray([], _sketchState.geometries, true);
6960
7038
  _geometries.splice(_geometries.indexOf(geoJson), 1);
6961
- return __assign(__assign({}, _sketchState), { geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
7039
+ return __assign(__assign({}, _sketchState), { drawMode: undefined, geometries: _geometries, activeGeometryIndex: _sketchState.activeGeometryIndex
6962
7040
  ? _sketchState.activeGeometryIndex - 1
6963
7041
  : undefined });
6964
7042
  });
6965
7043
  };
7044
+ var handleCheckboxChange = function (event) {
7045
+ var _a;
7046
+ (_a = props.onShowInstructionChange) === null || _a === void 0 ? void 0 : _a.call(props, event.target.checked);
7047
+ };
6966
7048
  var SketchToolButtons = function () {
6967
7049
  return (React__default.createElement(React__default.Fragment, null, sketchTools.map(function (el) {
6968
7050
  var stateColor = function (theme) {
@@ -6994,7 +7076,11 @@ var MlSketchTool = function (props) {
6994
7076
  } },
6995
7077
  React__default.createElement(ButtonGroup, null,
6996
7078
  React__default.createElement(SketchToolButtons, null))),
7079
+ React__default.createElement(Box, { sx: { marginTop: '10px' } },
7080
+ React__default.createElement(FormGroup, null,
7081
+ React__default.createElement(FormControlLabel, { control: React__default.createElement(Checkbox, { size: "small", checked: props.showInstruction, onChange: handleCheckboxChange }), label: "Show instructions" }))),
6997
7082
  sketchState.drawMode && (React__default.createElement(MlFeatureEditor, { mode: sketchState.drawMode, geojson: sketchState.selectedGeoJson, onChange: function (feature) {
7083
+ console.log(feature);
6998
7084
  if (!(feature === null || feature === void 0 ? void 0 : feature[0]))
6999
7085
  return;
7000
7086
  setSketchState(function (_sketchState) {
@@ -7013,65 +7099,152 @@ var MlSketchTool = function (props) {
7013
7099
  else {
7014
7100
  _geometries[_sketchState.activeGeometryIndex] = feature[0];
7015
7101
  }
7102
+ // Check if the geometry type is point and if the coordinates have changed to exit draw mode after editing
7103
+ var changedPoint = function () {
7104
+ var _a, _b, _c, _d;
7105
+ if (_sketchState.selectedGeoJson &&
7106
+ typeof _sketchState.activeGeometryIndex !== 'undefined' &&
7107
+ _sketchState.geometries[_sketchState.activeGeometryIndex] &&
7108
+ _sketchState.geometries[_sketchState.activeGeometryIndex].geometry.type ===
7109
+ 'Point') {
7110
+ var selectedCoords = (_b = (_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 : _b.coordinates;
7111
+ var activeCoords = (_d = (_c = _sketchState.geometries[_sketchState.activeGeometryIndex]) === null || _c === void 0 ? void 0 : _c.geometry) === null || _d === void 0 ? void 0 : _d.coordinates;
7112
+ // Compare coordinates
7113
+ return JSON.stringify(selectedCoords) !== JSON.stringify(activeCoords);
7114
+ }
7115
+ return false;
7116
+ };
7117
+ if (changedPoint()) {
7118
+ _sketchState.drawMode = undefined;
7119
+ }
7016
7120
  return __assign(__assign({}, _sketchState), { geometries: _geometries });
7017
7121
  });
7018
7122
  }, onFinish: function () {
7019
7123
  setSketchState(function (_sketchState) { return (__assign(__assign({}, _sketchState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined })); });
7020
7124
  } })),
7021
7125
  React__default.createElement(List$1, { sx: { zIndex: 105, marginBottom: '-10px' } },
7022
- sketchState.geometries.map(function (el) { return (React__default.createElement(React__default.Fragment, null,
7023
- React__default.createElement(Box, { key: el.id, sx: { display: 'flex', flexDirection: 'column' } },
7024
- React__default.createElement("br", null),
7025
- React__default.createElement(Box, { flexDirection: 'row', sx: {
7026
- '&:hover': {
7027
- backgroundColor: 'rgb(177, 177, 177, 0.2)',
7028
- },
7029
- marginTop: '25px',
7030
- }, onMouseOver: function () {
7031
- setHoveredGeometry(el);
7032
- }, onMouseLeave: function () {
7033
- setHoveredGeometry(undefined);
7034
- } },
7035
- React__default.createElement(LayerListItem, { listItemSx: buttonStyle, configurable: true, layerComponent: React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: el, layerId: String(el.id) }), type: 'layer', name: String(el.id), description: el.geometry.type }),
7036
- React__default.createElement(Box, { sx: {
7037
- padding: '3px 30px',
7126
+ sketchState.geometries.map(function (el, index) {
7127
+ var _a, _b, _c;
7128
+ return (React__default.createElement(React__default.Fragment, null,
7129
+ React__default.createElement(Box, { key: el.id, sx: { display: 'flex', flexDirection: 'column' } },
7130
+ React__default.createElement("br", null),
7131
+ React__default.createElement(Box, { flexDirection: 'row', sx: {
7132
+ '&:hover': {
7133
+ backgroundColor: 'rgb(177, 177, 177, 0.2)',
7134
+ },
7135
+ marginTop: '25px',
7136
+ }, onMouseOver: function () {
7137
+ setHoveredGeometry(el);
7138
+ }, onMouseLeave: function () {
7139
+ setHoveredGeometry(undefined);
7038
7140
  } },
7039
- React__default.createElement(ButtonGroup, { size: "small" },
7040
- React__default.createElement(Button, { onClick: function () {
7041
- var _a;
7042
- (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.map.setCenter(el.geometry.type === 'Point'
7043
- ? el.geometry.coordinates
7044
- : turf.centerOfMass(el).geometry.coordinates);
7045
- } },
7046
- React__default.createElement(GpsFixedIcon, null)),
7047
- React__default.createElement(Button, { sx: buttonStyle, onClick: function () {
7048
- setSketchState(function (_sketchState) { return (__assign(__assign({}, _sketchState), { selectedGeoJson: el, activeGeometryIndex: _sketchState.geometries.indexOf(el), drawMode: 'simple_select' })); });
7049
- } },
7050
- React__default.createElement(EditIcon, null)),
7051
- React__default.createElement(Button, { sx: buttonStyle, onClick: function () {
7052
- removeGeoJson(el);
7053
- setHoveredGeometry(undefined);
7054
- } },
7055
- React__default.createElement(DeleteIcon, null)))))))); }),
7141
+ !((_a = el.properties) === null || _a === void 0 ? void 0 : _a.customName) && (React__default.createElement("input", { type: "text", value: ((_b = el.properties) === null || _b === void 0 ? void 0 : _b.name) || '', placeholder: "Assign name", onChange: function (e) {
7142
+ var newName = e.target.value;
7143
+ setSketchState(function (_sketchState) {
7144
+ var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
7145
+ if (!updatedGeometries[index].properties) {
7146
+ updatedGeometries[index].properties = {};
7147
+ }
7148
+ updatedGeometries[index].properties.name = newName;
7149
+ return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
7150
+ });
7151
+ }, style: {
7152
+ padding: '5px',
7153
+ border: '1px solid #ccc',
7154
+ borderRadius: '4px',
7155
+ outline: 'none',
7156
+ }, onFocus: function (e) { return (e.target.style.borderColor = '#009ee0'); }, onBlur: function (e) {
7157
+ e.target.style.borderColor = '#ccc';
7158
+ setSketchState(function (_sketchState) {
7159
+ var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
7160
+ if (!updatedGeometries[index].properties) {
7161
+ updatedGeometries[index].properties = {};
7162
+ }
7163
+ updatedGeometries[index].properties.customName = true;
7164
+ return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
7165
+ });
7166
+ } })),
7167
+ React__default.createElement(LayerListItem, { listItemSx: buttonStyle, configurable: true, layerComponent: React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: el, layerId: String(el.id), defaultPaintOverrides: {
7168
+ fill: { 'fill-opacity': 0.5 },
7169
+ } }), type: 'layer', name: React__default.createElement(Typography, { onClick: function () {
7170
+ setSketchState(function (_sketchState) {
7171
+ var updatedGeometries = __spreadArray([], _sketchState.geometries, true);
7172
+ if (!updatedGeometries[index].properties) {
7173
+ updatedGeometries[index].properties = {};
7174
+ }
7175
+ updatedGeometries[index].properties.customName = false;
7176
+ return __assign(__assign({}, _sketchState), { geometries: updatedGeometries });
7177
+ });
7178
+ }, sx: {
7179
+ cursor: 'pointer',
7180
+ overflow: 'hidden',
7181
+ whiteSpace: 'nowrap',
7182
+ } }, ((_c = el.properties) === null || _c === void 0 ? void 0 : _c.name) || String(el.id)), description: el.geometry.type }),
7183
+ React__default.createElement(Box, { sx: {
7184
+ padding: '3px 30px',
7185
+ } },
7186
+ React__default.createElement(ButtonGroup, { size: "small" },
7187
+ React__default.createElement(Tooltip$1, { title: "Center" },
7188
+ 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 () {
7189
+ var _a;
7190
+ (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.map.setCenter(el.geometry.type === 'Point'
7191
+ ? el.geometry.coordinates
7192
+ : turf.centerOfMass(el).geometry.coordinates);
7193
+ } },
7194
+ React__default.createElement(GpsFixedIcon, null))),
7195
+ React__default.createElement(Tooltip$1, { title: "Edit" },
7196
+ React__default.createElement(Button, { sx: __assign({ color: function (theme) {
7197
+ var _a;
7198
+ if (sketchState.drawMode === 'simple_select' &&
7199
+ ((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
7200
+ return theme.palette.navigation.navColor;
7201
+ }
7202
+ else {
7203
+ return theme.palette.primary.main;
7204
+ }
7205
+ }, backgroundColor: function (theme) {
7206
+ var _a;
7207
+ if (sketchState.drawMode === 'simple_select' &&
7208
+ ((_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id) {
7209
+ return theme.palette.primary.main;
7210
+ }
7211
+ else {
7212
+ return theme.palette.navigation.navColor;
7213
+ }
7214
+ } }, buttonStyle), onClick: function () {
7215
+ setSketchState(function (_sketchState) {
7216
+ var _a;
7217
+ var newDrawMode = _sketchState.drawMode === 'simple_select' &&
7218
+ ((_a = _sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.id) === el.id
7219
+ ? undefined
7220
+ : 'simple_select';
7221
+ return __assign(__assign({}, _sketchState), { selectedGeoJson: el, activeGeometryIndex: _sketchState.geometries.indexOf(el), drawMode: newDrawMode });
7222
+ });
7223
+ } },
7224
+ React__default.createElement(EditIcon, null))),
7225
+ React__default.createElement(Tooltip$1, { title: "Delete" },
7226
+ 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 () {
7227
+ removeGeoJson(el);
7228
+ setHoveredGeometry(undefined);
7229
+ } },
7230
+ React__default.createElement(DeleteIcon, null)))))))));
7231
+ }),
7056
7232
  hoveredGeometry && (React__default.createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, layerId: 'highlightBorder', defaultPaintOverrides: {
7057
7233
  circle: {
7058
- 'circle-color': '#dd9900',
7059
- 'circle-opacity': 0.4,
7234
+ 'circle-color': '#000000',
7235
+ 'circle-opacity': 0.2,
7060
7236
  'circle-radius': 10,
7061
7237
  },
7062
7238
  line: {
7063
- 'line-color': '#dd9900',
7064
- 'line-opacity': 0.4,
7239
+ 'line-color': '#000000',
7240
+ 'line-opacity': 0.2,
7065
7241
  'line-width': 10,
7066
7242
  },
7067
7243
  fill: {
7068
- 'fill-color': '#dd9900',
7069
- 'fill-opacity': 0.4,
7244
+ 'fill-color': '#000000',
7245
+ 'fill-opacity': 0.2,
7070
7246
  },
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))));
7247
+ } })))));
7075
7248
  };
7076
7249
  MlSketchTool.defaultProps = {
7077
7250
  mapId: undefined,