@mapcomponents/react-maplibre 0.1.44 → 0.1.48
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 +32 -2
- package/coverage/clover.xml +226 -145
- package/coverage/coverage-final.json +7 -5
- package/coverage/lcov-report/index.html +86 -71
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +40 -10
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +17 -17
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +4 -4
- package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +188 -53
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +21 -21
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +2 -2
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
- package/coverage/lcov-report/src/components/MlMarker/MlMarker.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
- package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +265 -0
- package/coverage/lcov-report/src/components/MlMeasureTool/index.html +116 -0
- package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.js.html +232 -0
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +25 -10
- package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
- package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
- package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
- package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
- package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
- package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
- package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx.html +74 -20
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +19 -19
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.tsx.html +80 -20
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +21 -21
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +2 -2
- package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
- package/coverage/lcov-report/src/contexts/MapContext.tsx.html +1 -1
- package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +1 -1
- package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +1 -1
- package/coverage/lcov-report/src/contexts/index.html +1 -1
- package/coverage/lcov-report/src/hooks/index.html +19 -19
- package/coverage/lcov-report/src/hooks/useLayer.ts.html +75 -27
- package/coverage/lcov-report/src/hooks/useMap.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useMapState.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useWms.js.html +2 -2
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +12 -6
- package/coverage/lcov.info +466 -281
- package/dist/index.esm.js +173 -42
- package/dist/index.esm.js.map +1 -1
- package/docs-build/{0.b1b9b035.iframe.bundle.js → 0.968bdc5f.iframe.bundle.js} +2 -2
- package/docs-build/0.968bdc5f.iframe.bundle.js.map +1 -0
- package/docs-build/{1.c50fb367.iframe.bundle.js → 1.3530bc86.iframe.bundle.js} +3 -3
- package/docs-build/1.3530bc86.iframe.bundle.js.map +1 -0
- package/docs-build/{17.2e544968.iframe.bundle.js → 17.c96fb6bc.iframe.bundle.js} +2 -2
- package/docs-build/17.c96fb6bc.iframe.bundle.js.map +1 -0
- package/docs-build/{18.42087006.iframe.bundle.js → 18.0947f810.iframe.bundle.js} +3 -3
- package/docs-build/18.0947f810.iframe.bundle.js.map +1 -0
- package/docs-build/{19.7e782442.iframe.bundle.js → 19.44204e5a.iframe.bundle.js} +2 -2
- package/docs-build/19.44204e5a.iframe.bundle.js.map +1 -0
- package/docs-build/{2.e58dc625.iframe.bundle.js → 2.c62e9630.iframe.bundle.js} +2 -2
- package/docs-build/2.c62e9630.iframe.bundle.js.map +1 -0
- package/docs-build/{20.f009289a.iframe.bundle.js → 20.50a2ad76.iframe.bundle.js} +2 -2
- package/docs-build/20.50a2ad76.iframe.bundle.js.map +1 -0
- package/docs-build/{21.1cdc9040.iframe.bundle.js → 21.ce55b70e.iframe.bundle.js} +2 -2
- package/docs-build/21.ce55b70e.iframe.bundle.js.map +1 -0
- package/docs-build/{22.c9e6b2d7.iframe.bundle.js → 22.639c6bb4.iframe.bundle.js} +2 -2
- package/docs-build/22.639c6bb4.iframe.bundle.js.map +1 -0
- package/docs-build/{3.a8172b89.iframe.bundle.js → 3.afb0e0a5.iframe.bundle.js} +2 -2
- package/docs-build/3.afb0e0a5.iframe.bundle.js.map +1 -0
- package/docs-build/catalogue/mc_meta.json +1 -1
- package/docs-build/iframe.html +1 -1
- package/docs-build/main~24120820.e956ad2c.iframe.bundle.js +2 -0
- package/docs-build/main~24120820.e956ad2c.iframe.bundle.js.map +1 -0
- package/docs-build/thumbnails/MlMeasureTool.png +0 -0
- package/docs-build/{vendors~main~0ad7406a.2054ae7c.iframe.bundle.js → vendors~main~0ad7406a.834c9ace.iframe.bundle.js} +3 -3
- package/docs-build/vendors~main~0ad7406a.834c9ace.iframe.bundle.js.map +1 -0
- package/docs-build/vendors~main~0f485567.7297d057.iframe.bundle.js +2 -0
- package/docs-build/vendors~main~0f485567.7297d057.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~41a6ab2c.a947ed53.iframe.bundle.js → vendors~main~41a6ab2c.19d97527.iframe.bundle.js} +2 -2
- package/docs-build/vendors~main~41a6ab2c.19d97527.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~52589227.1d1558cd.iframe.bundle.js → vendors~main~52589227.cebbe724.iframe.bundle.js} +2 -2
- package/docs-build/vendors~main~52589227.cebbe724.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~57c1f6cb.6a433835.iframe.bundle.js → vendors~main~57c1f6cb.8a8dd47e.iframe.bundle.js} +2 -2
- package/docs-build/vendors~main~57c1f6cb.8a8dd47e.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~73914085.a8e03e3b.iframe.bundle.js → vendors~main~73914085.2e61c0dc.iframe.bundle.js} +13 -13
- package/docs-build/vendors~main~73914085.2e61c0dc.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~9c5b28f6.7b8beed1.iframe.bundle.js → vendors~main~9c5b28f6.32356887.iframe.bundle.js} +3 -3
- package/docs-build/vendors~main~9c5b28f6.32356887.iframe.bundle.js.map +1 -0
- package/docs-build/vendors~main~b5906859.94dc520a.iframe.bundle.js +21 -0
- package/docs-build/vendors~main~b5906859.94dc520a.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~b8f44717.7053e467.iframe.bundle.js → vendors~main~b8f44717.8669cfb8.iframe.bundle.js} +3 -3
- package/docs-build/vendors~main~b8f44717.8669cfb8.iframe.bundle.js.map +1 -0
- package/docs-build/{vendors~main~b9cf3951.a4fd68f5.iframe.bundle.js → vendors~main~b9cf3951.2a2025c3.iframe.bundle.js} +11 -11
- package/docs-build/vendors~main~b9cf3951.2a2025c3.iframe.bundle.js.map +1 -0
- package/docs-build/vendors~main~d939e436.bb2b0303.iframe.bundle.js +2 -0
- package/docs-build/vendors~main~d939e436.bb2b0303.iframe.bundle.js.map +1 -0
- package/docs-build/vendors~main~f420d588.3481b43e.iframe.bundle.js +107 -0
- package/docs-build/vendors~main~f420d588.3481b43e.iframe.bundle.js.map +1 -0
- package/package.json +1 -1
- package/public/catalogue/mc_meta.json +1 -0
- package/public/thumbnails/MlMeasureTool.png +0 -0
- package/src/components/MapLibreMap/MapLibreMap.stories.js +75 -20
- package/src/components/MapLibreMap/MapLibreMap.tsx +11 -1
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.ts +2 -2
- package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +3 -3
- package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.test.js +1 -1
- package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx +82 -37
- package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +1 -1
- package/src/components/MlMeasureTool/MlMeasureTool.doc.de.md +3 -0
- package/src/components/MlMeasureTool/MlMeasureTool.meta.json +15 -0
- package/src/components/MlMeasureTool/MlMeasureTool.stories.js +96 -0
- package/src/components/MlMeasureTool/MlMeasureTool.tsx +60 -0
- package/src/components/MlOsmLayer/{MlOsmLayer.stories.js → MlOsmLayer.stories_.js} +0 -0
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx +26 -8
- package/src/components/MlWmsLayer/MlWmsLayer.stories.js +2 -3
- package/src/components/MlWmsLayer/MlWmsLayer.tsx +27 -7
- package/src/components/MlWmsLoader/MlWmsLoader.tsx +1 -1
- package/src/hooks/useLayer.ts +27 -11
- package/src/hooks/useWms.js +1 -1
- package/src/index.ts +5 -4
- package/src/util/layerRemovalTest.js +5 -0
- package/docs-build/0.b1b9b035.iframe.bundle.js.map +0 -1
- package/docs-build/1.c50fb367.iframe.bundle.js.map +0 -1
- package/docs-build/17.2e544968.iframe.bundle.js.map +0 -1
- package/docs-build/18.42087006.iframe.bundle.js.map +0 -1
- package/docs-build/19.7e782442.iframe.bundle.js.map +0 -1
- package/docs-build/2.e58dc625.iframe.bundle.js.map +0 -1
- package/docs-build/20.f009289a.iframe.bundle.js.map +0 -1
- package/docs-build/21.1cdc9040.iframe.bundle.js.map +0 -1
- package/docs-build/22.c9e6b2d7.iframe.bundle.js.map +0 -1
- package/docs-build/3.a8172b89.iframe.bundle.js.map +0 -1
- package/docs-build/main~24120820.edd86ba9.iframe.bundle.js +0 -2
- package/docs-build/main~24120820.edd86ba9.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~0ad7406a.2054ae7c.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~0f485567.de36692f.iframe.bundle.js +0 -2
- package/docs-build/vendors~main~0f485567.de36692f.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~41a6ab2c.a947ed53.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~52589227.1d1558cd.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~57c1f6cb.6a433835.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~73914085.a8e03e3b.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~9c5b28f6.7b8beed1.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~b5906859.7f66dcaf.iframe.bundle.js +0 -21
- package/docs-build/vendors~main~b5906859.7f66dcaf.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~b8f44717.7053e467.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~b9cf3951.a4fd68f5.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~d939e436.ba1cad1b.iframe.bundle.js +0 -2
- package/docs-build/vendors~main~d939e436.ba1cad1b.iframe.bundle.js.map +0 -1
- package/docs-build/vendors~main~f420d588.59c93444.iframe.bundle.js +0 -107
- package/docs-build/vendors~main~f420d588.59c93444.iframe.bundle.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"MlCreatePdfButton":{"name":"MlCreatePdfButton","title":"Export PDF","description":"Creates a PDF file with the current map view.","i18n":{"de":{"title":"PDF Export","description":"Erzeugt eine PDF Datei aus der aktuellen Kartenansicht."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlFeatureEditor":{"name":"MlFeatureEditor","title":"Sketch tools","description":"Enables the editing of Point, Linestring and Polygon GeoJSON Files.","i18n":{"de":{"title":"Skizzen Werkzeug","description":"Erzeugen und Bearbeiten von Objekten."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":0},"MlFillExtrusionLayer":{"name":"MlFillExtrusionLayer","title":"Simple 3D buildings","description":"Draws a level, out of the building outline and the height, extrudes 3D Objects as buildings.","i18n":{"de":{"title":"3D Gebäude","description":"Zeichnet eine Ebene mit einfach, aus den Gebäudeumrissen und anhand der Höhen, extrudierten 3D Objekten als Gebäude."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlFollowGps":{"name":"MlFollowGps","title":"GPS tracker","description":"","i18n":{"de":{"title":"GPS-Tracker","description":""}},"tags":[],"category":"","type":"component","price":0},"MlGeoJsonLayer":{"name":"MlGeoJsonLayer","title":"GeoJSON layer","description":"","i18n":{"de":{"title":"GeoJSON Darstellung","description":""}},"tags":[],"category":"","type":"component","price":0},"MlGPXViewer":{"name":"MlGPXViewer","title":"GPX viewer","description":"","i18n":{"de":{"title":"GPX Darstellung","description":""}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlLayerMagnify":{"name":"MlLayerMagnify","title":"Map magnifier","description":"Hides a part of a map that is superimposed on another MapLibre map.","i18n":{"de":{"title":"Kartenlupe","description":"Kartenlupe blendet einen Teil einer, von zwei übereinanderliegenden, MapLibre Karten aus."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlLayerSwipe":{"name":"MlLayerSwipe","title":"Map curtain","description":"Map curtain hides an area of the top one of two overlaying MapLibre maps.","i18n":{"de":{"title":"Kartenvorhang","description":"Kartenvorhangs blendet einen Teil einer, von zwei übereinanderliegenden, MapLibre Karten aus."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlMeasureTool":{"name":"MlMeasureTool","title":"Measure tool","description":"","i18n":{"de":{"title":"Messwerkzeug","description":""}},"tags":[],"category":"","type":"component","price":0},"MlNavigationCompass":{"name":"MlNavigationCompass","title":"Compass","description":"","i18n":{"de":{"title":"Kompass","description":""}},"tags":[],"category":"","type":"component","price":0},"MlNavigationTools":{"name":"MlNavigationTools","title":"Navigation tools","description":"","i18n":{"de":{"title":"Navigationswerkzeuge","description":""}},"tags":[],"category":"","type":"component","price":0},"MlScaleReference":{"name":"MlScaleReference","title":"Reference scale","description":"","i18n":{"de":{"title":"Maßstabsreferenz","description":""}},"tags":[],"category":"","type":"component","price":0},"MlSpatialElevationProfile":{"name":"MlSpatialElevationProfile","title":"3D height profile","description":"Draws a level, out of the building outline and the height, extrudes 3D Objects as buildings.","i18n":{"de":{"title":"3D Höhenprofil","description":"Zeichnet eine Ebene mit einfach, aus den Gebäudeumrissen und anhand der Höhen, extrudierten 3D Objekten als Gebäude."}},"tags":["Map add-on"],"category":"add-ons","type":"component","price":5000},"MlThreeJsLayer":{"name":"MlThreeJsLayer","title":"3D Model","description":"Layer Component, that makes it possible to show 3D Models on the map.","i18n":{"de":{"title":"3D Modelle","description":"Layer Component, das es ermöglicht 3D Modelle auf der Karte darzustellen."}},"tags":["Map layer"],"category":"layer","type":"component","price":5000},"MlTransitionGeoJsonLayer":{"name":"MlTransitionGeoJsonLayer","title":"GeoJSON layer","description":"","i18n":{"de":{"title":"GeoJSON Ebene","description":""}},"tags":[],"category":"","type":"component","price":0},"MlVectorTileLayer":{"name":"MlVectorTileLayer","title":"Vector tile layer","description":"Adds a vector tile layer to the map","i18n":{"de":{"title":"Vector Tiles","description":"Baustein: Vektorenkacheln/Vector Tiles (der Anwendung/Karte hinzufügen)"}},"tags":["Map layer"],"category":"layer","type":"component","price":5000},"MlWmsLoader":{"name":"MlWmsLoader","title":"WMS loader","description":"","i18n":{"de":{"title":"WMS Feature Info","description":""}},"tags":[],"category":"","type":"component","price":0}}
|
|
Binary file
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import MapLibreMap from "./MapLibreMap";
|
|
4
4
|
import { MapComponentsProvider } from "../../contexts/MapContext";
|
|
5
|
+
import MlGeoJsonLayer from "../MlGeoJsonLayer/MlGeoJsonLayer";
|
|
6
|
+
import { Button } from "@mui/material";
|
|
7
|
+
import TopToolbar from "../../ui_components/TopToolbar";
|
|
8
|
+
import sample_geojson_1 from "../MlGeoJsonLayer/assets/sample_1.json";
|
|
5
9
|
|
|
6
10
|
const storyoptions = {
|
|
7
11
|
title: "Core/MapLibreMap",
|
|
@@ -16,30 +20,81 @@ const storyoptions = {
|
|
|
16
20
|
};
|
|
17
21
|
export default storyoptions;
|
|
18
22
|
|
|
19
|
-
const Template = (args) =>
|
|
20
|
-
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
const Template = (args) => {
|
|
24
|
+
return (
|
|
25
|
+
<MapComponentsProvider>
|
|
26
|
+
<MapLibreMap
|
|
27
|
+
options={args.options}
|
|
28
|
+
style={{
|
|
29
|
+
position: "absolute",
|
|
30
|
+
height: "100vh",
|
|
31
|
+
width: "100vw",
|
|
32
|
+
top: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
bottom: 0,
|
|
36
|
+
zIndex: 100,
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</MapComponentsProvider>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
36
42
|
|
|
37
43
|
export const ExampleConfig = Template.bind({});
|
|
38
44
|
ExampleConfig.args = {
|
|
39
45
|
options: {
|
|
40
46
|
style: "https://wms.wheregroup.com/tileserver/style/osm-bright.json",
|
|
41
47
|
center: [8.607, 53.1409349],
|
|
42
|
-
zoom: 14
|
|
48
|
+
zoom: 14,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const StyleChangeTemplate = (args) => {
|
|
53
|
+
const [activeStyle, setActiveStyle] = useState(
|
|
54
|
+
"https://wms.wheregroup.com/tileserver/style/osm-fiord-color.json"
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<MapComponentsProvider>
|
|
59
|
+
<TopToolbar>
|
|
60
|
+
<Button
|
|
61
|
+
onClick={() =>
|
|
62
|
+
setActiveStyle("https://wms.wheregroup.com/tileserver/style/osm-bright.json")
|
|
63
|
+
}
|
|
64
|
+
>
|
|
65
|
+
OSM-Bright
|
|
66
|
+
</Button>
|
|
67
|
+
<Button
|
|
68
|
+
onClick={() =>
|
|
69
|
+
setActiveStyle("https://wms.wheregroup.com/tileserver/style/osm-fiord-color.json")
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
OSM-Fiord-Color
|
|
73
|
+
</Button>
|
|
74
|
+
</TopToolbar>
|
|
75
|
+
<MapLibreMap
|
|
76
|
+
options={{ ...args.options, style: activeStyle }}
|
|
77
|
+
style={{
|
|
78
|
+
position: "absolute",
|
|
79
|
+
height: "100vh",
|
|
80
|
+
width: "100vw",
|
|
81
|
+
top: 0,
|
|
82
|
+
right: 0,
|
|
83
|
+
left: 0,
|
|
84
|
+
bottom: 0,
|
|
85
|
+
zIndex: 100,
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
<MlGeoJsonLayer type="line" geojson={sample_geojson_1} />
|
|
89
|
+
</MapComponentsProvider>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const StyleChangeConfig = StyleChangeTemplate.bind({});
|
|
94
|
+
StyleChangeConfig.args = {
|
|
95
|
+
options: {
|
|
96
|
+
zoom: 14.5,
|
|
97
|
+
center: [7.0851268, 50.73884],
|
|
43
98
|
},
|
|
44
99
|
};
|
|
45
|
-
|
|
100
|
+
StyleChangeConfig.parameters = {};
|
|
@@ -40,7 +40,7 @@ const defaultProps: MapLibreMapProps = {
|
|
|
40
40
|
id: "background",
|
|
41
41
|
type: "background",
|
|
42
42
|
paint: {
|
|
43
|
-
"background-color": "rgba(
|
|
43
|
+
"background-color": "rgba(0,0,0,0)",
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -66,6 +66,7 @@ const MapLibreMap: FC<MapLibreMapProps> = (props: MapLibreMapProps) => {
|
|
|
66
66
|
|
|
67
67
|
const mapIdRef = useRef(props.mapId);
|
|
68
68
|
const initializedRef = useRef(false);
|
|
69
|
+
const currentStyle = useRef(props.options?.style);
|
|
69
70
|
|
|
70
71
|
useEffect(() => {
|
|
71
72
|
let mapId = mapIdRef.current;
|
|
@@ -101,6 +102,15 @@ const MapLibreMap: FC<MapLibreMapProps> = (props: MapLibreMapProps) => {
|
|
|
101
102
|
}
|
|
102
103
|
}, [props.options, props.mapId]);
|
|
103
104
|
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (map.current?.map && props?.options?.style && currentStyle.current !== props.options.style) {
|
|
107
|
+
console.log("set style");
|
|
108
|
+
currentStyle.current = props.options.style;
|
|
109
|
+
map.current.map.setStyle(props.options.style);
|
|
110
|
+
}
|
|
111
|
+
// @ts-ignore: props.options is either passed or populated with default values
|
|
112
|
+
}, [props.options.style])
|
|
113
|
+
|
|
104
114
|
return <div ref={mapContainer as RefObject<HTMLDivElement>} className="mapContainer" style={props.style} />;
|
|
105
115
|
};
|
|
106
116
|
|
|
@@ -213,7 +213,7 @@ class MapLibreGlWrapper {
|
|
|
213
213
|
*/
|
|
214
214
|
buildLayerObjects: () => {
|
|
215
215
|
// @ts-ignore
|
|
216
|
-
return self.style._order
|
|
216
|
+
return self.map.style._order
|
|
217
217
|
.map((layerId: string) => {
|
|
218
218
|
return self.wrapper.buildLayerObject(
|
|
219
219
|
self.map.style._layers[layerId]
|
|
@@ -487,7 +487,7 @@ class MapLibreGlWrapper {
|
|
|
487
487
|
this[item] = (...props: any[]) => {
|
|
488
488
|
if (
|
|
489
489
|
self.map &&
|
|
490
|
-
|
|
490
|
+
self.map.style &&
|
|
491
491
|
typeof self.map.style[item] === "function"
|
|
492
492
|
) {
|
|
493
493
|
self.map.style[item](...props);
|
|
@@ -14,16 +14,16 @@ interface MlFeatureEditorProps {
|
|
|
14
14
|
/**
|
|
15
15
|
* Id of the target MapLibre instance in mapContext
|
|
16
16
|
*/
|
|
17
|
-
mapId
|
|
17
|
+
mapId?: string;
|
|
18
18
|
/**
|
|
19
19
|
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
20
20
|
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
21
21
|
*/
|
|
22
|
-
insertBeforeLayer
|
|
22
|
+
insertBeforeLayer?: string;
|
|
23
23
|
/**
|
|
24
24
|
* Input GeoJson data at initialization
|
|
25
25
|
*/
|
|
26
|
-
geojson
|
|
26
|
+
geojson?: any;
|
|
27
27
|
/**
|
|
28
28
|
* Callback function that is called each time the GeoJson data within has changed within MlFeatureEditor.
|
|
29
29
|
* First parameter is the new GeoJson feature.
|
|
@@ -3,7 +3,7 @@ import { uuid_regex } from "../../setupTests";
|
|
|
3
3
|
|
|
4
4
|
import MlImageMarkerLayer from "./MlImageMarkerLayer";
|
|
5
5
|
|
|
6
|
-
const testComponent = <MlImageMarkerLayer options={{ source: {} }}
|
|
6
|
+
const testComponent = <MlImageMarkerLayer options={{ source: {} }} />;
|
|
7
7
|
|
|
8
8
|
layerRemovalTest(
|
|
9
9
|
"<MlImageMarkerLayer />",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useRef, useCallback, useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { GeoJSONSource } from "maplibre-gl";
|
|
4
|
-
import useMap from "../../hooks/useMap";
|
|
4
|
+
import useMap, { useMapType } from "../../hooks/useMap";
|
|
5
5
|
|
|
6
6
|
interface MlImageMarkerLayerProps {
|
|
7
7
|
/**
|
|
@@ -37,12 +37,12 @@ const MlImageMarkerLayer = (props: MlImageMarkerLayerProps) => {
|
|
|
37
37
|
waitForLayer: props.insertBeforeLayer,
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const initializedRef = useRef(false);
|
|
41
|
+
const recreationInProgress = useRef(false);
|
|
41
42
|
const imageIdRef = useRef(props.imageId || "img_" + new Date().getTime());
|
|
42
|
-
const layerId = useRef(
|
|
43
|
-
props.layerId || "MlImageMarkerLayer-" + mapHook.componentId
|
|
44
|
-
);
|
|
43
|
+
const layerId = useRef(props.layerId || "MlImageMarkerLayer-" + mapHook.componentId);
|
|
45
44
|
|
|
45
|
+
// effect to sync Layer paint & layout properties
|
|
46
46
|
useEffect(() => {
|
|
47
47
|
if (
|
|
48
48
|
!mapHook.map ||
|
|
@@ -50,32 +50,53 @@ const MlImageMarkerLayer = (props: MlImageMarkerLayerProps) => {
|
|
|
50
50
|
!props.options
|
|
51
51
|
)
|
|
52
52
|
return;
|
|
53
|
-
|
|
54
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
53
|
+
|
|
55
54
|
var key;
|
|
56
55
|
|
|
57
56
|
if (props.options.layout) {
|
|
58
57
|
for (key in props.options.layout) {
|
|
59
|
-
mapHook.map.map.setLayoutProperty(
|
|
60
|
-
layerId.current,
|
|
61
|
-
key,
|
|
62
|
-
props.options.layout[key]
|
|
63
|
-
);
|
|
58
|
+
mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
61
|
if (props.options.paint) {
|
|
67
62
|
for (key in props.options.paint) {
|
|
68
|
-
mapHook.map.map.setPaintProperty(
|
|
69
|
-
layerId.current,
|
|
70
|
-
key,
|
|
71
|
-
props.options.paint[key]
|
|
72
|
-
);
|
|
63
|
+
mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
66
|
}, [props.options, layerId.current, props.mapId]);
|
|
76
67
|
|
|
77
|
-
const
|
|
78
|
-
if(!mapHook.map)
|
|
68
|
+
const createImage = (mapHook: useMapType, props: MlImageMarkerLayerProps, callback: Function) => {
|
|
69
|
+
if (!mapHook.map) {
|
|
70
|
+
initializedRef.current = false;
|
|
71
|
+
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (props.imgSrc && !mapHook.map.map.hasImage(imageIdRef.current)) {
|
|
76
|
+
mapHook.map.map.loadImage(props.imgSrc, function (error, image) {
|
|
77
|
+
if (error) throw error;
|
|
78
|
+
|
|
79
|
+
if (!mapHook.map || mapHook.map.map.hasImage(imageIdRef.current)) return;
|
|
80
|
+
|
|
81
|
+
mapHook.map.addImage(imageIdRef.current, image, mapHook.componentId);
|
|
82
|
+
|
|
83
|
+
if (typeof callback === "function") {
|
|
84
|
+
callback();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
if (typeof callback === "function") {
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const createLayer = (
|
|
95
|
+
mapHook: useMapType,
|
|
96
|
+
props: MlImageMarkerLayerProps,
|
|
97
|
+
createMapLibreElements: Function
|
|
98
|
+
) => {
|
|
99
|
+
if (!props.options || !mapHook.map || mapHook.map?.map.getLayer(layerId.current)) return;
|
|
79
100
|
|
|
80
101
|
let tmpOptions = {
|
|
81
102
|
id: layerId.current,
|
|
@@ -83,31 +104,55 @@ const MlImageMarkerLayer = (props: MlImageMarkerLayerProps) => {
|
|
|
83
104
|
...props.options,
|
|
84
105
|
};
|
|
85
106
|
tmpOptions.layout["icon-image"] = imageIdRef.current;
|
|
86
|
-
mapHook.map.addLayer(
|
|
87
|
-
|
|
88
|
-
|
|
107
|
+
mapHook.map.addLayer(tmpOptions, props.insertBeforeLayer, mapHook.componentId);
|
|
108
|
+
|
|
109
|
+
// recreate layer if map style.json has changed
|
|
110
|
+
mapHook.map.on(
|
|
111
|
+
"styledata",
|
|
112
|
+
() => {
|
|
113
|
+
if (
|
|
114
|
+
initializedRef.current &&
|
|
115
|
+
!mapHook.map?.map.getLayer(layerId.current) &&
|
|
116
|
+
!recreationInProgress.current
|
|
117
|
+
) {
|
|
118
|
+
initializedRef.current = false;
|
|
119
|
+
recreationInProgress.current = true;
|
|
120
|
+
console.log("Recreate Layer " + layerId.current);
|
|
121
|
+
createMapLibreElements();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
89
124
|
mapHook.componentId
|
|
90
125
|
);
|
|
91
|
-
}, [props, mapHook.map]);
|
|
92
126
|
|
|
93
|
-
|
|
94
|
-
|
|
127
|
+
if (recreationInProgress.current) {
|
|
128
|
+
recreationInProgress.current = false;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const createMapLibreElements = useCallback(() => {
|
|
133
|
+
if (!mapHook.map || initializedRef.current || mapHook.map?.map.getLayer(layerId.current))
|
|
95
134
|
return;
|
|
96
135
|
|
|
97
|
-
|
|
136
|
+
initializedRef.current = true;
|
|
98
137
|
|
|
99
|
-
if (
|
|
100
|
-
mapHook.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if(!mapHook.map)return;
|
|
138
|
+
if (recreationInProgress.current) {
|
|
139
|
+
mapHook.cleanup();
|
|
140
|
+
}
|
|
104
141
|
|
|
105
|
-
|
|
142
|
+
if (props.imgSrc) {
|
|
143
|
+
createImage(mapHook, props, () => {
|
|
144
|
+
createLayer(mapHook, props, createMapLibreElements);
|
|
106
145
|
});
|
|
146
|
+
} else {
|
|
147
|
+
createLayer(mapHook, props, createMapLibreElements);
|
|
107
148
|
}
|
|
149
|
+
}, [props, mapHook]);
|
|
108
150
|
|
|
109
|
-
|
|
110
|
-
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (initializedRef.current) return;
|
|
153
|
+
|
|
154
|
+
createMapLibreElements();
|
|
155
|
+
}, [createMapLibreElements]);
|
|
111
156
|
|
|
112
157
|
useEffect(() => {
|
|
113
158
|
if (
|
|
@@ -118,9 +163,9 @@ const MlImageMarkerLayer = (props: MlImageMarkerLayerProps) => {
|
|
|
118
163
|
return;
|
|
119
164
|
}
|
|
120
165
|
|
|
121
|
-
(mapHook.map.map
|
|
122
|
-
.
|
|
123
|
-
|
|
166
|
+
(mapHook.map.map.getSource(layerId.current) as GeoJSONSource).setData(
|
|
167
|
+
props.options.source.data
|
|
168
|
+
);
|
|
124
169
|
}, [props.options.source.data, props]);
|
|
125
170
|
|
|
126
171
|
return <></>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./MlLayerSwitcher.css";
|
|
2
2
|
//External
|
|
3
|
-
import { useEffect, useContext, useState } from "react";
|
|
3
|
+
import React, { useEffect, useContext, useState } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import { useTranslation } from "react-i18next";
|
|
6
6
|
import { Card, CardContent, Typography, Box } from "@mui/material";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import MlMeasureTool from "./MlMeasureTool";
|
|
4
|
+
|
|
5
|
+
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
6
|
+
import StraightenOutlinedIcon from "@mui/icons-material/StraightenOutlined";
|
|
7
|
+
import SquareFootOutlinedIcon from "@mui/icons-material/SquareFootOutlined";
|
|
8
|
+
import Grid from "@mui/material/Grid";
|
|
9
|
+
import Box from "@mui/material/Box";
|
|
10
|
+
import { MenuItem, Select } from "@mui/material";
|
|
11
|
+
|
|
12
|
+
const storyoptions = {
|
|
13
|
+
title: "MapComponents/MlMeasureTool",
|
|
14
|
+
component: MlMeasureTool,
|
|
15
|
+
argTypes: {},
|
|
16
|
+
decorators: mapContextDecorator,
|
|
17
|
+
};
|
|
18
|
+
export default storyoptions;
|
|
19
|
+
|
|
20
|
+
const Template = (args) => {
|
|
21
|
+
const [unit, setUnit] = useState("kilometers");
|
|
22
|
+
const handleChange = (event) => {
|
|
23
|
+
setUnit(event.target.value);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div style={{ width: "200px", position: "absolute", zIndex: 105 }}>
|
|
28
|
+
<Select
|
|
29
|
+
name={"units"}
|
|
30
|
+
onChange={handleChange}
|
|
31
|
+
label={"Unit for measurement"}
|
|
32
|
+
defaultValue={"kilometers"}
|
|
33
|
+
>
|
|
34
|
+
<MenuItem value={"kilometers"}>Kilometers</MenuItem>
|
|
35
|
+
<MenuItem value={"miles"}>Miles</MenuItem>
|
|
36
|
+
</Select>
|
|
37
|
+
<Grid
|
|
38
|
+
container
|
|
39
|
+
style={{
|
|
40
|
+
textAlign: "left",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<SquareFootOutlinedIcon />
|
|
45
|
+
<h4 style={{ margin: "0px" }}>Measure Polygon</h4>
|
|
46
|
+
</Grid>
|
|
47
|
+
|
|
48
|
+
<Box m={2} style={{ textAlign: "left" }}>
|
|
49
|
+
Area: <MlMeasureTool measureType={"polygon"} unit={unit} />
|
|
50
|
+
</Box>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const LineTemplate = (args) => {
|
|
56
|
+
const [unit, setUnit] = useState("kilometers");
|
|
57
|
+
const handleChange = (event) => {
|
|
58
|
+
setUnit(event.target.value);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div style={{ width: "200px", position: "absolute", zIndex: 105 }}>
|
|
63
|
+
<Select
|
|
64
|
+
name={"units"}
|
|
65
|
+
onChange={handleChange}
|
|
66
|
+
label={"Unit for measurement"}
|
|
67
|
+
defaultValue={"kilometers"}
|
|
68
|
+
>
|
|
69
|
+
<MenuItem value={"kilometers"}> Kilometers</MenuItem>
|
|
70
|
+
<MenuItem value={"miles"}> Miles</MenuItem>
|
|
71
|
+
</Select>
|
|
72
|
+
<Grid
|
|
73
|
+
container
|
|
74
|
+
style={{
|
|
75
|
+
textAlign: "left",
|
|
76
|
+
alignItems: "center",
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<StraightenOutlinedIcon />
|
|
80
|
+
<h4 style={{ margin: "0px" }}>Measure Line</h4>
|
|
81
|
+
</Grid>
|
|
82
|
+
|
|
83
|
+
<Box m={2} style={{ textAlign: "left" }}>
|
|
84
|
+
Length: <MlMeasureTool measureType={"line"} unit={unit} />
|
|
85
|
+
</Box>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const MeasureLine = LineTemplate.bind({});
|
|
91
|
+
MeasureLine.parameters = {};
|
|
92
|
+
MeasureLine.args = {};
|
|
93
|
+
|
|
94
|
+
export const MeasurePolygon = Template.bind({});
|
|
95
|
+
MeasurePolygon.parameters = {};
|
|
96
|
+
MeasurePolygon.args = {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import MlFeatureEditor from "../MlFeatureEditor/MlFeatureEditor";
|
|
3
|
+
import * as turf from "@turf/turf";
|
|
4
|
+
|
|
5
|
+
interface MlMeasureToolProps {
|
|
6
|
+
/**
|
|
7
|
+
* String that specify if the Tool measures an area ("polygon") or length ("line")
|
|
8
|
+
*/
|
|
9
|
+
measureType?: string;
|
|
10
|
+
/**
|
|
11
|
+
* String that dictates which unit of measurement is used
|
|
12
|
+
*/
|
|
13
|
+
unit?: turf.Units;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//const unitSquareConvert = {
|
|
17
|
+
// kilometers: 1,
|
|
18
|
+
// miles: 1 / 2.58998811,
|
|
19
|
+
//};
|
|
20
|
+
function getUnitSquareMultiplier(measureType:string | undefined) {
|
|
21
|
+
return measureType === "miles" ? 1 / 2.58998811 : 1;
|
|
22
|
+
}
|
|
23
|
+
function getUnitLabel(measureType:string | undefined) {
|
|
24
|
+
return measureType === "miles" ? 'mi' : 'km';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const MlMeasureTool = (props: MlMeasureToolProps) => {
|
|
28
|
+
const [length, setLength] = useState(0);
|
|
29
|
+
const [currentFeatures, setCurrentFeatures] = useState([undefined]);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (currentFeatures[0]) {
|
|
33
|
+
setLength(
|
|
34
|
+
props.measureType === "polygon"
|
|
35
|
+
? (turf.area(currentFeatures[0]) / 1000000) * getUnitSquareMultiplier(props.unit)
|
|
36
|
+
: turf.length(currentFeatures[0], { units: props.unit })
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}, [props.unit, currentFeatures]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<MlFeatureEditor
|
|
44
|
+
onChange={(features:any) => {
|
|
45
|
+
setCurrentFeatures(features);
|
|
46
|
+
}}
|
|
47
|
+
mode={props.measureType === "polygon" ? "custom_polygon" : "draw_line_string"}
|
|
48
|
+
/>
|
|
49
|
+
{length.toFixed(2)} {getUnitLabel(props.unit)}
|
|
50
|
+
{props.measureType === "polygon" ? "²" : ""}
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
MlMeasureTool.defaultProps = {
|
|
56
|
+
mapId: undefined,
|
|
57
|
+
measureType: "line",
|
|
58
|
+
unit: "kilometers",
|
|
59
|
+
};
|
|
60
|
+
export default MlMeasureTool;
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useEffect } from "react";
|
|
1
|
+
import React, { useRef, useEffect, useCallback } from "react";
|
|
2
2
|
import useMap from "../../hooks/useMap";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
|
|
@@ -24,18 +24,20 @@ const MlVectorTileLayer = (props: MlVectorTileLayerProps) => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
const layerIdsRef = useRef({});
|
|
27
|
-
const layerId = useRef(
|
|
28
|
-
props.layerId || "MlVectorTileLayer-" + mapHook.componentId
|
|
29
|
-
);
|
|
27
|
+
const layerId = useRef(props.layerId || "MlVectorTileLayer-" + mapHook.componentId);
|
|
30
28
|
const layerPaintConfsRef = useRef({});
|
|
31
29
|
const layerLayoutConfsRef = useRef({});
|
|
32
30
|
const initializedRef = useRef(false);
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
if (!mapHook.map
|
|
32
|
+
const createLayer = useCallback(() => {
|
|
33
|
+
if (!mapHook.map) return;
|
|
36
34
|
|
|
37
35
|
initializedRef.current = true;
|
|
38
36
|
|
|
37
|
+
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
38
|
+
mapHook.cleanup();
|
|
39
|
+
}
|
|
40
|
+
|
|
39
41
|
// Add the new layer to the openlayers instance once it is available
|
|
40
42
|
mapHook.map.addSource(
|
|
41
43
|
layerId.current,
|
|
@@ -72,12 +74,28 @@ const MlVectorTileLayer = (props: MlVectorTileLayerProps) => {
|
|
|
72
74
|
mapHook.componentId
|
|
73
75
|
);
|
|
74
76
|
layerPaintConfsRef.current[key] = JSON.stringify(props.layers[key].paint);
|
|
75
|
-
layerLayoutConfsRef.current[key] = JSON.stringify(
|
|
76
|
-
|
|
77
|
+
layerLayoutConfsRef.current[key] = JSON.stringify(props.layers[key].layout);
|
|
78
|
+
|
|
79
|
+
// recreate layer if style has changed
|
|
80
|
+
mapHook.map.on(
|
|
81
|
+
"styledata",
|
|
82
|
+
() => {
|
|
83
|
+
if (initializedRef.current && !mapHook.map?.map.getSource(layerId.current)) {
|
|
84
|
+
console.log("Recreate Layer " + layerId.current);
|
|
85
|
+
createLayer();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
mapHook.componentId
|
|
77
89
|
);
|
|
78
90
|
}
|
|
79
91
|
}, [mapHook.map, props]);
|
|
80
92
|
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (initializedRef.current) return;
|
|
95
|
+
|
|
96
|
+
createLayer();
|
|
97
|
+
}, [createLayer]);
|
|
98
|
+
|
|
81
99
|
useEffect(() => {
|
|
82
100
|
if (!mapHook.map || !initializedRef.current) return;
|
|
83
101
|
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
@@ -4,7 +4,7 @@ import MlWmsLayer from "./MlWmsLayer";
|
|
|
4
4
|
import TopToolbar from "../../ui_components/TopToolbar";
|
|
5
5
|
import Button from "@mui/material/Button";
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import mapContextDecorator from "../../decorators/MapContextDecorator";
|
|
8
8
|
|
|
9
9
|
import "../../App.css";
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ const storyoptions = {
|
|
|
15
15
|
url: {},
|
|
16
16
|
layer: {},
|
|
17
17
|
},
|
|
18
|
-
decorators:
|
|
18
|
+
decorators: mapContextDecorator,
|
|
19
19
|
};
|
|
20
20
|
export default storyoptions;
|
|
21
21
|
|
|
@@ -41,7 +41,6 @@ const Template = (props) => {
|
|
|
41
41
|
export const ExampleConfig = Template.bind({});
|
|
42
42
|
ExampleConfig.parameters = {};
|
|
43
43
|
ExampleConfig.args = {
|
|
44
|
-
mapId: "map_2",
|
|
45
44
|
url: "https://www.wms.nrw.de/geobasis/wms_nw_uraufnahme",
|
|
46
45
|
urlParameters: {
|
|
47
46
|
layers: "nw_uraufnahme_rw",
|