@mapcomponents/react-maplibre 0.1.21 → 0.1.25

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 (74) hide show
  1. package/coverage/clover.xml +113 -135
  2. package/coverage/coverage-final.json +4 -4
  3. package/coverage/lcov-report/index.html +33 -33
  4. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.js.html +1 -1
  5. package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
  6. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.js.html +1 -1
  7. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
  8. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.js.html +1 -1
  9. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
  10. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +1 -1
  11. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
  12. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.js.html +30 -93
  13. package/coverage/lcov-report/src/components/MlFollowGps/index.html +18 -18
  14. package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.js.html +1 -1
  15. package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
  16. package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
  17. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js.html +1 -1
  18. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
  19. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html +1 -1
  20. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
  21. package/coverage/lcov-report/src/components/MlLayer/MlLayer.js.html +1 -1
  22. package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
  23. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.js.html +1 -1
  24. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
  25. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.js.html +1 -1
  26. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
  27. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +1 -1
  28. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
  29. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
  30. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
  31. package/coverage/lcov-report/src/components/MlMarker/MlMarker.js.html +1 -1
  32. package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
  33. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.js.html +1 -1
  34. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
  35. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.js.html +1 -1
  36. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
  37. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
  38. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
  39. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
  40. package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
  41. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
  42. package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
  43. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
  44. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
  45. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
  46. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
  47. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
  48. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
  49. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.js.html +88 -154
  50. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +17 -17
  51. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
  52. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
  53. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.js.html +1 -1
  54. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
  55. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.js.html +1 -1
  56. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
  57. package/coverage/lcov-report/src/hooks/index.html +12 -12
  58. package/coverage/lcov-report/src/hooks/useMap.js.html +29 -41
  59. package/coverage/lcov-report/src/hooks/useMapState.js.html +34 -34
  60. package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
  61. package/coverage/lcov-report/src/i18n.js.html +1 -1
  62. package/coverage/lcov-report/src/index.html +1 -1
  63. package/coverage/lcov-report/src/translations/english.js.html +1 -1
  64. package/coverage/lcov-report/src/translations/german.js.html +1 -1
  65. package/coverage/lcov-report/src/translations/index.html +1 -1
  66. package/coverage/lcov.info +191 -233
  67. package/dist/index.esm.js +53 -104
  68. package/dist/index.esm.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/components/MlFollowGps/MlFollowGps.js +18 -39
  71. package/src/components/MlFollowGps/MlFollowGps.test.js +1 -1
  72. package/src/components/MlVectorTileLayer/MlVectorTileLayer.js +64 -86
  73. package/src/components/MlVectorTileLayer/MlVectorTileLayer.test.js +6 -6
  74. package/src/hooks/useMap.js +1 -5
