@mapcomponents/react-maplibre 1.0.9 → 1.0.11

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.cjs.js +125 -69
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.esm.js +125 -69
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/src/components/MlClientSearch/lib/createGeojsonFeature.d.ts +3 -2
  7. package/dist/src/components/MlCreatePdfButton/MlCreatePdfButton.d.ts +1 -1
  8. package/dist/src/components/MlCreatePdfForm/lib/PdfPreview.d.ts +1 -1
  9. package/dist/src/components/MlCreatePngButton/MlCreatePngButton.d.ts +1 -1
  10. package/dist/src/components/MlGeoJsonLayer/MlGeoJsonLayer.d.ts +2 -2
  11. package/dist/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.d.ts +2 -1
  12. package/dist/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.d.ts +3 -1
  13. package/dist/src/components/MlGpxViewer/MlGpxViewer.d.ts +1 -1
  14. package/dist/src/components/MlGpxViewer/util/GeoJsonContext.d.ts +3 -3
  15. package/dist/src/components/MlImageMarkerLayer/MlImageMarkerLayer.d.ts +1 -1
  16. package/dist/src/components/MlLayer/MlLayer.d.ts +1 -1
  17. package/dist/src/components/MlMeasureTool/MlMeasureTool.d.ts +8 -7
  18. package/dist/src/components/MlMultiMeasureTool/MlMultiMeasureTool.d.ts +3 -3
  19. package/dist/src/components/MlSketchTool/MlSketchTool.d.ts +1 -1
  20. package/dist/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.d.ts +1 -1
  21. package/dist/src/components/MlSpatialElevationProfile/util/getElevationData.d.ts +1 -1
  22. package/dist/src/components/MlTemporalController/MlTemporalController.d.ts +1 -1
  23. package/dist/src/components/MlTemporalController/utils/MlTemporalControllerLabels.d.ts +1 -1
  24. package/dist/src/components/MlTemporalController/utils/useFilterData.d.ts +2 -2
  25. package/dist/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.d.ts +2 -2
  26. package/dist/src/hooks/useExportMap/lib.d.ts +1 -1
  27. package/dist/src/hooks/useFeatureEditor/useFeatureEditor.d.ts +3 -3
  28. package/dist/src/hooks/useFeatureEditor/utils/FeatureEditorStyle.d.ts +44 -16
  29. package/dist/src/hooks/useGpx/useGpx.d.ts +2 -2
  30. package/dist/src/hooks/useLayer.d.ts +3 -3
  31. package/dist/src/hooks/useLayerHoverPopup/LayerHoverPopup.d.ts +2 -1
  32. package/dist/src/protocol_handlers/csv.d.ts +2 -2
  33. package/dist/src/protocol_handlers/osm.d.ts +2 -2
  34. package/dist/src/protocol_handlers/topojson.d.ts +2 -2
  35. package/dist/src/protocol_handlers/xml.d.ts +2 -2
  36. package/package.json +6 -4
  37. package/rollup.config.mjs +2 -1
package/dist/index.esm.js CHANGED
@@ -2007,9 +2007,9 @@ function featureEditorStyle() {
2007
2007
  ['!=', 'mode', 'static'],
2008
2008
  ],
2009
2009
  paint: {
2010
- 'fill-color': '#3bb2d0',
2011
- 'fill-outline-color': '#3bb2d0',
2012
- 'fill-opacity': 0.1,
2010
+ 'fill-color': '#009EE0',
2011
+ 'fill-outline-color': '#009EE0',
2012
+ 'fill-opacity': 0.3,
2013
2013
  },
2014
2014
  },
