@mapcomponents/react-maplibre 0.1.88 → 0.1.90

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.1.89] - 2024-01-02
4
+
5
+ ### Fixed
6
+
7
+ - ca2fe4e: fix AddLayerButton mbtiles useAddProtocol
8
+
3
9
  ## [v0.1.88] - 2023-12-22
4
10
 
5
11
  ### Added
@@ -18,7 +18,12 @@ interface MlMeasureToolProps {
18
18
  value: number;
19
19
  unit: string | undefined;
20
20
  geojson: GeoJSONObject;
21
+ geometries?: [];
21
22
  }) => void;
23
+ /**
24
+ * Callback function that is called by the end of drawing geometries.
25
+ */
26
+ onFinish?: () => void;
22
27
  }
23
28
  declare const MlMeasureTool: {
24
29
  (props: MlMeasureToolProps): JSX.Element;
@@ -0,0 +1,55 @@
1
+ /// <reference types="react" />
2
+ import { SxProps } from '@mui/material';
3
+ import * as turf from '@turf/turf';
4
+ import { GeoJSONObject } from '@turf/turf';
5
+ export interface MlMultiMeasureToolProps {
6
+ /**
7
+ * Id of the target MapLibre instance in mapContext
8
+ */
9
+ mapId?: string;
10
+ /**
11
+ * Id of an existing layer in the mapLibre instance to help specify the layer order
12
+ * This layer will be visually beneath the layer with the "insertBeforeLayer" id.
13
+ */
14
+ insertBeforeLayer?: string;
15
+ /**
16
+ * Style attribute for the button-style
17
+ * https://mui.com/system/getting-started/the-sx-prop/
18
+ */
19
+ buttonStyleOverride?: SxProps;
20
+ /**
21
+ * String that specify if the Tool measures an area ("polygon") or length ("line")
22
+ */
23
+ measureType?: 'polygon' | 'line';
24
+ /**
25
+ * Boolean which decides if the user can switch between measure modes
26
+ */
27
+ multiType?: boolean;
28
+ /**
29
+ * String that dictates which unit of measurement is used
30
+ */
31
+ unit?: turf.Units;
32
+ /**
33
+ * Callback function that is called each time measurment geometry within has changed within MlMeasureTool.
34
+ * First parameter is the new GeoJson feature.
35
+ */
36
+ onChange?: (options: {
37
+ value: number;
38
+ unit: string | undefined;
39
+ geojson: GeoJSONObject;
40
+ geometries?: [];
41
+ }) => void;
42
+ /**
43
+ * Callback function that is called by the end of drawing geometries.
44
+ */
45
+ onFinish?: () => void;
46
+ }
47
+ declare const MlMultiMeasureTool: {
48
+ (props: MlMultiMeasureToolProps): JSX.Element;
49
+ defaultProps: {
50
+ mapId: undefined;
51
+ measureType: string;
52
+ buttonStyleOverride: {};
53
+ };
54
+ };
55
+ export default MlMultiMeasureTool;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ declare const storyoptions: {
3
+ title: string;
4
+ component: {
5
+ (props: import("./MlMultiMeasureTool").MlMultiMeasureToolProps): JSX.Element;
6
+ defaultProps: {
7
+ mapId: undefined;
8
+ measureType: string;
9
+ buttonStyleOverride: {};
10
+ };
11
+ };
12
+ argTypes: {};
13
+ decorators: ((Story: any, context: any) => JSX.Element)[];
14
+ };
15
+ export default storyoptions;
16
+ export declare const ExampleConfig: any;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { Feature } from '@turf/turf';
2
3
  import { SxProps } from '@mui/system/styleFunctionSx/styleFunctionSx';
3
4
  export interface MlSketchToolProps {
4
5
  /**
@@ -15,7 +16,18 @@ export interface MlSketchToolProps {
15
16
  * https://mui.com/system/getting-started/the-sx-prop/
16
17
  */
17
18
  buttonStyleOverride?: SxProps;
19
+ /**
20
+ * Callback function that is called each time GeoJson data has changed within MlSketchTool.
21
+ * First parameter contains all geometries in the `geometries` prop.
22
+ */
23
+ onChange?: (para: SketchStateType) => void;
18
24
  }
25
+ type SketchStateType = {
26
+ selectedGeoJson?: Feature;
27
+ activeGeometryIndex?: number;
28
+ geometries: Feature[];
29
+ drawMode?: keyof MapboxDraw.Modes;
30
+ };
19
31
  /**
20
32
  * Component template
21
33
  *
@@ -16,7 +16,7 @@ export interface useFeatureEditorProps {
16
16
  */
17
17
  geojson?: Feature;
18
18
  /**
19
- * Callback function that is called each time the GeoJson data within has changed within MlFeatureEditor.
19
+ * Callback function that is called each time the GeoJson data has changed within MlFeatureEditor.
20
20
  * First parameter is the new GeoJson feature.
21
21
  */
22
22
  onChange?: (para: GeoJSONObject[]) => void;
package/dist/index.esm.js CHANGED
@@ -2036,7 +2036,7 @@ function PdfForm(props) {
2036
2036
  ]);
