@mapcomponents/react-maplibre 0.1.23 → 0.1.27

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 (78) hide show
  1. package/CHANGELOG.md +54 -8
  2. package/coverage/clover.xml +90 -96
  3. package/coverage/coverage-final.json +6 -6
  4. package/coverage/lcov-report/index.html +25 -25
  5. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +1 -1
  6. package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
  7. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +1 -1
  8. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
  9. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.js.html +1 -1
  10. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
  11. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +1 -1
  12. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
  13. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +43 -94
  14. package/coverage/lcov-report/src/components/MlFollowGps/index.html +18 -18
  15. package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +1 -1
  16. package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
  17. package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
  18. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +1 -1
  19. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
  20. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +2 -2
  21. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
  22. package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +1 -1
  23. package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
  24. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +1 -1
  25. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
  26. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +1 -1
  27. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
  28. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +1 -1
  29. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
  30. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
  31. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
  32. package/coverage/lcov-report/src/components/MlMarker/MlMarker.js.html +1 -1
  33. package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
  34. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.js.html +1 -1
  35. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
  36. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +1 -1
  37. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
  38. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
  39. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
  40. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
  41. package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
  42. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
  43. package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
  44. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
  45. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
  46. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
  47. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
  48. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
  49. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
  50. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.js.html +7 -10
  51. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +10 -10
  52. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
  53. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
  54. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.js.html +1 -1
  55. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
  56. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.js.html +1 -1
  57. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
  58. package/coverage/lcov-report/src/hooks/index.html +6 -6
  59. package/coverage/lcov-report/src/hooks/useMap.js.html +15 -6
  60. package/coverage/lcov-report/src/hooks/useMapState.js.html +21 -12
  61. package/coverage/lcov-report/src/hooks/useWms.js.html +2 -2
  62. package/coverage/lcov-report/src/i18n.js.html +1 -1
  63. package/coverage/lcov-report/src/index.html +1 -1
  64. package/coverage/lcov-report/src/translations/english.js.html +1 -1
  65. package/coverage/lcov-report/src/translations/german.js.html +1 -1
  66. package/coverage/lcov-report/src/translations/index.html +1 -1
  67. package/coverage/lcov.info +154 -164
  68. package/dist/index.esm.js +97 -106
  69. package/dist/index.esm.js.map +1 -1
  70. package/package.json +1 -1
  71. package/src/components/MlFollowGps/MlFollowGps.js +29 -46
  72. package/src/components/MlFollowGps/MlFollowGps.test.js +1 -1
  73. package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +1 -2
  74. package/src/hooks/useMap.js +5 -2
  75. package/src/hooks/useMapState.js +3 -0
  76. package/src/hooks/useWms.js +1 -1
  77. package/dist/b556faa3bc6829d2.png +0 -0
  78. package/src/components/MlFollowGps/assets/marker.png +0 -0