package/dist/index.esm.js CHANGED
@@ -1016,12 +1016,7 @@ function useMap(props) {
1016
1016
 
1017
1017
  useEffect(function () {
1018
1018
  var _componentId = componentId.current;
1019
- console.log("initialize maphook");
1020
1019
  return function () {
1021
- console.log("cleanup maphook");
1022
- console.log(_typeof(mapRef.current));
1023
- console.log(JSON.stringify(mapRef.current.style._order));
1024
-
1025
1020
  if (mapRef.current) {
1026
1021
  mapRef.current.cleanup(_componentId);
1027
1022
  mapRef.current = undefined;
@@ -1714,8 +1709,6 @@ var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
1714
1709
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
1715
1710
  };
1716
1711
 
1717
- var marker = "b556faa3bc6829d2.png";
1718
-
1719
1712
  /**
1720
1713
  * Adds a button that makes the map follow the users GPS position using
1721
1714
  * navigator.geolocation.watchPosition if activated
@@ -1742,8 +1735,6 @@ var MlFollowGps = function MlFollowGps(props) {
1742
1735
  geoJson = _useState4[0],
1743
1736
  setGeoJson = _useState4[1];
1744
1737
 
1745
- var watchIdRef = useRef(undefined);
1746
-
1747
1738
  var _useState5 = useState(false),
1748
1739
  _useState6 = _slicedToArray(_useState5, 2),
1749
1740
  locationAccessDenied = _useState6[0],
@@ -1754,14 +1745,6 @@ var MlFollowGps = function MlFollowGps(props) {
1754
1745
  accuracyGeoJson = _useState8[0],
1755
1746
  setAccuracyGeoJson = _useState8[1];
1756
1747
 
1757
- useEffect(function () {
1758
- return function () {
1759
- if (watchIdRef.current) {
1760
- navigator.geolocation.clearWatch(watchIdRef.current);
1761
- watchIdRef.current = undefined;
1762
- }
1763
- };
1764
- }, []);
1765
1748
  var getLocationSuccess = useCallback(function (pos) {
1766
1749
  if (!mapHook.map) return;
1767
1750
  mapHook.map.setCenter([pos.coords.longitude, pos.coords.latitude]);
@@ -1779,9 +1762,11 @@ var MlFollowGps = function MlFollowGps(props) {
1779
1762
  if (!mapHook.map) return;
1780
1763
 
1781
1764
  if (isFollowed) {
1782
- watchIdRef.current = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
1783
- } else {
1784
- navigator.geolocation.clearWatch(watchIdRef.current);
1765
+ var _watchId = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
1766
+
1767
+ return function () {
1768
+ navigator.geolocation.clearWatch(_watchId);
1769
+ };
1785
1770
  }
1786
1771
  }, [isFollowed, getLocationSuccess]);
1787
1772
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
@@ -1791,21 +1776,15 @@ var MlFollowGps = function MlFollowGps(props) {
1791
1776
  "fill-color": "#ee7700",
1792
1777
  "fill-opacity": 0.5
1793
1778
  }, props.accuracyPaint),
1794
- insertBeforeLayer: "MlFollowGpsMarker"
1795
- }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlImageMarkerLayer, {
1796
- layerId: "MlFollowGpsMarker",
1797
- options: {
1798
- type: "symbol",
1799
- source: {
1800
- type: "geojson",
1801
- data: geoJson
1802
- },
1803
- layout: _objectSpread2({
1804
- "icon-size": 0.1,
1805
- "icon-offset": [0, -340]
1806
- }, props.markerLayout)
1807
- },
1808
- imgSrc: props.markerImage || marker
1779
+ insertBeforeLayer: props.insertBeforeLayer
1780
+ }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
1781
+ geojson: geoJson,
1782
+ type: "circle",
1783
+ paint: _objectSpread2({
1784
+ "circle-color": "#ee9900",
1785
+ "circle-radius": 5
1786
+ }, props.circlePaint),
1787
+ insertBeforeLayer: props.insertBeforeLayer
1809
1788
  }), /*#__PURE__*/React__default.createElement(Button, {
1810
1789
  sx: _objectSpread2({
1811
1790
  zIndex: 1002,
@@ -1870,16 +1849,11 @@ MlFollowGps.propTypes = {
1870
1849
  accuracyPaint: PropTypes.object,
1871
1850
 
1872
1851
  /**
1873
- * Marker layout property object, that is passed to the MlImageMarkerLayer responsible for drawing the position marker.
1874
- * Use any available layout property from layer type "symbol".
1875
- * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#symbol
1876
- */
1877
- markerLayout: PropTypes.object,
1878
-
1879
- /**
1880
- * Replace the default marker image with a custom one.
1852
+ * position circle paint property object, that is passed to the MlGeoJsonLayer responsible for drawing the accuracy circle.
1853
+ * Use any available paint prop from layer type "fill".
1854
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
1881
1855
  */
1882
- markerImage: PropTypes.string
1856
+ circlePaint: PropTypes.object
1883
1857
  };
1884
1858
 
1885
1859
  var nmMap = {
@@ -2688,50 +2662,33 @@ MlOsmLayer.propTypes = {
2688
2662
  */
2689
2663
 
2690
2664
  var MlVectorTileLayer = function MlVectorTileLayer(props) {
2691
- var mapContext = useContext(MapContext);
2692
- var layerName = "vector-tile-layer-";
2693
- var sourceName = "vector-tile-source-";
2694
- var idSuffixRef = useRef(new Date().getTime());
2665
+ var mapHook = useMap({
2666
+ mapId: props.mapId,
2667
+ waitForLayer: props.insertBeforeLayer
2668
+ });
2695
2669
  var layerIdsRef = useRef({});
2670
+ var layerId = useRef(props.layerId || "MlVectorTileLayer-" + mapHook.componentId);
2696
2671
  var layerPaintConfsRef = useRef({});
2672
+ var layerLayoutConfsRef = useRef({});
2697
2673
  var initializedRef = useRef(false);
2698
- var mapRef = useRef(null);
2699
-
2700
- var cleanup = function cleanup() {
2701
- if (mapRef.current && mapRef.current.style) {
2702
- for (var key in layerIdsRef.current) {
2703
- if (mapRef.current.getLayer(layerIdsRef.current[key])) {
2704
- mapRef.current.removeLayer(layerIdsRef.current[key]);
2705
- }
2706
- }
2707
-
2708
- if (mapRef.current.getSource(sourceName + idSuffixRef.current)) {
2709
- mapRef.current.removeSource(sourceName + idSuffixRef.current);
2710
- }
2711
- }
2712
- };
2713
-
2714
- useEffect(function () {
2715
- return cleanup;
2716
- }, []);
2717
2674
  useEffect(function () {
2718
- if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
2719
- initializedRef.current = true;
2720
- mapRef.current = mapContext.getMap(props.mapId); // Add the new layer to the openlayers instance once it is available
2675
+ if (!mapHook.map || initializedRef.current) return;
2676
+ initializedRef.current = true; // Add the new layer to the openlayers instance once it is available
2721
2677
 
2722
- mapRef.current.addSource(sourceName + idSuffixRef.current, _objectSpread2({
2678
+ mapHook.map.addSource(layerId.current, _objectSpread2({
2723
2679
  type: "vector",
2724
2680
  tiles: [props.url],
2725
2681
  tileSize: 512,
2726
2682
  attribution: ""
2727
- }, props.sourceOptions));
2683
+ }, props.sourceOptions), mapHook.componentId);
2728
2684
 
2729
2685
  for (var key in props.layers) {
2730
- var layerId = layerName + "_" + key + "_" + idSuffixRef.current;
2731
- layerIdsRef.current[key] = layerId;
2732
- mapRef.current.addLayer(_objectSpread2({
2733
- id: layerId,
2734
- source: sourceName + idSuffixRef.current,
2686
+ var _layerId = layerId.current + "_" + key;
2687
+
2688
+ layerIdsRef.current[key] = _layerId;
2689
+ mapHook.map.addLayer(_objectSpread2({
2690
+ id: _layerId,
2691
+ source: layerId.current,
2735
2692
  type: "line",
2736
2693
  minzoom: 0,
2737
2694
  maxzoom: 22,
@@ -2741,42 +2698,39 @@ var MlVectorTileLayer = function MlVectorTileLayer(props) {
2741
2698
  "line-color": "rgb(80, 80, 80)",
2742
2699
  "line-width": 2
2743
2700
  }
2744
- }, props.layers[key]));
2701
+ }, props.layers[key]), props.insertBeforeLayer, mapHook.componentId);
2745
2702
  layerPaintConfsRef.current[key] = JSON.stringify(props.layers[key].paint);
2703
+ layerLayoutConfsRef.current[key] = JSON.stringify(props.layers[key].layout);
2746
2704
  }
2747
- }, [mapContext.mapIds, props, mapContext]);
2705
+ }, [mapHook.map, props]);
2748
2706
  useEffect(function () {
2749
- if (!mapRef.current) return; // the MapLibre-gl instance (mapContext.map) is accessible here
2750
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
2707
+ if (!mapHook.map || !initializedRef.current) return; // initialize the layer and add it to the MapLibre-gl instance or do something else with it
2751
2708
 
2752
2709
  for (var key in props.layers) {
2753
- if (mapRef.current.getLayer(layerIdsRef.current[key])) {
2754
- var layerConfString = JSON.stringify(props.layers[key].paint);
2710
+ if (mapHook.map.getLayer(layerIdsRef.current[key])) {
2711
+ // update changed paint property
2712
+ var layerPaintConfString = JSON.stringify(props.layers[key].paint);
2755
2713
 
2756
- if (layerConfString !== layerPaintConfsRef.current[key]) {
2714
+ if (layerPaintConfString !== layerPaintConfsRef.current[key]) {
2757
2715
  for (var paintKey in props.layers[key].paint) {
2758
- mapContext.getMap(props.mapId).setPaintProperty(layerIdsRef.current[key], paintKey, props.layers[key].paint[paintKey]);
2716
+ mapHook.map.setPaintProperty(layerIdsRef.current[key], paintKey, props.layers[key].paint[paintKey]);
2759
2717
  }
2760
2718
  }
2761
2719
 
2762
- layerPaintConfsRef.current[key] = layerConfString;
2763
- }
2764
- }
2765
- }, [props.layers, props, mapContext]);
2766
- useEffect(function () {
2767
- if (!mapRef.current) return;
2720
+ layerPaintConfsRef.current[key] = layerPaintConfString; // update changed layout property
2768
2721
 
2769
- for (var key in props.layers) {
2770
- if (mapRef.current.getLayer(layerIdsRef.current[key])) {
2771
- // toggle layer visibility by changing the layout object's visibility property
2772
- if (props.visible) {
2773
- mapContext.getMap(props.mapId).setLayoutProperty(layerIdsRef.current[key], "visibility", "visible");
2774
- } else {
2775
- mapContext.getMap(props.mapId).setLayoutProperty(layerIdsRef.current[key], "visibility", "none");
2722
+ var layerLayoutConfString = JSON.stringify(props.layers[key].layout);
2723
+
2724
+ if (layerLayoutConfString !== layerLayoutConfsRef.current[key]) {
2725
+ for (var layoutKey in props.layers[key].layout) {
2726
+ mapHook.map.setLayoutProperty(layerIdsRef.current[key], layoutKey, props.layers[key].layout[layoutKey]);
2727
+ }
2776
2728
  }
2729
+
2730
+ layerLayoutConfsRef.current[key] = layerLayoutConfString;
2777
2731
  }
2778
2732
  }
2779
- }, [props.visible]);
2733
+ }, [props.layers, mapHook.map]);
2780
2734
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
2781
2735
  };
2782
2736
 
@@ -2796,11 +2750,6 @@ MlVectorTileLayer.propTypes = {
2796
2750
  */
2797
2751
  layers: PropTypes.object,
2798
2752
 
2799
- /**
2800
- * Boolean value to control the visibility of this layer
2801
- */
2802
- visible: PropTypes.bool,
2803
-
2804
2753
  /**
2805
2754
  * String of the URL of a wms layer
2806
2755
  */