@mapcomponents/react-maplibre 0.1.13 → 0.1.14

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 (68) hide show
  1. package/coverage/clover.xml +2 -2
  2. package/coverage/lcov-report/index.html +1 -1
  3. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +1 -1
  4. package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
  5. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +1 -1
  6. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
  7. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.js.html +1 -1
  8. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
  9. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +1 -1
  10. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
  11. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +1 -1
  12. package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
  13. package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +1 -1
  14. package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
  15. package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
  16. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +1 -1
  17. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
  18. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +1 -1
  19. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
  20. package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +1 -1
  21. package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
  22. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +1 -1
  23. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
  24. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +1 -1
  25. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
  26. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +1 -1
  27. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
  28. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
  29. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
  30. package/coverage/lcov-report/src/components/MlMarker/MlMarker.js.html +1 -1
  31. package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
  32. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.js.html +1 -1
  33. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
  34. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +1 -1
  35. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
  36. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
  37. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
  38. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
  39. package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
  40. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
  41. package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
  42. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
  43. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
  44. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
  45. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
  46. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
  47. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
  48. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.js.html +1 -1
  49. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
  50. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
  51. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
  52. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.js.html +1 -1
  53. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
  54. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.js.html +1 -1
  55. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
  56. package/coverage/lcov-report/src/hooks/index.html +1 -1
  57. package/coverage/lcov-report/src/hooks/useMap.js.html +1 -1
  58. package/coverage/lcov-report/src/hooks/useMapState.js.html +1 -1
  59. package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
  60. package/coverage/lcov-report/src/i18n.js.html +1 -1
  61. package/coverage/lcov-report/src/index.html +1 -1
  62. package/coverage/lcov-report/src/translations/english.js.html +1 -1
  63. package/coverage/lcov-report/src/translations/german.js.html +1 -1
  64. package/coverage/lcov-report/src/translations/index.html +1 -1
  65. package/dist/index.esm.js +137 -2
  66. package/dist/index.esm.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/index.js +1 -0
@@ -565,7 +565,7 @@ export default useMapState;
565
565
  <div class='footer quiet pad2 space-top1 center small'>
566
566
  Code coverage generated by
567
567
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
568
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
568
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
569
569
  </div>
570
570
  </div>
571
571
  <script src="../../prettify.js"></script>
@@ -355,7 +355,7 @@ export default useWms;</pre></td></tr></table></pre>
355
355
  <div class='footer quiet pad2 space-top1 center small'>
356
356
  Code coverage generated by
357
357
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
358
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
358
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
359
359
  </div>
360
360
  </div>
361
361
  <script src="../../prettify.js"></script>
@@ -151,7 +151,7 @@ export default i18n;</pre></td></tr></table></pre>
151
151
  <div class='footer quiet pad2 space-top1 center small'>
152
152
  Code coverage generated by
153
153
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
154
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
154
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
155
155
  </div>
156
156
  </div>
157
157
  <script src="../prettify.js"></script>
@@ -101,7 +101,7 @@
101
101
  <div class='footer quiet pad2 space-top1 center small'>
102
102
  Code coverage generated by
103
103
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
104
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
104
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
105
105
  </div>
106
106
  </div>
107
107
  <script src="../prettify.js"></script>
@@ -79,7 +79,7 @@ export default english;</pre></td></tr></table></pre>
79
79
  <div class='footer quiet pad2 space-top1 center small'>
80
80
  Code coverage generated by
81
81
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
82
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
82
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
83
83
  </div>
84
84
  </div>
85
85
  <script src="../../prettify.js"></script>
@@ -79,7 +79,7 @@ export default german;</pre></td></tr></table></pre>
79
79
  <div class='footer quiet pad2 space-top1 center small'>
80
80
  Code coverage generated by
81
81
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
82
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
82
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
83
83
  </div>
84
84
  </div>
85
85
  <script src="../../prettify.js"></script>
@@ -116,7 +116,7 @@
116
116
  <div class='footer quiet pad2 space-top1 center small'>
117
117
  Code coverage generated by
118
118
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener">istanbul</a>
119
- at Wed Dec 15 2021 17:14:00 GMT+0000 (Coordinated Universal Time)
119
+ at Wed Dec 15 2021 17:41:09 GMT+0000 (Coordinated Universal Time)
120
120
  </div>
121
121
  </div>
122
122
  <script src="../../prettify.js"></script>
package/dist/index.esm.js CHANGED
@@ -8,7 +8,7 @@ import Button from '@mui/material/Button';
8
8
  import maplibregl$1, { Popup } from 'maplibre-gl';
9
9
  import jsPDF from 'jspdf';