2037
2037
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2038
2038
  React__default["default"].createElement(material.FormControl, { fullWidth: true, sx: formControlStyles },
2039
- React__default["default"].createElement(material.InputLabel, { id: "format-select-label" }, "Format"),
2039
+ React__default["default"].createElement(material.InputLabel, { sx: { marginTop: '3px' }, id: "format-select-label" }, "Format"),
2040
2040
  React__default["default"].createElement(material.Select, { labelId: "format-select-label", id: "format-select", label: "Format", value: pdfContext.format, onChange: function (event) {
2041
2041
  var _a;
2042
2042
  (_a = pdfContext.setFormat) === null || _a === void 0 ? void 0 : _a.call(pdfContext, event.target.value);
@@ -2319,7 +2319,6 @@ function featureEditorStyle() {
2319
2319
  * GeoJson Feature editor that allows to create or manipulate GeoJson data
2320
2320
  */
2321
2321
  var useFeatureEditor = function (props) {
2322
- console.log(featureEditorStyle());
2323
2322
  var draw = React.useRef();
2324
2323
  var mapHook = useMap({
2325
2324
  mapId: props.mapId,
@@ -2908,8 +2907,9 @@ var MlMeasureTool = function (props) {
2908
2907
  React.useEffect(function () {
2909
2908
  if (currentFeatures[0]) {
2910
2909
  var result = props.measureType === 'polygon'
2911
- // for "polyong" mode calculate km²
2912
- ? (turf__namespace.area(currentFeatures[0]) / 1000000) * getUnitSquareMultiplier(props.unit)
2910
+ ? // for "polyong" mode calculate km²
2911
+ (turf__namespace.area(currentFeatures[0]) / 1000000) *
2912
+ getUnitSquareMultiplier(props.unit)
2913
2913
  : turf__namespace.length(currentFeatures[0], { units: props.unit });
2914
2914
  if (typeof props.onChange === 'function') {
2915
2915
  props.onChange({ value: result, unit: props.unit, geojson: currentFeatures[0] });
@@ -2936,12 +2936,14 @@ var MlMeasureTool = function (props) {
2936
2936
  }, [props.unit, currentFeatures]);
2937
2937
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2938
2938
  React__default["default"].createElement(MlFeatureEditor, { onChange: function (features) {
2939
- setCurrentFeatures(features);
2940
- }, mode: props.measureType === 'polygon' ? 'draw_polygon' : 'draw_line_string' }),
2939
+ features && setCurrentFeatures(features);
2940
+ }, mode: props.measureType === 'polygon' ? 'draw_polygon' : 'draw_line_string', onFinish: props.onFinish }),
2941
2941
  displayValue.value.toFixed(2),
2942
2942
  " ",
2943
- displayValue.label,
2944
- props.measureType === 'polygon' ? '²' : ''));
2943
+ '',
2944
+ React__default["default"].createElement(material.Typography, null,
2945
+ displayValue.label,
2946
+ props.measureType === 'polygon' ? ' ²' : '')));
2945
2947
  };
2946
2948
  MlMeasureTool.defaultProps = {
2947
2949
  mapId: undefined,
@@ -2950,9 +2952,9 @@ MlMeasureTool.defaultProps = {
2950
2952
  };
2951
2953
 
2952
2954
  var _g;
2953
- function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
2955
+ function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
2954
2956
  var SvgCompassNeedle = function SvgCompassNeedle(props) {
2955
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
2957
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$2({
2956
2958
  width: 10,
2957
2959
  height: 40,
2958
2960
  viewBox: "0 0 10 40",
@@ -2970,10 +2972,10 @@ var SvgCompassNeedle = function SvgCompassNeedle(props) {
2970
2972
  }))));
2971
2973
  };
2972
2974
 
2973
- var _circle, _path, _path2, _path3, _path4;
2974
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2975
+ var _circle, _path$1, _path2$1, _path3, _path4;
2976
+ function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
2975
2977
  var SvgCompassBackground = function SvgCompassBackground(props) {
2976
- return /*#__PURE__*/React__namespace.createElement("svg", _extends({
2978
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
2977
2979
  width: 52,
2978
2980
  height: 53,
2979
2981
  viewBox: "0 0 52 53",
@@ -2986,10 +2988,10 @@ var SvgCompassBackground = function SvgCompassBackground(props) {
2986
2988
  fill: "white",
2987
2989
  stroke: "#009EE0",
2988
2990
  strokeWidth: 2
2989
- })), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
2991
+ })), _path$1 || (_path$1 = /*#__PURE__*/React__namespace.createElement("path", {
2990
2992
  d: "M26.4915 7.59161C26.3524 8.07338 25.6698 8.07338 25.5307 7.59161L24.2998 3.3276C24.2075 3.0079 24.4474 2.68893 24.7802 2.68893H27.242C27.5748 2.68893 27.8147 3.0079 27.7224 3.3276L26.4915 7.59161Z",
2991
2993
  fill: "#009EE0"
2992
- })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
2994
+ })), _path2$1 || (_path2$1 = /*#__PURE__*/React__namespace.createElement("path", {
2993
2995
  d: "M25.5085 44.7598C25.6476 44.278 26.3302 44.278 26.4693 44.7598L27.7002 49.0238C27.7925 49.3435 27.5526 49.6625 27.2198 49.6625H24.758C24.4252 49.6625 24.1853 49.3435 24.2776 49.0238L25.5085 44.7598Z",
2994
2996
  fill: "#009EE0"
2995
2997
  })), _path3 || (_path3 = /*#__PURE__*/React__namespace.createElement("path", {
@@ -3423,6 +3425,22 @@ MlLayerMagnify.defaultProps = {
3423
3425
  magnifierStyle: {},
3424
3426
  };
3425
3427
 
3428
+ var _path, _path2;
3429
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3430
+ var SvgIcononlyarrow = function SvgIcononlyarrow(props) {
3431
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends({
3432
+ viewBox: "0 0 47 30",
3433
+ fill: "none",
3434
+ xmlns: "http://www.w3.org/2000/svg"
3435
+ }, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
3436
+ d: "M29.5 21.25L35.75 15L29.5 8.75V21.25Z",
3437
+ fill: "#009EE0"
3438
+ })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
3439
+ d: "M17.5 8.75L11.25 15L17.5 21.25V8.75Z",
3440
+ fill: "#009EE0"
3441
+ })));
3442
+ };
3443
+
3426
3444
  /**
3427
3445
  * creates a split view of 2 synchronised maplibre instances
3428
3446
  */
