@mapcomponents/react-maplibre 0.1.89 → 0.1.91

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,6 +1,18 @@
1
1
  # Change Log
2
2
 
3
- ## [v0.1.89] - 2024-01-02
3
+ ## [v0.1.91] - 2024-01-16
4
+
5
+ ### Fixed
6
+
7
+ - 4775728: remove mbtiles protocol handler from build to fix sql.js error
8
+
9
+ ## [v0.1.90] - 2024-01-16 (broken)
10
+
11
+ ### Fixed
12
+
13
+ - f40622f: fix build error suggesting marking sql.js as external
14
+
15
+ ## [v0.1.89] - 2024-01-02 (broken)
4
16
 
5
17
  ### Fixed
6
18
 
@@ -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
@@ -68,8 +68,6 @@ var csv2geojson = require('csv2geojson');
68
68
  var topojsonClient = require('topojson-client');
69
69
  var osm2geojson = require('osm2geojson-lite');
70
70
  var externParser = require('@tmcw/togeojson');
71
- var initSqlJs = require('sql.js');
72
- var pako = require('pako');
73
71
  var KeyboardArrowDownIcon = require('@mui/icons-material/KeyboardArrowDown');
74
72
  var KeyboardArrowUpIcon = require('@mui/icons-material/KeyboardArrowUp');
75
73
  var AppBar = require('@mui/material/AppBar');
@@ -161,8 +159,6 @@ var IndeterminateCheckBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(Inde
161
159
  var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
162
160
  var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
163
161
  var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
164
- var initSqlJs__default = /*#__PURE__*/_interopDefaultLegacy(initSqlJs);
165
- var pako__namespace = /*#__PURE__*/_interopNamespace(pako);
166
162
  var KeyboardArrowDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowDownIcon);
167
163
  var KeyboardArrowUpIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowUpIcon);
168
164
  var AppBar__default = /*#__PURE__*/_interopDefaultLegacy(AppBar);
@@ -2036,7 +2032,7 @@ function PdfForm(props) {
2036
2032
  ]);