10
10
  import PrinterIcon from '@mui/icons-material/Print';
11
- import { lineString, length, lineChunk, point, bbox } from '@turf/turf';
11
+ import { lineString, length, lineChunk, point, bbox, lineOffset, distance } from '@turf/turf';
12
12
  import ButtonGroup from '@mui/material/ButtonGroup';
13
13
  import ControlPointIcon from '@mui/icons-material/ControlPoint';
14
14
  import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
@@ -31,6 +31,7 @@ import FileCopy from '@mui/icons-material/FileCopy';
31
31
  import List from '@mui/material/List';
32
32
  import ListItem from '@mui/material/ListItem';
33
33
  import ListItemText from '@mui/material/ListItemText';
34
+ import { lineString as lineString$1, polygon } from '@turf/helpers';
34
35
 
35
36
  function ownKeys(object, enumerableOnly) {
36
37
  var keys = Object.keys(object);
@@ -5396,6 +5397,140 @@ GeoJsonProvider.propTypes = {
5396
5397
  children: PropTypes.node.isRequired
5397
5398
  };
5398
5399
 
5400
+ /**
5401
+ * MlSpatialElevationProfile returns a Button that will add a standard OSM tile layer to the maplibre-gl instance.
5402
+ *
5403
+ * @component
5404
+ */
5405
+
5406
+ var MlSpatialElevationProfile = function MlSpatialElevationProfile(props) {
5407
+ var mapContext = useContext(MapContext);
5408
+ var componentId = useRef((props.idPrefix ? props.idPrefix : "MlSpatialElevationProfile-") + v4());
5409
+ var mapRef = useRef(null);
5410
+ var initializedRef = useRef(false);
5411
+ var dataSource = useContext(GeoJsonContext);
5412
+ var sourceName = useRef("elevationprofile-" + v4());
5413
+ var layerName = useRef("elevationprofile-layer-" + v4());
5414
+ var createStep = useCallback(function (x, y, z, x2, y2) {
5415
+ //const summand = 0.0002;
5416
+ var line = lineString$1([[x, y], [x2, y2]]);
5417
+ var offsetLine = lineOffset(line, 5, {
5418
+ units: "meters"
5419
+ });
5420
+ var x3 = offsetLine.geometry.coordinates[0][0];
5421
+ var y3 = offsetLine.geometry.coordinates[0][1];
5422
+ var x4 = offsetLine.geometry.coordinates[1][0];
5423
+ var y4 = offsetLine.geometry.coordinates[1][1];
5424
+ return polygon([[[x, y], [x2, y2], [x4, y4], [x3, y3], [x, y]]], {
5425
+ height: z * props.elevationFactor
5426
+ });
5427
+ }, [props.elevationFactor]);
5428
+ useEffect(function () {
5429
+ var _componentId = componentId.current;
5430
+ return function () {
5431
+ // This is the cleanup function, it is called when this react component is removed from react-dom
5432
+ if (mapRef.current) {
5433
+ mapRef.current.cleanup(_componentId);
5434
+ mapRef.current = null;
5435
+ }
5436
+ };
5437
+ }, []);
5438
+ useEffect(function () {
5439
+ if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
5440
+ initializedRef.current = true;
5441
+ mapRef.current = mapContext.getMap(props.mapId);
5442
+ mapRef.current.addSource(sourceName.current, {
5443
+ type: "geojson",
5444
+ data: dataSource.data
5445
+ }, componentId.current);
5446
+ mapRef.current.addLayer({
5447
+ id: layerName.current,
5448
+ source: sourceName.current,
5449
+ type: "fill-extrusion",
5450
+ paint: {
5451
+ "fill-extrusion-height": ["get", "height"],
5452
+ "fill-extrusion-opacity": 0.9,
5453
+ "fill-extrusion-color": ["interpolate", ["linear"], ["get", "height"], 0, "rgba(0, 0, 255, 0)", 0.1, "royalblue", 0.3, "cyan", 0.5, "lime", 0.7, "yellow", 1, "yellow"]
5454
+ }
5455
+ }, props.insertBeforeLayer, componentId.current);
5456
+ }, [mapContext.mapIds, props.insertBeforeLayer, props.mapId, dataSource, mapContext]);
5457
+ useEffect(function () {
5458
+ var _mapRef$current$getSo;
5459
+
5460
+ if (!mapRef.current || !mapRef.current.getLayer(layerName.current)) return;
5461
+ var data = dataSource.data;
5462
+ if (!data || !data.features) return;
5463
+ var line = data.features.find(function (element) {
5464
+ return element.geometry.type === "LineString";
5465
+ });
5466
+ if (!line || !line.geometry) return;
5467
+ var heights = line.geometry.coordinates.map(function (coordinate, index) {
5468
+ return coordinate[2];
5469
+ });
5470
+ var min = Math.min.apply(Math, _toConsumableArray(heights));
5471
+ var max = Math.max.apply(Math, _toConsumableArray(heights)) - min;
5472
+ max = max === 0 ? 1 : max;
5473
+ mapRef.current.setPaintProperty(layerName.current, "fill-extrusion-color", ["interpolate", ["linear"], ["get", "height"], 0, "rgb(0,255,55)", max * props.elevationFactor, "rgb(255,0,0)"]);
5474
+
5475
+ var lerp = function lerp(x, y, a) {
5476
+ return x * (1 - a) + y * a;
5477
+ };
5478
+
5479
+ var points = [];
5480
+ line.geometry.coordinates.forEach(function (coordinate, index) {
5481
+ //const point = createPoint(coordinate[0],coordinate[1],coordinate[2]-min);
5482
+ //points.push(point);
5483
+ if (line.geometry.coordinates[index + 1]) {
5484
+ var wayLength = distance([coordinate[0], coordinate[1]], [line.geometry.coordinates[index + 1][0], line.geometry.coordinates[index + 1][1]], {
5485
+ units: "kilometers"
5486
+ });
5487
+ var listLength = ~~(wayLength * 1000 / 10);
5488
+ listLength = listLength < 1 ? 1 : listLength;
5489
+
5490
+ for (var i = 0; i < listLength; i++) {
5491
+ var x = lerp(line.geometry.coordinates[index][0], line.geometry.coordinates[index + 1][0], i / listLength);
5492
+ var y = lerp(line.geometry.coordinates[index][1], line.geometry.coordinates[index + 1][1], i / listLength);
5493
+ var z = lerp(line.geometry.coordinates[index][2] - min, line.geometry.coordinates[index + 1][2] - min, i / listLength);
5494
+ var x2 = lerp(line.geometry.coordinates[index][0], line.geometry.coordinates[index + 1][0], (i + 1) / listLength);
5495
+ var y2 = lerp(line.geometry.coordinates[index][1], line.geometry.coordinates[index + 1][1], (i + 1) / listLength);
5496
+ var point = createStep(x, y, z, x2, y2);
5497
+ points.push(point);
5498
+ }
5499
+ }
5500
+ });
5501
+ var newData = dataSource.getEmptyFeatureCollection();
5502
+ newData.features = points;
5503
+ (_mapRef$current$getSo = mapRef.current.getSource(sourceName.current)) === null || _mapRef$current$getSo === void 0 ? void 0 : _mapRef$current$getSo.setData(newData);
5504
+ }, [dataSource.data, createStep, dataSource, props.elevationFactor, mapContext]);
5505
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
5506
+ };
5507
+
5508
+ MlSpatialElevationProfile.defaultProps = {
5509
+ elevationFactor: 1
5510
+ };
5511
+ MlSpatialElevationProfile.propTypes = {
5512
+ /**
5513
+ * Id of the target MapLibre instance in mapContext
5514
+ */
5515
+ mapId: PropTypes.string,
5516
+
5517
+ /**
5518
+ * Prefix of the component id this component uses when adding elements to the MapLibreGl-instance
5519
+ */
5520
+ idPrefix: PropTypes.string,
5521
+
5522
+ /**
5523
+ * Number describes the factor of the height of the elevation
5524
+ */
5525
+ elevationFactor: PropTypes.number,
5526
+
5527
+ /**
5528
+ * The layerId of an existing layer this layer should be rendered visually beneath
5529
+ * https://maplibre.org/maplibre-gl-js-docs/api/map/#map#addlayer - see "beforeId" property
5530
+ */
5531
+ insertBeforeLayer: PropTypes.string
5532
+ };
5533
+
5399
5534
  /**
5400
5535
  * React hook that allows subscribing to map state changes
5401
5536
  *
@@ -5557,5 +5692,5 @@ useMapState.propTypes = {
5557
5692
  })
5558
5693
  };
5559
5694
 
5560
- export { GeoJsonContext, GeoJsonProvider, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlFeatureEditor, MlFillExtrusionLayer, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlNavigationCompass, MlNavigationTools, MlOsmLayer, MlVectorTileLayer, MlWmsLayer, useMapState };
5695
+ export { GeoJsonContext, GeoJsonProvider, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlFeatureEditor, MlFillExtrusionLayer, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlNavigationCompass, MlNavigationTools, MlOsmLayer, MlSpatialElevationProfile, MlVectorTileLayer, MlWmsLayer, useMapState };
5561
5696
  //# sourceMappingURL=index.esm.js.map