@@ -3492,7 +3510,10 @@ var MlLayerSwipe = function (props) {
3492
3510
  document.removeEventListener('mouseup', onMouseUp);
3493
3511
  };
3494
3512
  function adjustWindowSize() {
3495
- var clipWidth = mapContext.maps[props.map2Id].getContainer().style.clip.split(',')[1].replace('px', '');
3513
+ var clipWidth = mapContext.maps[props.map2Id]
3514
+ .getContainer()
3515
+ .style.clip.split(',')[1]
3516
+ .replace('px', '');
3496
3517
  var canvasWidth = mapContext.maps[props.map1Id].getCanvas().getBoundingClientRect().width;
3497
3518
  if (parseFloat(clipWidth) < canvasWidth) {
3498
3519
  var newPosition = parseFloat(((clipWidth / canvasWidth) * 100).toFixed(2));
@@ -3510,7 +3531,13 @@ var MlLayerSwipe = function (props) {
3510
3531
  window.removeEventListener('resize', adjustWindowSize);
3511
3532
  };
3512
3533
  }, [mapContext]);
3513
- return (React__default["default"].createElement("div", { style: __assign({ position: 'absolute', left: swipeX + '%', top: '50%', borderRadius: '50%', width: '100px', height: '100px', background: '#0066ff', border: '3px solid #eaebf1', cursor: 'pointer', zIndex: '110', marginLeft: '-50px', marginTop: '-50px', textAlign: 'center', lineHeight: '91px', fontSize: '2em', color: '#fafafa', userSelect: 'none' }, props.buttonStyle), onTouchStart: onDown, onMouseDown: onDown }));
3534
+ return (React__default["default"].createElement("div", { style: __assign({ position: 'absolute', left: swipeX + '%', top: '50%', borderRadius: '50%', width: '65px', height: '65px', background: 'rgba(234, 235, 241, 0.75)', border: '2px solid rgba(0, 158, 224, 0.75)', cursor: 'pointer', zIndex: '110', marginLeft: '-35px', marginTop: '-50px', textAlign: 'center', lineHeight: '91px', fontSize: '2em', color: '#fafafa', userSelect: 'none' }, props.buttonStyle), onTouchStart: onDown, onMouseDown: onDown },
3535
+ React__default["default"].createElement(SvgIcononlyarrow, { color: "#0066ff", style: {
3536
+ width: '65px',
3537
+ height: '65px',
3538
+ justifyContent: 'center',
3539
+ zIndex: 1100,
3540
+ } })));
3514
3541
  };