2037
2033
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2038
2034
  React__default["default"].createElement(material.FormControl, { fullWidth: true, sx: formControlStyles },
2039
- React__default["default"].createElement(material.InputLabel, { id: "format-select-label" }, "Format"),
2035
+ React__default["default"].createElement(material.InputLabel, { sx: { marginTop: '3px' }, id: "format-select-label" }, "Format"),
2040
2036
  React__default["default"].createElement(material.Select, { labelId: "format-select-label", id: "format-select", label: "Format", value: pdfContext.format, onChange: function (event) {
2041
2037
  var _a;
2042
2038
  (_a = pdfContext.setFormat) === null || _a === void 0 ? void 0 : _a.call(pdfContext, event.target.value);
@@ -2319,7 +2315,6 @@ function featureEditorStyle() {
2319
2315
  * GeoJson Feature editor that allows to create or manipulate GeoJson data
2320
2316
  */
2321
2317
  var useFeatureEditor = function (props) {
2322
- console.log(featureEditorStyle());
2323
2318
  var draw = React.useRef();
2324
2319
  var mapHook = useMap({
2325
2320
  mapId: props.mapId,
@@ -2908,8 +2903,9 @@ var MlMeasureTool = function (props) {
2908
2903
  React.useEffect(function () {
2909
2904
  if (currentFeatures[0]) {
2910
2905
  var result = props.measureType === 'polygon'
2911
- // for "polyong" mode calculate km²
2912
- ? (turf__namespace.area(currentFeatures[0]) / 1000000) * getUnitSquareMultiplier(props.unit)
2906
+ ? // for "polyong" mode calculate km²
2907
+ (turf__namespace.area(currentFeatures[0]) / 1000000) *
2908
+ getUnitSquareMultiplier(props.unit)
2913
2909
  : turf__namespace.length(currentFeatures[0], { units: props.unit });
2914
2910
  if (typeof props.onChange === 'function') {
2915
2911
  props.onChange({ value: result, unit: props.unit, geojson: currentFeatures[0] });
@@ -2936,12 +2932,14 @@ var MlMeasureTool = function (props) {
2936
2932
  }, [props.unit, currentFeatures]);
2937
2933
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2938
2934
  React__default["default"].createElement(MlFeatureEditor, { onChange: function (features) {
2939
- setCurrentFeatures(features);
2940
- }, mode: props.measureType === 'polygon' ? 'draw_polygon' : 'draw_line_string' }),
2935
+ features && setCurrentFeatures(features);
2936
+ }, mode: props.measureType === 'polygon' ? 'draw_polygon' : 'draw_line_string', onFinish: props.onFinish }),
2941
2937
  displayValue.value.toFixed(2),
2942
2938
  " ",
2943
- displayValue.label,
2944
- props.measureType === 'polygon' ? '²' : ''));
2939
+ '',
2940
+ React__default["default"].createElement(material.Typography, null,
2941
+ displayValue.label,
2942
+ props.measureType === 'polygon' ? ' ²' : '')));
2945
2943
  };
2946
2944
  MlMeasureTool.defaultProps = {
2947
2945
  mapId: undefined,
@@ -2950,9 +2948,9 @@ MlMeasureTool.defaultProps = {
2950
2948
  };
2951
2949
 
2952
2950
  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); }
2951
+ 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
2952
  var SvgCompassNeedle = function SvgCompassNeedle(props) {
2955
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
2953
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$2({
2956
2954
  width: 10,
2957
2955
  height: 40,
2958
2956
  viewBox: "0 0 10 40",
@@ -2970,10 +2968,10 @@ var SvgCompassNeedle = function SvgCompassNeedle(props) {
2970
2968
  }))));
2971
2969
  };
2972
2970
 
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); }
2971
+ var _circle, _path$1, _path2$1, _path3, _path4;
2972
+ 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
2973
  var SvgCompassBackground = function SvgCompassBackground(props) {
2976
- return /*#__PURE__*/React__namespace.createElement("svg", _extends({
2974
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
2977
2975
  width: 52,
2978
2976
  height: 53,
2979
2977
  viewBox: "0 0 52 53",
@@ -2986,10 +2984,10 @@ var SvgCompassBackground = function SvgCompassBackground(props) {
2986
2984
  fill: "white",
2987
2985
  stroke: "#009EE0",
2988
2986
  strokeWidth: 2
2989
- })), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
2987
+ })), _path$1 || (_path$1 = /*#__PURE__*/React__namespace.createElement("path", {
2990
2988
  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
2989
  fill: "#009EE0"
2992
- })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
2990
+ })), _path2$1 || (_path2$1 = /*#__PURE__*/React__namespace.createElement("path", {
2993
2991
  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
2992
  fill: "#009EE0"
2995
2993
  })), _path3 || (_path3 = /*#__PURE__*/React__namespace.createElement("path", {
@@ -3423,6 +3421,22 @@ MlLayerMagnify.defaultProps = {
3423
3421
  magnifierStyle: {},
3424
3422
  };
3425
3423
 
3424
+ var _path, _path2;
3425
+ 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); }
3426
+ var SvgIcononlyarrow = function SvgIcononlyarrow(props) {
3427
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends({
3428
+ viewBox: "0 0 47 30",
3429
+ fill: "none",
3430
+ xmlns: "http://www.w3.org/2000/svg"
3431
+ }, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
3432
+ d: "M29.5 21.25L35.75 15L29.5 8.75V21.25Z",
3433
+ fill: "#009EE0"
3434
+ })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
3435
+ d: "M17.5 8.75L11.25 15L17.5 21.25V8.75Z",
3436
+ fill: "#009EE0"
3437
+ })));
3438
+ };
3439
+
3426
3440
  /**
3427
3441
  * creates a split view of 2 synchronised maplibre instances
3428
3442
  */
@@ -3492,7 +3506,10 @@ var MlLayerSwipe = function (props) {
3492
3506
  document.removeEventListener('mouseup', onMouseUp);
3493
3507
  };