2015
2015
  {
@@ -2017,18 +2017,9 @@ function featureEditorStyle() {
2017
2017
  type: 'fill',
2018
2018
  filter: ['all', ['==', 'active', 'true'], ['==', '$type', 'Polygon']],
2019
2019
  paint: {
2020
- 'fill-color': '#fbb03b',
2021
- 'fill-outline-color': '#fbb03b',
2022
- 'fill-opacity': 0.1,
2023
- },
2024
- },
2025
- {
2026
- id: 'gl-draw-polygon-midpoint',
2027
- type: 'circle',
2028
- filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
2029
- paint: {
2030
- 'circle-radius': mediaIsMobile ? 7 : 5,
2031
- 'circle-color': '#fbb03b',
2020
+ 'fill-color': '#009EE0',
2021
+ 'fill-outline-color': '#009EE0',
2022
+ 'fill-opacity': 0.2,
2032
2023
  },
2033
2024
  },
2034
2025
  {
@@ -2045,8 +2036,8 @@ function featureEditorStyle() {
2045
2036
  'line-join': 'round',
2046
2037
  },
2047
2038
  paint: {
2048
- 'line-color': '#3bb2d0',
2049
- 'line-width': 2,
2039
+ 'line-color': '#009EE0',
2040
+ 'line-width': 3,
2050
2041
  },
2051
2042
  },
2052
2043
  {
@@ -2058,7 +2049,7 @@ function featureEditorStyle() {
2058
2049
  'line-join': 'round',
2059
2050
  },
2060
2051
  paint: {
2061
- 'line-color': '#fbb03b',
2052
+ 'line-color': '#009EE0',
2062
2053
  'line-dasharray': [0.2, 2],
2063
2054
  'line-width': 2,
2064
2055
  },
@@ -2077,8 +2068,8 @@ function featureEditorStyle() {
2077
2068
  'line-join': 'round',
2078
2069
  },
2079
2070
  paint: {
2080
- 'line-color': '#3bb2d0',
2081
- 'line-width': 2,
2071
+ 'line-color': '#009EE0',
2072
+ 'line-width': 3,
2082
2073
  },
2083
2074
  },
2084
2075
  {
@@ -2090,11 +2081,22 @@ function featureEditorStyle() {
2090
2081
  'line-join': 'round',
2091
2082
  },
2092
2083
  paint: {
2093
- 'line-color': '#fbb03b',
2084
+ 'line-color': "#009EE0",
2094
2085
  'line-dasharray': [0.2, 2],
2095
2086
  'line-width': 2,
2096
2087
  },
2097
2088
  },
2089
+ {
2090
+ id: 'gl-draw-polygon-midpoint',
2091
+ type: 'circle',
2092
+ filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
2093
+ paint: {
2094
+ 'circle-radius': mediaIsMobile ? 5 : 4,
2095
+ 'circle-color': '#ffffff',
2096
+ 'circle-stroke-color': '#009EE0',
2097
+ 'circle-stroke-width': 1
2098
+ },
2099
+ },
2098
2100
  {
2099
2101
  id: 'gl-draw-polygon-and-line-vertex-stroke-inactive',
2100
2102
  type: 'circle',
@@ -2110,7 +2112,9 @@ function featureEditorStyle() {
2110
2112
  filter: ['all', ['==', 'meta', 'vertex'], ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
2111
2113
  paint: {
2112
2114
  'circle-radius': mediaIsMobile ? 7 : 5,
2113
- 'circle-color': '#fbb03b',
2115
+ 'circle-color': '#ffffff',
2116
+ 'circle-stroke-color': '#009EE0',
2117
+ 'circle-stroke-width': 1
2114
2118
  },
2115
2119
  },
2116
2120
  {
@@ -2126,7 +2130,7 @@ function featureEditorStyle() {
2126
2130
  paint: {
2127
2131
  'circle-radius': mediaIsMobile ? 10 : 9,
2128
2132
  'circle-opacity': 1,
2129
- 'circle-color': '#fff',
2133
+ 'circle-color': '#009EE0',
2130
2134
  },
2131
2135
  },
2132
2136
  {
@@ -2141,7 +2145,7 @@ function featureEditorStyle() {
2141
2145
  ],
2142
2146
  paint: {
2143
2147
  'circle-radius': mediaIsMobile ? 7.5 : 6.5,
2144
- 'circle-color': '#3bb2d0',
2148
+ 'circle-color': '#009EE0',
2145
2149
  },
2146
2150
  },
2147
2151
  {
@@ -2169,7 +2173,7 @@ function featureEditorStyle() {
2169
2173
  ],
2170
2174
  paint: {
2171
2175
  'circle-radius': mediaIsMobile ? 8.5 : 7.5,
2172
- 'circle-color': '#fbb03b',
2176
+ 'circle-color': '#009EE0',
2173
2177
  },
2174
2178
  },
2175
2179
  {
@@ -2908,7 +2912,7 @@ var MlFollowGps = function (props) {
2908
2912
  ];
2909
2913
  var accurancyBounds = bbox(accuracyGeoJson);
2910
2914
  var contained = booleanContains(bboxPolygon(actualBounds), bboxPolygon(accurancyBounds));
2911
- if (contained === false) {
2915
+ if (!contained) {
2912
2916
  (_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.fitBounds(accurancyBounds, {
2913
2917
  padding: { top: 25, bottom: 25 },
2914
2918
  });
@@ -2987,46 +2991,93 @@ var MlImageMarkerLayer = function (props) {
2987
2991
  return React__default.createElement(React__default.Fragment, null);
2988
2992
  };
2989
2993
 
2990
- //const unitSquareConvert = {
2991
- // kilometers: 1,
2992
- // miles: 1 / 2.58998811,
2993
- //};
2994
- function getUnitSquareMultiplier(measureType) {
2995
- return measureType === 'miles' ? 1 / 2.58998811 : 1;
2994
+ function unitMultiplier(unit) {
2995
+ switch (unit) {
2996
+ case 'meters':
2997
+ return 1;
2998
+ case 'millimeters':
2999
+ return 1000;
3000
+ case 'centimeters':
3001
+ return 100;
3002
+ case 'kilometers':
3003
+ return 0.001;
3004
+ case 'miles':
3005
+ return 1 / 1609.344; // Meters in Miles
3006
+ case 'nauticalmiles':
3007
+ return 1 / 1852; // Meters in Nautical Miles
3008
+ case 'inches':
3009
+ return 39.3701; // Meters in Inches
3010
+ case 'yards':
3011
+ return 1.09361; // Meters in Yards
3012
+ case 'feet':
3013
+ return 3.28084; // Meters in Feet
3014
+ // case 'acres':
3015
+ // return 1 / 4046.8564224; // Square meters in an acre
3016
+ // case 'hectares':
3017
+ // return 1 / 10000; // Square meters in a hectare
3018
+ default:
3019
+ return 1;
3020
+ }
2996
3021
  }
2997
- function getUnitLabel(measureType) {
2998
- return measureType === 'miles' ? 'mi' : 'km';
3022
+ function unitLabel(unit) {
3023
+ switch (unit) {
3024
+ case 'miles':
3025
+ return 'mi';
3026
+ case 'acres':
3027
+ return 'ac';
3028
+ case 'kilometers':
3029
+ return 'km';
3030
+ case 'meters':
3031
+ return 'm';
3032
+ case 'millimeters':
3033
+ return 'mm';
3034
+ case 'centimeters':
3035
+ return 'cm';
3036
+ case 'nauticalmiles':
3037
+ return 'nm';
3038
+ case 'inches':
3039
+ return 'in';
3040
+ case 'yards':
3041
+ return 'yd';
3042
+ case 'feet':
3043
+ return 'ft';
3044
+ case 'hectares':
3045
+ return 'ha';
3046
+ default:
3047
+ return 'm';
3048
+ }
2999
3049
  }
3000
3050
  var MlMeasureTool = function (props) {
3001
3051
  var _a = useState({ value: 0, label: '' }), displayValue = _a[0], setDisplayValue = _a[1];
3002
3052
  var _b = useState([]), currentFeatures = _b[0], setCurrentFeatures = _b[1];
3003
3053
  useEffect(function () {
3004
3054
  if (currentFeatures[0]) {
3005
- var result = props.measureType === 'polygon'
3006
- ? // for "polyong" mode calculate km²
3007
- (turf.area(currentFeatures[0]) / 1000000) *
3008
- getUnitSquareMultiplier(props.unit)
3009
- : turf.length(currentFeatures[0], { units: props.unit });
3055
+ var result = 0;
3056
+ if (props.measureType === 'polygon') {
3057
+ // Calculate area in square meters
3058
+ result = turf.area(currentFeatures[0]);
3059
+ // Convert area depending on the unit (square meters -> selected area unit)
3060
+ if (props.unit) {
3061
+ var unit = props.unit;
3062
+ if (unit === 'acres') {
3063
+ result = result / 4046.8564224;
3064
+ }
3065
+ else if (unit === 'hectares') {
3066
+ result = result / 10000;
3067
+ }
3068
+ else {
3069
+ result = result * Math.pow(unitMultiplier(props.unit), 2);
3070
+ }
3071
+ }
3072
+ }
3073
+ else {
3074
+ result = turf.length(currentFeatures[0], { units: props.unit });
3075
+ }
3010
3076
  if (typeof props.onChange === 'function') {
3011
3077
  props.onChange({ value: result, unit: props.unit, geojson: currentFeatures[0] });
3012
3078
  }
3013
3079
  if (result >= 0.1) {
3014
- setDisplayValue({ value: result, label: getUnitLabel(props.unit) });
3015
- }
3016
- else {
3017
- var label = 'm';
3018
- var value = result * 1000;
3019
- if (props.measureType === 'polygon') {
3020
- value = result * 1000000;
3021
- }
3022
- if (getUnitLabel(props.unit) === 'mi') {
3023
- label = 'Yard';
3024
- value = result * 1760;
3025
- if (props.measureType === 'polygon') {
3026
- value = result * 3097600;
3027
- }
3028
- }
3029
- setDisplayValue({ value: value, label: label });
3080
+ setDisplayValue({ value: result, label: unitLabel(props.unit) });
3030
3081
  }
3031
3082
  }
3032
3083
  }, [props.unit, currentFeatures]);
@@ -3034,16 +3085,22 @@ var MlMeasureTool = function (props) {
3034
3085
  React__default.createElement(MlFeatureEditor, { onChange: function (features) {
3035
3086
  features && setCurrentFeatures(features);
3036
3087
  }, mode: props.measureType === 'polygon' ? 'draw_polygon' : 'draw_line_string', onFinish: props.onFinish }),
3037
- displayValue.value.toFixed(2),
3038
- " ",
3039
- '',
3040
- displayValue.label,
3041
- displayValue.label && props.measureType === 'polygon' ? ' ²' : ''));
3088
+ displayValue.value.toLocaleString('de-DE', {
3089
+ minimumFractionDigits: 2,
3090
+ maximumFractionDigits: 2,
3091
+ }),
3092
+ ' ',
3093
+ unitLabel(props.unit),
3094
+ displayValue.label &&
3095
+ props.measureType === 'polygon' &&
3096
+ !['hectares', 'acres'].includes(props.unit || '')
3097
+ ? ' ²'
3098
+ : ''));
3042
3099
  };
3043
3100
  MlMeasureTool.defaultProps = {
3044
3101
  mapId: undefined,
3045
3102
  measureType: 'line',
3046
- unit: 'kilometers',
3103
+ unit: 'meters',
3047
3104
  };
3048
3105
 
3049
3106
  var ListStyled$3 = styled(List)({
@@ -3600,7 +3657,6 @@ var MlMultiMeasureTool = function (props) {
3600
3657
  var _d = useState(), measureState = _d[0], setMeasureState = _d[1];
3601
3658
  var _e = useState('kilometers'), selectedUnit = _e[0], setSelectedUnit = _e[1];
3602
3659
  var _f = useState([]), measureList = _f[0], setMeasureList = _f[1];
3603
- console.log(measureList);
3604
3660
  var _g = useState(false), reload = _g[0], setReload = _g[1];
3605
3661
  var unitSwitch = function () {
3606
3662
  if (selectedUnit === 'kilometers') {
@@ -3949,7 +4005,7 @@ var MlNavigationTools = function (props) {
3949
4005
  var targetPitch = mapHook.map.getPitch() !== 0 ? 0 : 60;
3950
4006
  mapHook.map.easeTo({ pitch: targetPitch });
3951
4007
  }, [mapHook.map]);
3952
- return (React__default.createElement(Box$2, { sx: __assign(__assign({ zIndex: 501, position: 'absolute', display: 'flex', flexDirection: 'column', right: mediaIsMobile ? '15px' : '25px', bottom: mediaIsMobile ? '20px' : '30px' }, (mediaIsMobile ? { margin: '80px 10px 50px 10px' } : { marginTop: '50px' })), props.sx) },
4008
+ return (React__default.createElement(Box$2, { sx: __assign(__assign({ zIndex: 501, position: 'absolute', display: 'flex', flexDirection: 'column', right: mediaIsMobile ? '15px' : '25px', bottom: mediaIsMobile ? '20px' : '40px' }, (mediaIsMobile ? { margin: '80px 10px 50px 10px' } : { marginTop: '50px' })), props.sx) },
3953
4009
  React__default.createElement(MlNavigationCompass, null),
3954
4010
  props.show3DButton && (React__default.createElement(Button$1, { variant: "navtools", onClick: adjustPitch }, pitch < 29 ? '3D' : '2D')),
3955
4011
  props.showFollowGpsButton && React__default.createElement(MlFollowGps, null),
@@ -6194,13 +6250,13 @@ var MlWmsLoader = function (props) {
6194
6250
  var unprojected = mapHook.map.unproject([ev.point.x, ev.point.y]);
6195
6251
  var point = turf.point([unprojected.lng, unprojected.lat]);
6196
6252
  var buffered = turf.buffer(point, 50, { units: 'meters' });
6197
- var _bbox = turf.bbox(buffered);
6198
- var _sw = lngLatToMeters({ lng: _bbox[0], lat: _bbox[1] });
6199
- var _ne = lngLatToMeters({ lng: _bbox[2], lat: _bbox[3] });
6200
- var bbox = [_sw[0], _sw[1], _ne[0], _ne[1]];
6253
+ var _bbox = buffered && turf.bbox(buffered);
6254
+ var _sw = _bbox && lngLatToMeters({ lng: _bbox[0], lat: _bbox[1] });
6255
+ var _ne = _bbox && lngLatToMeters({ lng: _bbox[2], lat: _bbox[3] });
6256
+ var bbox = _sw && _ne && [_sw[0], _sw[1], _ne[0], _ne[1]];
6201
6257
  var _getFeatureInfoUrlParams = {
6202
6258
  REQUEST: 'GetFeatureInfo',
6203
- BBOX: bbox.join(','),
6259
+ BBOX: bbox === null || bbox === void 0 ? void 0 : bbox.join(','),
6204
6260
  SERVICE: 'WMS',
6205
6261
  INFO_FORMAT: ((_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _a === void 0 ? void 0 : _a.Request) === null || _b === void 0 ? void 0 : _b.GetFeatureInfo.Format.indexOf('text/html')) !== -1
6206
6262
  ? 'text/html'
@@ -7120,7 +7176,7 @@ var useCameraFollowPath = function (props) {
7120
7176
  var speed = useRef(props.speed);
7121
7177
  var timeoutId = useRef();
7122
7178
  var kmPerStep = props.kmPerStep || 0.01;
7123
- var routeDistance = turf.lineDistance(props.route);
7179
+ var routeDistance = turf.length(props.route);
7124
7180
  var stepDuration = props.stepDuration || 70;
7125
7181
  var mapHook = useMap({
7126
7182
  mapId: props.mapId,