3515
3542
  MlLayerSwipe.defaultProps = {
3516
3543
  buttonStyle: {},
@@ -6438,6 +6465,8 @@ var PaperStyled = material.styled(material.Paper)({
6438
6465
  marginRight: '-21px',
6439
6466
  paddingLeft: '53px',
6440
6467
  borderRadius: '0px',
6468
+ boxShadow: 'none',
6469
+ backgroundColor: 'rgb(0, 0, 0, 0)',
6441
6470
  });
6442
6471
  var BoxStyled = material.styled(material.Box)({
6443
6472
  marginLeft: '61px',
@@ -6744,6 +6773,11 @@ var MlSketchTool = function (props) {
6744
6773
  geometries: [],
6745
6774
  drawMode: undefined,
6746
6775
  }), sketchState = _d[0], setSketchState = _d[1];
6776
+ React.useEffect(function () {
6777
+ if (!(typeof props.onChange === 'function'))
6778
+ return;
6779
+ props.onChange(sketchState);
6780
+ }, [sketchState, props.onChange]);
6747
6781
  var buttonStyle = __assign({}, props.buttonStyleOverride);
6748
6782
  var buttonClickHandler = function (buttonDrawMode) {
6749
6783
  setSketchState(function (_state) { return ({
@@ -6812,7 +6846,7 @@ var MlSketchTool = function (props) {
6812
6846
  }, onFinish: function () {
6813
6847
  setSketchState(function (_sketchState) { return (__assign(__assign({}, _sketchState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined })); });
6814
6848
  } })),
6815
- React__default["default"].createElement(List__default["default"], { sx: { zIndex: 105 } },
6849
+ React__default["default"].createElement(List__default["default"], { sx: { zIndex: 105, marginBottom: '-10px' } },
6816
6850
  sketchState.geometries.map(function (el) { return (React__default["default"].createElement(React__default["default"].Fragment, null,
6817
6851
  React__default["default"].createElement(system.Box, { key: el.id, sx: { display: 'flex', flexDirection: 'column' } },
6818
6852
  React__default["default"].createElement("br", null),
@@ -6820,6 +6854,7 @@ var MlSketchTool = function (props) {
6820
6854
  '&:hover': {
6821
6855
  backgroundColor: 'rgb(177, 177, 177, 0.2)',
6822
6856
  },
6857
+ marginTop: '25px',
6823
6858
  }, onMouseOver: function () {
6824
6859
  setHoveredGeometry(el);
6825
6860
  }, onMouseLeave: function () {
@@ -6846,10 +6881,21 @@ var MlSketchTool = function (props) {
6846
6881
  setHoveredGeometry(undefined);
6847
6882
  } },
6848
6883
  React__default["default"].createElement(DeleteIcon__default["default"], null)))))))); }),
6849
- hoveredGeometry && (React__default["default"].createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, type: 'line', layerId: 'highlightBorder', paint: {
6850
- 'line-color': '#dd9900',
6851
- 'line-opacity': 0.4,
6852
- 'line-width': 10,
6884
+ hoveredGeometry && (React__default["default"].createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, layerId: 'highlightBorder', defaultPaintOverrides: {
6885
+ circle: {
6886
+ 'circle-color': '#dd9900',
6887
+ 'circle-opacity': 0.4,
6888
+ 'circle-radius': 10,
6889
+ },
6890
+ line: {
6891
+ 'line-color': '#dd9900',
6892
+ 'line-opacity': 0.4,
6893
+ 'line-width': 10,
6894
+ },
6895
+ fill: {
6896
+ 'fill-color': '#dd9900',
6897
+ 'fill-opacity': 0.4
6898
+ },
6853
6899
  } }))),
6854
6900
  sketchState.drawMode === 'simple_select' && (React__default["default"].createElement(material.Typography, { sx: { fontSize: '0.6em' } },
6855
6901
  "Edit ", (_b = (_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 :
@@ -8106,14 +8152,31 @@ var AddLayerPopup = function (props) {
8106
8152
  };
8107
8153
  AddLayerPopup.defaultProps = {};
8108
8154
 
8155
+ function AddProtocol(props) {
8156
+ useAddProtocol({
8157
+ protocol: props.protocol,
8158
+ handler: props.handler,
8159
+ });
8160
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
8161
+ }
8109
8162
  var AddLayerButton = function (props) {
8110
8163
  var _a = React__default["default"].useState(false), popupOpen = _a[0], setPopupOpen = _a[1];
8111
- var layerTypes = props.layerTypes || ['geojson', 'wms', 'mbtiles', 'csv', 'topojson', 'osm', 'gpx', 'kml', 'tcx'];
8112
- layerTypes.includes('mbtiles') && useAddProtocol({
8113
- protocol: 'mbtiles',
8114
- handler: mbTilesProtocolHandler,
8115
- });
8164
+ var layerTypes = props.layerTypes || [
8165
+ 'geojson',
8166
+ 'wms',
8167
+ 'mbtiles',
8168
+ 'csv',
8169
+ 'topojson',
8170
+ 'osm',
8171
+ 'gpx',
8172
+ 'kml',
8173
+ 'tcx',
8174
+ ];
8116
8175
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
8176
+ layerTypes.includes('mbtiles') && (React__default["default"].createElement(AddProtocol, __assign({}, {
8177
+ protocol: 'mbtiles',
8178
+ handler: mbTilesProtocolHandler,
8179
+ }))),
8117
8180
  React__default["default"].createElement(material.Button, { variant: "contained", sx: __assign({ marginTop: '10px' }, props.sx), onClick: function () { return setPopupOpen(true); } },
8118
8181
  React__default["default"].createElement(PlaylistAddIcon__default["default"], null)),
8119
8182
  React__default["default"].createElement(AddLayerPopup, { open: popupOpen, setOpen: setPopupOpen, onComplete: props === null || props === void 0 ? void 0 : props.onComplete, layerTypes: layerTypes })));