@mapcomponents/react-maplibre 0.1.56 → 0.1.58
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/.eslintignore +11 -0
- package/.eslintrc.js +20 -0
- package/.github/workflows/check-formatting.yml +46 -0
- package/.prettierignore +11 -0
- package/.prettierrc.json +6 -0
- package/CHANGELOG.md +20 -0
- package/coverage/clover.xml +232 -80
- package/coverage/coverage-final.json +43 -37
- package/coverage/lcov-report/index.html +71 -26
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +83 -83
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +66 -66
- package/coverage/lcov-report/src/components/MlCenterPosition/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +30 -30
- package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx.html +202 -0
- package/coverage/lcov-report/src/components/MlCreatePdfForm/index.html +116 -0
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +99 -99
- package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +66 -66
- package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +221 -221
- package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.tsx.html +308 -308
- package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +497 -497
- package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx.html +85 -85
- package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx.html +469 -0
- package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/index.html +116 -0
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +140 -140
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +37 -37
- package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +179 -179
- package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.html +113 -113
- package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
- package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +181 -181
- package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +58 -58
- 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 +108 -108
- package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
- package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +39 -39
- package/coverage/lcov-report/src/components/MlMeasureTool/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +183 -183
- package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
- package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +163 -163
- package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +50 -50
- package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.js.html +30 -30
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +89 -89
- package/coverage/lcov-report/src/components/MlScaleReference/index.html +11 -11
- package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +204 -204
- package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +180 -180
- package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
- package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +163 -163
- package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +136 -136
- package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +53 -53
- package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
- package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx.html +123 -123
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +35 -35
- package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.tsx.html +155 -155
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +255 -255
- package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
- package/coverage/lcov-report/src/contexts/MapContext.tsx.html +66 -66
- package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +1 -1
- package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +48 -48
- package/coverage/lcov-report/src/contexts/index.html +1 -1
- package/coverage/lcov-report/src/hooks/exportMap/index.html +131 -0
- package/coverage/lcov-report/src/hooks/exportMap/index.ts.html +175 -0
- package/coverage/lcov-report/src/hooks/exportMap/lib.ts.html +646 -0
- package/coverage/lcov-report/src/hooks/index.html +48 -18
- package/coverage/lcov-report/src/hooks/useLayer.ts.html +230 -188
- package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +232 -0
- package/coverage/lcov-report/src/hooks/useMap.ts.html +72 -69
- package/coverage/lcov-report/src/hooks/useMapState.ts.html +145 -145
- package/coverage/lcov-report/src/hooks/useSource.ts.html +337 -0
- package/coverage/lcov-report/src/hooks/useWms.js.html +72 -72
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +14 -2
- package/coverage/lcov.info +450 -153
- package/dist/components/MlCreatePdfForm/MlCreatePdfForm.d.ts +24 -0
- package/dist/components/MlCreatePdfForm/MlCreatePdfForm.stories.d.ts +13 -0
- package/dist/components/MlCreatePdfForm/lib/PdfContext.d.ts +21 -0
- package/dist/components/MlCreatePdfForm/lib/PdfForm.d.ts +10 -0
- package/dist/components/MlCreatePdfForm/lib/PdfPreview.d.ts +13 -0
- package/dist/components/MlCreatePdfForm/lib/pdf.templates.d.ts +11 -0
- package/dist/components/MlFeatureEditor/lib/create_vertex.d.ts +1 -1
- package/dist/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.d.ts +22 -0
- package/dist/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.stories.d.ts +10 -0
- package/dist/components/MlLayerSwipe/MlLayerSwipe.d.ts +1 -1
- package/dist/components/MlWmsLayer/MlWmsLayer.d.ts +2 -2
- package/dist/decorators/MapContextDecoratorHooks.d.ts +2 -0
- package/dist/decorators/ThemeWrapper.d.ts +1 -0
- package/dist/hooks/exportMap/index.d.ts +11 -0
- package/dist/hooks/exportMap/lib.d.ts +36 -0
- package/dist/hooks/useLayer.d.ts +6 -5
- package/dist/hooks/useLayerEvent.d.ts +2 -0
- package/dist/hooks/useMap.d.ts +1 -1
- package/dist/hooks/useMapState.stories.d.ts +2 -2
- package/dist/hooks/useSource.d.ts +17 -0
- package/dist/hooks/useSources.stories.d.ts +13 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +479 -190
- package/dist/index.esm.js.map +1 -1
- package/eslintErrorTest.js +10 -0
- package/package.json +7 -1
- package/public/thumbnails/MlCreatePdfForm.png +0 -0
- package/src/components/MapLibreMap/MapLibreMap.stories.js +72 -72
- package/src/components/MapLibreMap/MapLibreMap.test.js +60 -60
- package/src/components/MapLibreMap/MapLibreMap.tsx +82 -82
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.test.js +343 -343
- package/src/components/MapLibreMap/lib/MapLibreGlWrapper.ts +619 -619
- package/src/components/MlBasicComponent.js +25 -25
- package/src/components/MlCenterPosition/MlCenterPosition.stories.js +6 -6
- package/src/components/MlCenterPosition/MlCenterPosition.tsx +65 -65
- package/src/components/MlComponentTemplate/MlComponentTemplate.stories.js +5 -5
- package/src/components/MlComponentTemplate/MlComponentTemplate.tsx +23 -23
- package/src/components/MlCreatePdfButton/{MlCreatePdfButton.meta.json → MlCreatePdfButton.meta_.json} +0 -0
- package/src/components/MlCreatePdfButton/MlCreatePdfButton.stories.js +16 -16
- package/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx +29 -29
- package/src/components/MlCreatePdfButton/lib/createPdf.ts +175 -175
- package/src/components/MlCreatePdfButton/lib/nominatimMap.ts +51 -51
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.doc.de.md +3 -0
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.meta.json +15 -0
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +152 -0
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx +39 -0
- package/src/components/MlCreatePdfForm/lib/PdfContext.tsx +53 -0
- package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +161 -0
- package/src/components/MlCreatePdfForm/lib/PdfPreview.tsx +399 -0
- package/src/components/MlCreatePdfForm/lib/pdf.templates.ts +82 -0
- package/src/components/MlFeatureEditor/MlFeatureEditor.stories.js +55 -55
- package/src/components/MlFeatureEditor/MlFeatureEditor.test.js +105 -105
- package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +119 -119
- package/src/components/MlFeatureEditor/custom-direct-select-mode.js +208 -208
- package/src/components/MlFeatureEditor/custom-polygon-mode.js +148 -148
- package/src/components/MlFeatureEditor/custom-select-mode.js +314 -314
- package/src/components/MlFeatureEditor/lib/common_selectors.js +34 -34
- package/src/components/MlFeatureEditor/lib/constants.js +61 -61
- package/src/components/MlFeatureEditor/lib/constrain_feature_movement.js +51 -51
- package/src/components/MlFeatureEditor/lib/create_midpoint.js +30 -30
- package/src/components/MlFeatureEditor/lib/create_supplementary_points.js +82 -82
- package/src/components/MlFeatureEditor/lib/create_vertex.js +16 -16
- package/src/components/MlFeatureEditor/lib/double_click_zoom.js +23 -23
- package/src/components/MlFeatureEditor/lib/euclidean_distance.js +3 -3
- package/src/components/MlFeatureEditor/lib/features_at.js +23 -23
- package/src/components/MlFeatureEditor/lib/get_features_and_set_cursor.js +15 -15
- package/src/components/MlFeatureEditor/lib/is_click.js +8 -8
- package/src/components/MlFeatureEditor/lib/is_event_at_coordinates.js +2 -2
- package/src/components/MlFeatureEditor/lib/is_tap.js +6 -6
- package/src/components/MlFeatureEditor/lib/map_event_to_bounding_box.js +4 -4
- package/src/components/MlFeatureEditor/lib/mode_handler.js +105 -105
- package/src/components/MlFeatureEditor/lib/mouse_event_point.js +5 -5
- package/src/components/MlFeatureEditor/lib/move_features.js +33 -33
- package/src/components/MlFeatureEditor/lib/sort_features.js +25 -25
- package/src/components/MlFeatureEditor/lib/string_set.js +36 -36
- package/src/components/MlFeatureEditor/lib/string_sets_are_equal.js +2 -2
- package/src/components/MlFeatureEditor/lib/theme.js +230 -230
- package/src/components/MlFeatureEditor/lib/to_dense_array.js +1 -1
- package/src/components/MlFeatureEditor/lib/utils.js +40 -40
- package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.stories.js +9 -9
- package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.test.js +4 -4
- package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx +65 -65
- package/src/components/MlFollowGps/MlFollowGps.stories.js +6 -6
- package/src/components/MlFollowGps/MlFollowGps.test.js +44 -44
- package/src/components/MlFollowGps/MlFollowGps.tsx +220 -220
- package/src/components/MlGPXViewer/MlGPXViewer.stories.js +15 -15
- package/src/components/MlGPXViewer/MlGPXViewer.test.js +12 -12
- package/src/components/MlGPXViewer/MlGPXViewer.tsx +345 -345
- package/src/components/MlGPXViewer/gpxConverter.js +496 -496
- package/src/components/MlGPXViewer/util/GeoJsonContext.ts +4 -4
- package/src/components/MlGPXViewer/util/GeoJsonProvider.tsx +16 -16
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +34 -34
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.test.js +8 -8
- package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +84 -84
- package/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.ts +21 -21
- package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.ts +27 -27
- package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.doc.de.md +3 -0
- package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.meta_.json +15 -0
- package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.stories.js +19 -0
- package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx +128 -0
- package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.stories.js +28 -28
- package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.test.js +8 -8
- package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx +162 -162
- package/src/components/MlLayer/MlLayer.stories.js +5 -5
- package/src/components/MlLayer/MlLayer.test.js +86 -86
- package/src/components/MlLayer/MlLayer.tsx +36 -36
- package/src/components/MlLayerMagnify/MlLayerMagnify.stories.js +21 -21
- package/src/components/MlLayerMagnify/MlLayerMagnify.test.js +54 -54
- package/src/components/MlLayerMagnify/MlLayerMagnify.tsx +201 -201
- package/src/components/MlLayerSwipe/MlLayerSwipe.stories.js +20 -20
- package/src/components/MlLayerSwipe/MlLayerSwipe.test.js +54 -54
- package/src/components/MlLayerSwipe/MlLayerSwipe.tsx +130 -130
- package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +194 -194
- package/src/components/MlLayerSwitcher/MlLayerSwitcher.stories.js +85 -85
- package/src/components/MlLayerSwitcher/components/LayerBox.js +57 -57
- package/src/components/MlMarker/MlMarker.stories.js +7 -7
- package/src/components/MlMarker/MlMarker.tsx +119 -119
- package/src/components/MlMeasureTool/MlMeasureTool.stories.js +64 -64
- package/src/components/MlMeasureTool/MlMeasureTool.tsx +38 -38
- package/src/components/MlNavigationCompass/MlNavigationCompass.stories.js +45 -45
- package/src/components/MlNavigationCompass/MlNavigationCompass.test.js +40 -40
- package/src/components/MlNavigationCompass/MlNavigationCompass.tsx +192 -192
- package/src/components/MlNavigationTools/MlNavigationTools.stories.js +18 -18
- package/src/components/MlNavigationTools/MlNavigationTools.tsx +173 -173
- package/src/components/MlOsmLayer/MlOsmLayer.js +49 -49
- package/src/components/MlOsmLayer/MlOsmLayer.stories_.js +29 -29
- package/src/components/MlOsmLayer/MlOsmLayer.test.js +8 -8
- package/src/components/MlScaleReference/MlScaleReference.js +82 -82
- package/src/components/MlScaleReference/MlScaleReference.stories.js +33 -35
- package/src/components/MlShareMapState/MlShareMapState.js +203 -203
- package/src/components/MlShareMapState/MlShareMapState.stories.js +68 -68
- package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js +201 -201
- package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.stories.js +35 -35
- package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.test.js +8 -8
- package/src/components/MlThreeJsLayer/MlThreeJsLayer.js +186 -186
- package/src/components/MlThreeJsLayer/MlThreeJsLayer.stories.js +21 -21
- package/src/components/MlThreeJsLayer/MlThreeJsLayer.test.js +24 -24
- package/src/components/MlThreeJsLayer/lib/GLTFLoader.js +3327 -3327
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.stories.js +31 -30
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.test.js +8 -8
- package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx +146 -146
- package/src/components/MlTransitionGeoJsonLayer/util/transitionFunctions.js +207 -207
- package/src/components/MlUseMapDebugger/MlUseMapDebugger.js +52 -52
- package/src/components/MlUseMapDebugger/MlUseMapDebugger.stories.js +13 -13
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.stories.js +27 -27
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.test.js +27 -27
- package/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx +137 -137
- package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js +34 -34
- package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.stories.js +7 -7
- package/src/components/MlWmsLayer/MlWmsLayer.stories.js +26 -26
- package/src/components/MlWmsLayer/MlWmsLayer.test.js +8 -8
- package/src/components/MlWmsLayer/MlWmsLayer.tsx +167 -167
- package/src/components/MlWmsLoader/MlWmsLoader.stories.js +27 -27
- package/src/components/MlWmsLoader/MlWmsLoader.tsx +254 -254
- package/src/contexts/MapComponentsProvider.test.js +229 -229
- package/src/contexts/MapContext.tsx +65 -65
- package/src/contexts/SimpleDataProvider.js +47 -47
- package/src/contexts/SimpleDataProvider.test.js +29 -29
- package/src/custom.d.tsx +14 -14
- package/src/decorators/MapContextDecorator.js +23 -25
- package/src/decorators/MapContextDecoratorHooks.js +34 -0
- package/src/decorators/MultiMapContextDecorator.js +63 -63
- package/src/decorators/NoNavToolsDecorator.js +17 -17
- package/src/decorators/ThemeWrapper.jsx +9 -0
- package/src/hooks/assets/pointWG.json +13 -0
- package/src/hooks/exportMap/index.ts +30 -0
- package/src/hooks/exportMap/lib.ts +187 -0
- package/src/hooks/useLayer.test.js +188 -188
- package/src/hooks/useLayer.ts +194 -180
- package/src/hooks/useLayerEvent.js +49 -0
- package/src/hooks/useMap.ts +67 -66
- package/src/hooks/useMapState.stories.js +78 -78
- package/src/hooks/useMapState.ts +161 -161
- package/src/hooks/useSource.ts +84 -0
- package/src/hooks/useSources.stories.js +232 -0
- package/src/hooks/useWms.js +71 -71
- package/src/index.ts +4 -0
- package/src/setupTests.js +86 -86
- package/src/ui_components/ImageLoader.js +62 -62
- package/src/ui_components/Legend.js +34 -34
- package/src/ui_components/LoadingOverlay.js +29 -29
- package/src/ui_components/LoadingOverlayContext.js +68 -68
- package/src/ui_components/Sidebar.js +80 -80
- package/src/ui_components/Tooltip.js +9 -9
- package/src/ui_components/TopToolbar.js +23 -23
- package/src/util/layerRemovalTest.js +111 -111
- package/src/util/sourceRemovalTest.js +103 -103
package/src/hooks/useLayer.ts
CHANGED
|
@@ -1,198 +1,212 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef } from
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import useMap, { useMapType } from
|
|
3
|
+
import useMap, { useMapType } from './useMap';
|
|
4
4
|
|
|
5
|
-
import { LayerSpecification } from
|
|
5
|
+
import { SourceSpecification, LayerSpecification } from 'maplibre-gl';
|
|
6
6
|
|
|
7
|
-
import MapLibreGlWrapper from
|
|
7
|
+
import MapLibreGlWrapper from '../components/MapLibreMap/lib/MapLibreGlWrapper';
|
|
8
8
|
|
|
9
|
-
import { MapLayerMouseEvent } from
|
|
10
|
-
import { GeoJSONObject } from
|
|
9
|
+
import { MapLayerMouseEvent } from 'maplibre-gl';
|
|
10
|
+
import { GeoJSONObject } from '@turf/turf';
|
|
11
11
|
|
|
12
12
|
type useLayerType = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
map: MapLibreGlWrapper | undefined;
|
|
14
|
+
layer: LayerSpecification;
|
|
15
|
+
layerId: string;
|
|
16
|
+
componentId: string;
|
|
17
|
+
mapHook: useMapType;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
interface useLayerProps {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
mapId?: string;
|
|
22
|
+
layerId?: string;
|
|
23
|
+
idPrefix?: string;
|
|
24
|
+
insertBeforeLayer?: string;
|
|
25
|
+
insertBeforeFirstSymbolLayer?: boolean;
|
|
26
|
+
geojson?: GeoJSONObject;
|
|
27
|
+
source?: SourceSpecification | string;
|
|
28
|
+
options: Partial<LayerSpecification>;
|
|
29
|
+
onHover?: MapLayerMouseEvent;
|
|
30
|
+
onClick?: MapLayerMouseEvent;
|
|
31
|
+
onLeave?: MapLayerMouseEvent;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const legalLayerTypes = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
'fill',
|
|
36
|
+
'line',
|
|
37
|
+
'symbol',
|
|
38
|
+
'circle',
|
|
39
|
+
'heatmap',
|
|
40
|
+
'fill-extrusion',
|
|
41
|
+
'raster',
|
|
42
|
+
'hillshade',
|
|
43
|
+
'background',
|
|
43
44
|
];
|
|
44
45
|
|
|
45
46
|
function useLayer(props: useLayerProps): useLayerType {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
47
|
+
const mapHook = useMap({
|
|
48
|
+
mapId: props.mapId,
|
|
49
|
+
waitForLayer: props.insertBeforeLayer,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const layerTypeRef = useRef<string>('');
|
|
53
|
+
const layerPaintConfRef = useRef<string>('');
|
|
54
|
+
const layerLayoutConfRef = useRef<string>('');
|
|
55
|
+
|
|
56
|
+
const [layer, setLayer] = useState<any>();
|
|
57
|
+
|
|
58
|
+
const initializedRef = useRef<boolean>(false);
|
|
59
|
+
const layerId = useRef(
|
|
60
|
+
props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const createLayer = useCallback(() => {
|
|
64
|
+
if (!mapHook.map) return;
|
|
65
|
+
|
|
66
|
+
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
67
|
+
mapHook.cleanup();
|
|
68
|
+
}
|
|
69
|
+
if (mapHook.map.map.getSource(layerId.current)) {
|
|
70
|
+
mapHook.map.map.removeSource(layerId.current);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof props.source === 'string') {
|
|
74
|
+
if (props.source === '' || !mapHook.map.map.getSource(props.source)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
initializedRef.current = true;
|
|
80
|
+
|
|
81
|
+
mapHook.map.addLayer(
|
|
82
|
+
{
|
|
83
|
+
...props.options,
|
|
84
|
+
...(props.geojson && !props.source
|
|
85
|
+
? {
|
|
86
|
+
source: {
|
|
87
|
+
type: 'geojson',
|
|
88
|
+
data: props.geojson,
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
: {}),
|
|
92
|
+
...(props.source
|
|
93
|
+
? {
|
|
94
|
+
source: props.source,
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
id: layerId.current,
|
|
98
|
+
},
|
|
99
|
+
props.insertBeforeLayer
|
|
100
|
+
? props.insertBeforeLayer
|
|
101
|
+
: props.insertBeforeFirstSymbolLayer
|
|
102
|
+
? mapHook.map.firstSymbolLayer
|
|
103
|
+
: undefined,
|
|
104
|
+
mapHook.componentId
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
setLayer(mapHook.map.map.getLayer(layerId.current));
|
|
108
|
+
|
|
109
|
+
if (typeof props.onHover !== 'undefined') {
|
|
110
|
+
mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (typeof props.onClick !== 'undefined') {
|
|
114
|
+
mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (typeof props.onLeave !== 'undefined') {
|
|
118
|
+
mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// recreate layer if style has changed
|
|
122
|
+
mapHook.map.on(
|
|
123
|
+
'styledata',
|
|
124
|
+
() => {
|
|
125
|
+
if (initializedRef.current && !mapHook.map?.map.getLayer(layerId.current)) {
|
|
126
|
+
console.log('Recreate Layer');
|
|
127
|
+
createLayer();
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
mapHook.componentId
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
layerPaintConfRef.current = JSON.stringify(props.options?.paint);
|
|
134
|
+
layerLayoutConfRef.current = JSON.stringify(props.options?.layout);
|
|
135
|
+
layerTypeRef.current = props.options.type as LayerSpecification['type'];
|
|
136
|
+
}, [props, mapHook.map]);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (!mapHook.map) return;
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
initializedRef.current &&
|
|
143
|
+
(legalLayerTypes.indexOf(props.options.type as LayerSpecification['type']) === -1 ||
|
|
144
|
+
(legalLayerTypes.indexOf(props.options.type as LayerSpecification['type']) !== -1 &&
|
|
145
|
+
props.options.type === layerTypeRef.current))
|
|
146
|
+
) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
createLayer();
|
|
151
|
+
}, [mapHook.map, props.options, createLayer]);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!initializedRef.current || !mapHook.map?.map?.getSource(layerId.current)) return;
|
|
155
|
+
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
157
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
158
|
+
mapHook.map.map.getSource(layerId.current)?.setData?.(props.geojson);
|
|
159
|
+
}, [props.geojson, mapHook.map, props.options.type]);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (
|
|
163
|
+
!mapHook.map ||
|
|
164
|
+
!mapHook.map?.map?.getLayer?.(layerId.current) ||
|
|
165
|
+
!initializedRef.current ||
|
|
166
|
+
props.options.type !== layerTypeRef.current
|
|
167
|
+
)
|
|
168
|
+
return;
|
|
169
|
+
|
|
170
|
+
let key;
|
|
171
|
+
|
|
172
|
+
const layoutString = JSON.stringify(props.options.layout);
|
|
173
|
+
if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
|
|
174
|
+
const oldLayout = JSON.parse(layerLayoutConfRef.current);
|
|
175
|
+
|
|
176
|
+
for (key in props.options.layout) {
|
|
177
|
+
if (props.options.layout?.[key] && props.options.layout[key] !== oldLayout[key]) {
|
|
178
|
+
mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
layerLayoutConfRef.current = layoutString;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const paintString = JSON.stringify(props.options.paint);
|
|
185
|
+
if (paintString !== layerPaintConfRef.current) {
|
|
186
|
+
const oldPaint = JSON.parse(layerPaintConfRef.current);
|
|
187
|
+
for (key in props.options.paint) {
|
|
188
|
+
if (props.options.paint?.[key] && props.options.paint[key] !== oldPaint[key]) {
|
|
189
|
+
mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
layerPaintConfRef.current = paintString;
|
|
193
|
+
}
|
|
194
|
+
}, [props.options, mapHook.map]);
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
return () => {
|
|
198
|
+
initializedRef.current = false;
|
|
199
|
+
mapHook.cleanup();
|
|
200
|
+
};
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
map: mapHook.map,
|
|
205
|
+
layer: layer,
|
|
206
|
+
layerId: layerId.current,
|
|
207
|
+
componentId: mapHook.componentId,
|
|
208
|
+
mapHook: mapHook,
|
|
209
|
+
};
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
export default useLayer;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import useMapState from './useMapState';
|
|
4
|
+
import useMap from './useMap';
|
|
5
|
+
|
|
6
|
+
const touchEquivalents = {
|
|
7
|
+
mousedown: 'touchstart',
|
|
8
|
+
mouseup: 'touchend',
|
|
9
|
+
mousemove: 'touchmove',
|
|
10
|
+
};
|
|
11
|
+
const touchEquivalentsKeys = Object.keys(touchEquivalents);
|
|
12
|
+
function useLayerEvent(props) {
|
|
13
|
+
const mapState = useMapState({ mapId: props.mapId, watch: { layers: true } });
|
|
14
|
+
const mapHook = useMap({ mapId: props.mapId });
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!mapHook.map) return true;
|
|
18
|
+
if (typeof props.condition !== 'undefined' && props.condition === false) return;
|
|
19
|
+
//console.log('useLayerEvent');
|
|
20
|
+
//console.log(mapState);
|
|
21
|
+
|
|
22
|
+
if (mapHook.map.map.getLayer(props.layerId)) {
|
|
23
|
+
//console.log("layer avail");
|
|
24
|
+
var _event = props.event;
|
|
25
|
+
var _layerId = props.layerId;
|
|
26
|
+
var _eventHandler = props.eventHandler;
|
|
27
|
+
|
|
28
|
+
//console.log(_event);
|
|
29
|
+
mapHook.map.on(_event, _layerId, _eventHandler, mapHook.componentId);
|
|
30
|
+
if (props?.addTouchEvents === true) {
|
|
31
|
+
if (touchEquivalentsKeys.indexOf(_event) !== -1) {
|
|
32
|
+
mapHook.map.on(touchEquivalents[_event], _layerId, _eventHandler, mapHook.componentId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
mapHook.map.off(_event, _layerId, _eventHandler);
|
|
37
|
+
if (props?.addTouchEvents === true) {
|
|
38
|
+
if (touchEquivalentsKeys.indexOf(_event) !== -1) {
|
|
39
|
+
mapHook.map.off(touchEquivalents[_event], _layerId, _eventHandler, mapHook.componentId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}, [props, mapState, mapHook.map]);
|
|
45
|
+
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default useLayerEvent;
|
package/src/hooks/useMap.ts
CHANGED
|
@@ -1,88 +1,89 @@
|
|
|
1
|
-
import { useContext, useState, useEffect, useRef
|
|
1
|
+
import { useContext, useState, useEffect, useRef } from "react";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import MapContext from "../contexts/MapContext";
|
|
4
4
|
import useMapState from "./useMapState";
|
|
5
5
|
import MapLibreGlWrapper, { LayerState } from "../components/MapLibreMap/lib/MapLibreGlWrapper";
|
|
6
6
|
|
|
7
7
|
type useMapType = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
map: MapLibreGlWrapper | undefined;
|
|
9
|
+
mapIsReady: boolean;
|
|
10
|
+
componentId: string;
|
|
11
|
+
layers: (LayerState | undefined)[];
|
|
12
|
+
cleanup: () => void;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function useMap(props: { mapId?: string; waitForLayer?: string }): useMapType {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
17
|
+
const mapContext: MapContextType = useContext(MapContext);
|
|
18
|
+
const [map, setMap] = useState<MapLibreGlWrapper>();
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
const mapState = useMapState({
|
|
21
|
+
mapId: props.mapId,
|
|
22
|
+
watch: {
|
|
23
|
+
viewport: false,
|
|
24
|
+
layers: props.waitForLayer ? true : false,
|
|
25
|
+
sources: false,
|
|
26
|
+
},
|
|
27
|
+
filter: {
|
|
28
|
+
includeBaseLayers: true,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
const mapRef: MutableRefObject<MapLibreGlWrapper | undefined> = useRef(undefined);
|
|
32
|
+
const initializedRef = useRef(false);
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
const mapRef = useRef<MapLibreGlWrapper>();
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
const componentId = useRef(uuidv4());
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
if (mapRef.current) {
|
|
41
|
-
mapRef.current.cleanup(componentId.current);
|
|
42
|
-
mapRef.current = undefined;
|
|
43
|
-
}
|
|
44
|
-
initializedRef.current = false;
|
|
45
|
-
};
|
|
38
|
+
const [mapIsReady, setMapIsReady] = useState(false);
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
const cleanup = () => {
|
|
41
|
+
if (mapRef.current) {
|
|
42
|
+
mapRef.current.cleanup(componentId.current);
|
|
43
|
+
}
|
|
44
|
+
initializedRef.current = false;
|
|
45
|
+
};
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
cleanup();
|
|
50
|
+
setMapIsReady(false);
|
|
51
|
+
mapRef.current = undefined;
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (props.waitForLayer) {
|
|
60
|
-
let layerFound = false;
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
if (!layerFound) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
|
|
72
|
-
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
73
|
-
initializedRef.current = true;
|
|
74
|
-
mapRef.current = mapContext.getMap(props.mapId);
|
|
75
|
-
setMap(mapRef.current);
|
|
76
|
-
setMapIsReady(true);
|
|
77
|
-
}, [mapContext.mapIds, mapState.layers, mapContext, props.waitForLayer, props.mapId]);
|
|
58
|
+
// check if waitForLayer (string, layer id of the layer this hook is supposed to wait for)
|
|
59
|
+
// exists as layer in the MapLibre instance
|
|
60
|
+
if (props.waitForLayer) {
|
|
61
|
+
let layerFound = false;
|
|
78
62
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
mapState?.layers?.forEach((layer: any) => {
|
|
64
|
+
if (layer.id === props.waitForLayer) {
|
|
65
|
+
layerFound = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (!layerFound) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
|
|
73
|
+
// initialize the layer and add it to the MapLibre-gl instance or do something else with it
|
|
74
|
+
initializedRef.current = true;
|
|
75
|
+
mapRef.current = mapContext.getMap(props.mapId);
|
|
76
|
+
setMap(mapRef.current);
|
|
77
|
+
setMapIsReady(true);
|
|
78
|
+
}, [mapContext.mapIds, mapState.layers, mapContext, props.waitForLayer, props.mapId]);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
map: map,
|
|
82
|
+
mapIsReady,
|
|
83
|
+
componentId: componentId.current,
|
|
84
|
+
layers: mapState.layers,
|
|
85
|
+
cleanup,
|
|
86
|
+
};
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
export default useMap;
|