3494
3508
  function adjustWindowSize() {
3495
- var clipWidth = mapContext.maps[props.map2Id].getContainer().style.clip.split(',')[1].replace('px', '');
3509
+ var clipWidth = mapContext.maps[props.map2Id]
3510
+ .getContainer()
3511
+ .style.clip.split(',')[1]
3512
+ .replace('px', '');
3496
3513
  var canvasWidth = mapContext.maps[props.map1Id].getCanvas().getBoundingClientRect().width;
3497
3514
  if (parseFloat(clipWidth) < canvasWidth) {
3498
3515
  var newPosition = parseFloat(((clipWidth / canvasWidth) * 100).toFixed(2));
@@ -3510,7 +3527,13 @@ var MlLayerSwipe = function (props) {
3510
3527
  window.removeEventListener('resize', adjustWindowSize);
3511
3528
  };
3512
3529
  }, [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 }));
3530
+ 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 },
3531
+ React__default["default"].createElement(SvgIcononlyarrow, { color: "#0066ff", style: {
3532
+ width: '65px',
3533
+ height: '65px',
3534
+ justifyContent: 'center',
3535
+ zIndex: 1100,
3536
+ } })));
3514
3537
  };
3515
3538
  MlLayerSwipe.defaultProps = {
3516
3539
  buttonStyle: {},
@@ -6438,6 +6461,8 @@ var PaperStyled = material.styled(material.Paper)({
6438
6461
  marginRight: '-21px',
6439
6462
  paddingLeft: '53px',
6440
6463
  borderRadius: '0px',
6464
+ boxShadow: 'none',
6465
+ backgroundColor: 'rgb(0, 0, 0, 0)',
6441
6466
  });
6442
6467
  var BoxStyled = material.styled(material.Box)({
6443
6468
  marginLeft: '61px',
@@ -6744,6 +6769,11 @@ var MlSketchTool = function (props) {
6744
6769
  geometries: [],
6745
6770
  drawMode: undefined,
6746
6771
  }), sketchState = _d[0], setSketchState = _d[1];
6772
+ React.useEffect(function () {
6773
+ if (!(typeof props.onChange === 'function'))
6774
+ return;
6775
+ props.onChange(sketchState);
6776
+ }, [sketchState, props.onChange]);
6747
6777
  var buttonStyle = __assign({}, props.buttonStyleOverride);
6748
6778
  var buttonClickHandler = function (buttonDrawMode) {
6749
6779
  setSketchState(function (_state) { return ({
@@ -6812,7 +6842,7 @@ var MlSketchTool = function (props) {
6812
6842
  }, onFinish: function () {
6813
6843
  setSketchState(function (_sketchState) { return (__assign(__assign({}, _sketchState), { drawMode: undefined, activeGeometryIndex: undefined, selectedGeoJson: undefined })); });
6814
6844
  } })),
6815
- React__default["default"].createElement(List__default["default"], { sx: { zIndex: 105 } },
6845
+ React__default["default"].createElement(List__default["default"], { sx: { zIndex: 105, marginBottom: '-10px' } },
6816
6846
  sketchState.geometries.map(function (el) { return (React__default["default"].createElement(React__default["default"].Fragment, null,
6817
6847
  React__default["default"].createElement(system.Box, { key: el.id, sx: { display: 'flex', flexDirection: 'column' } },
6818
6848
  React__default["default"].createElement("br", null),
@@ -6820,6 +6850,7 @@ var MlSketchTool = function (props) {
6820
6850
  '&:hover': {
6821
6851
  backgroundColor: 'rgb(177, 177, 177, 0.2)',
6822
6852
  },
6853
+ marginTop: '25px',
6823
6854
  }, onMouseOver: function () {
6824
6855
  setHoveredGeometry(el);
6825
6856
  }, onMouseLeave: function () {
@@ -6846,10 +6877,21 @@ var MlSketchTool = function (props) {
6846
6877
  setHoveredGeometry(undefined);
6847
6878
  } },
6848
6879
  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,
6880
+ hoveredGeometry && (React__default["default"].createElement(MlGeoJsonLayer, { mapId: props.mapId, geojson: { type: 'FeatureCollection', features: [hoveredGeometry] }, layerId: 'highlightBorder', defaultPaintOverrides: {
6881
+ circle: {
6882
+ 'circle-color': '#dd9900',
6883
+ 'circle-opacity': 0.4,
6884
+ 'circle-radius': 10,
6885
+ },
6886
+ line: {
6887
+ 'line-color': '#dd9900',
6888
+ 'line-opacity': 0.4,
6889
+ 'line-width': 10,
6890
+ },
6891
+ fill: {
6892
+ 'fill-color': '#dd9900',
6893
+ 'fill-opacity': 0.4
6894
+ },
6853
6895
  } }))),
6854
6896
  sketchState.drawMode === 'simple_select' && (React__default["default"].createElement(material.Typography, { sx: { fontSize: '0.6em' } },
6855
6897
  "Edit ", (_b = (_a = sketchState.selectedGeoJson) === null || _a === void 0 ? void 0 : _a.geometry) === null || _b === void 0 ? void 0 :
@@ -7731,128 +7773,6 @@ var XMLProtocolHandler = function (params, callback) {
7731
7773
  return { cancel: function () { } };
7732
7774
  };
7733
7775
 
7734
- var loadedMbtiles = {};
7735
- var parseTileParams = function (url) {
7736
- var urlParts = url.split('://');
7737
- var mbtilesUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
7738
- var mbtilesParts = mbtilesUrl.split('/');
7739
- var mbtilesPartsLength = mbtilesParts.length;
7740
- var y = mbtilesParts.splice(mbtilesPartsLength - 1, 1)[0];
7741
- var x = mbtilesParts.splice(mbtilesPartsLength - 2, 1)[0];
7742
- var z = mbtilesParts.splice(mbtilesPartsLength - 3, 1)[0];
7743
- var filename = mbtilesParts.join('/');
7744
- return {
7745
- filename: filename,
7746
- z: z,
7747
- x: x,
7748
- y: y,
7749
- };
7750
- };
7751
- // mbtiles files are sqlite databases. This function loads the database and returns a handler
7752
- // to work with sqlite databases in javascript we need to use sql.js.
7753
- // to make this work in your project make sure to copy sql-wasm.wasm to the file root of your public folder and
7754
- // add the following config to the externals prop of your webpack config
7755
- // {externals: { fs: 'fs' }};
7756
- var getMbtilesDbHandler = function (_a) {
7757
- var filename = _a.filename;
7758
- return __awaiter(void 0, void 0, void 0, function () {
7759
- var SQL, fetched, buf, db;
7760
- return __generator(this, function (_b) {
7761
- switch (_b.label) {
7762
- case 0:
7763
- if (!!loadedMbtiles[filename]) return [3 /*break*/, 4];
7764
- return [4 /*yield*/, initSqlJs__default["default"]()];
7765
- case 1:
7766
- SQL = _b.sent();
7767
- return [4 /*yield*/, fetch(filename)];
7768
- case 2:
7769
- fetched = _b.sent();
7770
- return [4 /*yield*/, fetched.arrayBuffer()];
7771
- case 3:
7772
- buf = _b.sent();
7773
- db = new SQL.Database(new Uint8Array(buf));
7774
- loadedMbtiles[filename] = db;
7775
- _b.label = 4;
7776
- case 4: return [2 /*return*/, loadedMbtiles[filename]];
7777
- }
7778
- });
7779
- });
7780
- };
7781
- /**
7782
- * Example usage:
7783
- * getBufferFromMbtiles({ filename: 'mbtiles/countries.mbtiles', z: '0', x: '0', y: '0' }).then(
7784
- * (result) => {
7785
- * console.log(result);
7786
- * }
7787
- * );
7788
- */
7789
- function getBufferFromMbtiles(params) {
7790
- return __awaiter(this, void 0, void 0, function () {
7791
- var db, query;
7792
- return __generator(this, function (_a) {
7793
- switch (_a.label) {
7794
- case 0: return [4 /*yield*/, getMbtilesDbHandler(params)];
7795
- case 1:
7796
- db = _a.sent();
7797
- query = 'SELECT tile_data FROM tiles WHERE zoom_level = ' +
7798
- params.z +
7799
- ' AND tile_column = ' +
7800
- params.x +
7801
- ' AND tile_row = ' +
7802
- (Math.pow(2, parseInt(params.z)) - parseInt(params.y) - 1);
7803
- return [2 /*return*/, new Promise(function (resolve, reject) {
7804
- try {
7805
- // some of the logic here was heavily inspired by
7806
- // https://github.com/IsraelHikingMap/Site/blob/6aa2ec0cfb8891fa048b1d9e2a4fc7d4cbcc8c97/IsraelHiking.Web/src/application/services/database.service.ts
7807
- var result = db.exec(query);
7808
- if (result.length !== 1) {
7809
- reject(new Error('Tile not found.'));
7810
- return;
7811
- }
7812
- var resultData = result[0].values[0][0];
7813
- var binData = void 0;
7814
- var isGzipped = resultData[0] === 0x1f && resultData[1] === 0x8b;
7815
- if (isGzipped) {
7816
- binData = pako__namespace.inflate(resultData);
7817
- }
7818
- else {
7819
- binData = resultData;
7820
- }
7821
- if (binData === null || binData === void 0 ? void 0 : binData.buffer) {
7822
- resolve(binData.buffer);
7823
- }
7824
- else {
7825
- reject(new Error('Tile not found.'));
7826
- return;
7827
- }
7828
- }
7829
- catch (error) {
7830
- reject(error);
7831
- }
7832
- })];
7833
- }
7834
- });
7835
- });
7836
- }
7837
- /**
7838
- * Expects a tile url in the following format:
7839
- *
7840
- * 'mbtiles://mbtiles/countries.mbtiles/{z}/{x}/{y}'
7841
- */
7842
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7843
- var mbTilesProtocolHandler = function (params, callback) {
7844
- var parsedParams = parseTileParams(params.url);
7845
- getBufferFromMbtiles(parsedParams).then(function (result) {
7846
- if (result) {
7847
- callback(null, result, null, null);
7848
- }
7849
- else {
7850
- callback(new Error('Tile not found'));
7851
- }
7852
- });
7853
- return { cancel: function () { } };
7854
- };
7855
-
7856
7776
  var handlers = {
7857
7777
  csv: CSVProtocolHandler,
7858
7778
  topojson: TopojsonProtocolHandler,
@@ -7860,7 +7780,7 @@ var handlers = {
7860
7780
  gpx: XMLProtocolHandler,
7861
7781
  kml: XMLProtocolHandler,
7862
7782
  tcx: XMLProtocolHandler,
7863
- mbtiles: mbTilesProtocolHandler
7783
+ //mbtiles: mbTilesProtocolHandler
7864
7784
  };
7865
7785
  var types = ['fill', 'line', 'circle'];
7866
7786
  function ProtocolHandlerLayerForm(props) {
@@ -8106,19 +8026,12 @@ var AddLayerPopup = function (props) {
8106
8026
  };
8107
8027
  AddLayerPopup.defaultProps = {};
8108
8028
 
8109
- function AddProtocol(props) {
8110
- useAddProtocol({
8111
- protocol: props.protocol,
8112
- handler: props.handler,
8113
- });
8114
- return React__default["default"].createElement(React__default["default"].Fragment, null);
8115
- }
8116
8029
  var AddLayerButton = function (props) {
8117
8030
  var _a = React__default["default"].useState(false), popupOpen = _a[0], setPopupOpen = _a[1];
8118
8031
  var layerTypes = props.layerTypes || [
8119
8032
  'geojson',
8120
8033
  'wms',
8121
- 'mbtiles',
8034
+ //'mbtiles',
8122
8035
  'csv',
8123
8036
  'topojson',
8124
8037
  'osm',
@@ -8127,10 +8040,6 @@ var AddLayerButton = function (props) {
8127
8040
  'tcx',
8128
8041
  ];
8129
8042
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
8130
- layerTypes.includes('mbtiles') && (React__default["default"].createElement(AddProtocol, __assign({}, {
8131
- protocol: 'mbtiles',
8132
- handler: mbTilesProtocolHandler,
8133
- }))),
8134
8043
  React__default["default"].createElement(material.Button, { variant: "contained", sx: __assign({ marginTop: '10px' }, props.sx), onClick: function () { return setPopupOpen(true); } },
8135
8044
  React__default["default"].createElement(PlaylistAddIcon__default["default"], null)),
8136
8045
  React__default["default"].createElement(AddLayerPopup, { open: popupOpen, setOpen: setPopupOpen, onComplete: props === null || props === void 0 ? void 0 : props.onComplete, layerTypes: layerTypes })));