package/dist/index.esm.js CHANGED
@@ -910,6 +910,7 @@ function useMapState(props) {
910
910
  useEffect(function () {
911
911
  var _componentId = componentId.current;
912
912
  return function () {
913
+ // cleanup all event listeners
913
914
  if (mapRef.current) {
914
915
  mapRef.current.cleanup(_componentId);
915
916
  mapRef.current = undefined;
@@ -928,7 +929,8 @@ function useMapState(props) {
928
929
  mapRef.current = mapContext.getMap(props.mapId);
929
930
 
930
931
  if (props !== null && props !== void 0 && (_props$watch = props.watch) !== null && _props$watch !== void 0 && _props$watch.viewport) {
931
- setViewport(mapRef.current.wrapper.viewportState);
932
+ setViewport(mapRef.current.wrapper.viewportState); // register viewportchange event handler
933
+
932
934
  mapRef.current.wrapper.on("viewportchange", function () {
933
935
  var _mapRef$current;
934
936
 
@@ -938,7 +940,8 @@ function useMapState(props) {
938
940
  setViewport((_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.wrapper.viewportState);
939
941
  }
940
942
  }, componentId.current);
941
- }
943
+ } // register layerchange event handler
944
+
942
945
 
943
946
  if (props !== null && props !== void 0 && (_props$watch2 = props.watch) !== null && _props$watch2 !== void 0 && _props$watch2.layers) {
944
947
  var _props$filter3, _props$filter4;
@@ -1001,15 +1004,18 @@ function useMap(props) {
1001
1004
  mapId: props.mapId,
1002
1005
  watch: {
1003
1006
  viewport: false,
1004
- layers: true,
1007
+ layers: props.waitForLayer ? true : false,
1005
1008
  sources: false
1009
+ },
1010
+ filter: {
1011
+ includeBaseLayers: true
1006
1012
  }
1007
1013
  });
1008
1014
  var initializedRef = useRef(false);
1009
1015
  var mapRef = useRef(undefined);
1010
1016
  var componentId = useRef(v4());
1011
1017
 
1012
- var _useState = useState(undefined),
1018
+ var _useState = useState(false),
1013
1019
  _useState2 = _slicedToArray(_useState, 2),
1014
1020
  mapIsReady = _useState2[0],
1015
1021
  setMapIsReady = _useState2[1];
@@ -1651,66 +1657,6 @@ MlGeoJsonLayer.propTypes = {
1651
1657
  transitionTime: PropTypes.number
1652
1658
  };
1653
1659
 
1654
- var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
1655
- var mapHook = useMap({
1656
- mapId: props.mapId,
1657
- waitForLayer: props.insertBeforeLayer
1658
- });
1659
- var layerInitializedRef = useRef(false);
1660
- var imageIdRef = useRef(props.imageId || "img_" + new Date().getTime());
1661
- var layerId = useRef(props.layerId || "MlImageMarkerLayer-" + mapHook.componentId);
1662
- useEffect(function () {
1663
- if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) return; // the MapLibre-gl instance (mapContext.map) is accessible here
1664
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1665
-
1666
- var key;
1667
-
1668
- if (props.options.layout) {
1669
- for (key in props.options.layout) {
1670
- mapHook.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
1671
- }
1672
- }
1673
-
1674
- if (props.options.paint) {
1675
- for (key in props.options.paint) {
1676
- mapHook.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
1677
- }
1678
- }
1679
- }, [props.options, layerId.current, props.mapId]);
1680
- var addLayer = useCallback(function () {
1681
- var tmpOptions = _objectSpread2({
1682
- id: layerId.current,
1683
- layout: {}
1684
- }, props.options);
1685
-
1686
- tmpOptions.layout["icon-image"] = imageIdRef.current;
1687
- mapHook.map.addLayer(tmpOptions, props.insertBeforeLayer, mapHook.componentId);
1688
- }, [props, mapHook.mapIsReady, mapHook.map]);
1689
- useEffect(function () {
1690
- if (!props.options || !mapHook.mapIsReady || layerInitializedRef.current) return;
1691
- layerInitializedRef.current = true;
1692
-
1693
- if (props.imgSrc) {
1694
- mapHook.map.loadImage(props.imgSrc, function (error, image) {
1695
- if (error) throw error;
1696
- mapHook.map.addImage(imageIdRef.current, image, mapHook.componentId);
1697
- });
1698
- }
1699
-
1700
- addLayer();
1701
- }, [mapHook.mapIsReady, mapHook.map, addLayer, props]);
1702
- useEffect(function () {
1703
- if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) {
1704
- return;
1705
- }
1706
-
1707
- mapHook.map.getSource(layerId.current).setData(props.options.source.data);
1708
- }, [props.options.source.data, props]);
1709
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
1710
- };
1711
-
1712
- var marker = "b556faa3bc6829d2.png";
1713
-
1714
1660
  /**
1715
1661
  * Adds a button that makes the map follow the users GPS position using
1716
1662
  * navigator.geolocation.watchPosition if activated
@@ -1737,8 +1683,6 @@ var MlFollowGps = function MlFollowGps(props) {
1737
1683
  geoJson = _useState4[0],
1738
1684
  setGeoJson = _useState4[1];
1739
1685
 
1740
- var watchIdRef = useRef(undefined);
1741
-
1742
1686
  var _useState5 = useState(false),
1743
1687
  _useState6 = _slicedToArray(_useState5, 2),
1744
1688
  locationAccessDenied = _useState6[0],
@@ -1749,17 +1693,14 @@ var MlFollowGps = function MlFollowGps(props) {
1749
1693
  accuracyGeoJson = _useState8[0],
1750
1694
  setAccuracyGeoJson = _useState8[1];
1751
1695
 
1752
- useEffect(function () {
1753
- return function () {
1754
- if (watchIdRef.current) {
1755
- navigator.geolocation.clearWatch(watchIdRef.current);
1756
- watchIdRef.current = undefined;
1757
- }
1758
- };
1759
- }, []);
1760
1696
  var getLocationSuccess = useCallback(function (pos) {
1761
1697
  if (!mapHook.map) return;
1762
- mapHook.map.setCenter([pos.coords.longitude, pos.coords.latitude]);
1698
+ mapHook.map.flyTo({
1699
+ center: [pos.coords.longitude, pos.coords.latitude],
1700
+ zoom: 18,
1701
+ speed: 1,
1702
+ curve: 1
1703
+ });
1763
1704
  var geoJsonPoint = point([pos.coords.longitude, pos.coords.latitude]);
1764
1705
  setGeoJson(geoJsonPoint);
1765
1706
  setAccuracyGeoJson(circle(geoJsonPoint, pos.coords.accuracy / 1000));
@@ -1774,33 +1715,31 @@ var MlFollowGps = function MlFollowGps(props) {
1774
1715
  if (!mapHook.map) return;
1775
1716
 
1776
1717
  if (isFollowed) {
1777
- watchIdRef.current = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
1778
- } else {
1779
- navigator.geolocation.clearWatch(watchIdRef.current);
1718
+ var _watchId = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
1719
+
1720
+ return function () {
1721
+ navigator.geolocation.clearWatch(_watchId);
1722
+ };
1780
1723
  }
1781
1724
  }, [isFollowed, getLocationSuccess]);
1782
1725
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
1783
1726
  geojson: accuracyGeoJson,
1784
1727
  type: "fill",
1785
1728
  paint: _objectSpread2({
1786
- "fill-color": "#ee7700",
1787
- "fill-opacity": 0.5
1729
+ "fill-color": "#cbd300",
1730
+ "fill-opacity": 0.3
1788
1731
  }, props.accuracyPaint),
1789
- insertBeforeLayer: "MlFollowGpsMarker"
1790
- }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlImageMarkerLayer, {
1791
- layerId: "MlFollowGpsMarker",
1792
- options: {
1793
- type: "symbol",
1794
- source: {
1795
- type: "geojson",
1796
- data: geoJson
1797
- },
1798
- layout: _objectSpread2({
1799
- "icon-size": 0.1,
1800
- "icon-offset": [0, -340]
1801
- }, props.markerLayout)
1802
- },
1803
- imgSrc: props.markerImage || marker
1732
+ insertBeforeLayer: props.insertBeforeLayer
1733
+ }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
1734
+ geojson: geoJson,
1735
+ type: "circle",
1736
+ paint: _objectSpread2({
1737
+ "circle-color": "#009ee0",
1738
+ "circle-radius": 5,
1739
+ "circle-stroke-color": "#fafaff",
1740
+ "circle-stroke-width": 1
1741
+ }, props.circlePaint),
1742
+ insertBeforeLayer: props.insertBeforeLayer
1804
1743
  }), /*#__PURE__*/React__default.createElement(Button, {
1805
1744
  sx: _objectSpread2({
1806
1745
  zIndex: 1002,
@@ -1865,16 +1804,11 @@ MlFollowGps.propTypes = {
1865
1804
  accuracyPaint: PropTypes.object,
1866
1805
 
1867
1806
  /**
1868
- * Marker layout property object, that is passed to the MlImageMarkerLayer responsible for drawing the position marker.
1869
- * Use any available layout property from layer type "symbol".
1870
- * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#symbol
1871
- */
1872
- markerLayout: PropTypes.object,
1873
-
1874
- /**
1875
- * Replace the default marker image with a custom one.
1807
+ * position circle paint property object, that is passed to the MlGeoJsonLayer responsible for drawing the accuracy circle.
1808
+ * Use any available paint prop from layer type "fill".
1809
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
1876
1810
  */
1877
- markerImage: PropTypes.string
1811
+ circlePaint: PropTypes.object
1878
1812
  };
1879
1813
 
1880
1814
  var nmMap = {
@@ -2064,6 +1998,64 @@ MlCreatePdfButton.propTypes = {
2064
1998
  mapId: PropTypes.string
2065
1999
  };
2066
2000
 
2001
+ var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
2002
+ var mapHook = useMap({
2003
+ mapId: props.mapId,
2004
+ waitForLayer: props.insertBeforeLayer
2005
+ });
2006
+ var layerInitializedRef = useRef(false);
2007
+ var imageIdRef = useRef(props.imageId || "img_" + new Date().getTime());
2008
+ var layerId = useRef(props.layerId || "MlImageMarkerLayer-" + mapHook.componentId);
2009
+ useEffect(function () {
2010
+ if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) return; // the MapLibre-gl instance (mapContext.map) is accessible here
2011
+ // initialize the layer and add it to the MapLibre-gl instance or do something else with it
2012
+
2013
+ var key;
2014
+
2015
+ if (props.options.layout) {
2016
+ for (key in props.options.layout) {
2017
+ mapHook.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
2018
+ }
2019
+ }
2020
+
2021
+ if (props.options.paint) {
2022
+ for (key in props.options.paint) {
2023
+ mapHook.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
2024
+ }
2025
+ }
2026
+ }, [props.options, layerId.current, props.mapId]);
2027
+ var addLayer = useCallback(function () {
2028
+ var tmpOptions = _objectSpread2({
2029
+ id: layerId.current,
2030
+ layout: {}
2031
+ }, props.options);
2032
+
2033
+ tmpOptions.layout["icon-image"] = imageIdRef.current;
2034
+ mapHook.map.addLayer(tmpOptions, props.insertBeforeLayer, mapHook.componentId);
2035
+ }, [props, mapHook.mapIsReady, mapHook.map]);
2036
+ useEffect(function () {
2037
+ if (!props.options || !mapHook.mapIsReady || layerInitializedRef.current) return;
2038
+ layerInitializedRef.current = true;
2039
+
2040
+ if (props.imgSrc) {
2041
+ mapHook.map.loadImage(props.imgSrc, function (error, image) {
2042
+ if (error) throw error;
2043
+ mapHook.map.addImage(imageIdRef.current, image, mapHook.componentId);
2044
+ });
2045
+ }
2046
+
2047
+ addLayer();
2048
+ }, [mapHook.mapIsReady, mapHook.map, addLayer, props]);
2049
+ useEffect(function () {
2050
+ if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) {
2051
+ return;
2052
+ }
2053
+
2054
+ mapHook.map.getSource(layerId.current).setData(props.options.source.data);
2055
+ }, [props.options.source.data, props]);
2056
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
2057
+ };
2058
+
2067
2059
  function _extends() { _extends = Object.assign || 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); }
2068
2060
 
2069
2061
  function SvgRotateRight(props) {
@@ -2696,7 +2688,7 @@ var MlVectorTileLayer = function MlVectorTileLayer(props) {
2696
2688
  if (!mapHook.map || initializedRef.current) return;
2697
2689
  initializedRef.current = true; // Add the new layer to the openlayers instance once it is available
2698
2690
 
2699
- mapHook.map.addSource(layerId, _objectSpread2({
2691
+ mapHook.map.addSource(layerId.current, _objectSpread2({
2700
2692
  type: "vector",
2701
2693
  tiles: [props.url],
2702
2694
  tileSize: 512,
@@ -2707,7 +2699,6 @@ var MlVectorTileLayer = function MlVectorTileLayer(props) {
2707
2699
  var _layerId = layerId.current + "_" + key;
2708
2700
 
2709
2701
  layerIdsRef.current[key] = _layerId;
2710
- console.log(_layerId);
2711
2702
  mapHook.map.addLayer(_objectSpread2({
2712
2703
  id: _layerId,
2713
2704
  source: layerId.current,