@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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PdfPreview from './lib/PdfPreview';
|
|
3
|
+
import PdfForm from './lib/PdfForm';
|
|
4
|
+
import { PdfContextProvider } from './lib/PdfContext';
|
|
5
|
+
import { createPdfResolverParams } from '../../hooks/exportMap/lib';
|
|
6
|
+
import { SxProps } from '@mui/material';
|
|
7
|
+
|
|
8
|
+
interface MlCreatePdfFormProps {
|
|
9
|
+
/**
|
|
10
|
+
* Id of the target MapLibre instance in mapContext
|
|
11
|
+
*/
|
|
12
|
+
mapId?: string;
|
|
13
|
+
formControlStyles?: SxProps;
|
|
14
|
+
onCreatePdf?: (options:createPdfResolverParams) => createPdfResolverParams;
|
|
15
|
+
excludeLayerIds?: Array<string>;
|
|
16
|
+
includeLayerIds?: Array<string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { MlCreatePdfFormProps };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create PDF Form Component
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
const MlCreatePdfForm = (props: MlCreatePdfFormProps) => {
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<PdfContextProvider>
|
|
29
|
+
<PdfForm {...props} />
|
|
30
|
+
<PdfPreview />
|
|
31
|
+
</PdfContextProvider>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
MlCreatePdfForm.defaultProps = {
|
|
37
|
+
mapId: undefined,
|
|
38
|
+
};
|
|
39
|
+
export default MlCreatePdfForm;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { useState, useRef, useMemo, MutableRefObject } from 'react';
|
|
2
|
+
import templates from './pdf.templates';
|
|
3
|
+
import { Feature } from '@turf/turf';
|
|
4
|
+
|
|
5
|
+
interface PdfContextInterface {
|
|
6
|
+
format: string;
|
|
7
|
+
setFormat: (format: string) => void;
|
|
8
|
+
quality: string;
|
|
9
|
+
setQuality: (quality: string) => void;
|
|
10
|
+
orientation: string;
|
|
11
|
+
setOrientation: (orientation: string) => void;
|
|
12
|
+
geojsonRef: MutableRefObject<Feature | undefined>;
|
|
13
|
+
template: { width: number; height: number };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const PdfContext = React.createContext<Partial<PdfContextInterface>>({});
|
|
17
|
+
|
|
18
|
+
const defaultTemplate = templates['A4']['72dpi'];
|
|
19
|
+
const PdfContextProvider = ({ children }: { children: React.ReactNode }) => {
|
|
20
|
+
const [format, setFormat] = useState('A4');
|
|
21
|
+
const [quality, setQuality] = useState('72dpi');
|
|
22
|
+
const [orientation, setOrientation] = useState('portrait');
|
|
23
|
+
|
|
24
|
+
const geojsonRef = useRef();
|
|
25
|
+
|
|
26
|
+
const template = useMemo(() => {
|
|
27
|
+
if (typeof templates[format][quality] !== 'undefined') {
|
|
28
|
+
return orientation === 'portrait'
|
|
29
|
+
? templates[format][quality]
|
|
30
|
+
: {
|
|
31
|
+
width: templates[format][quality].height,
|
|
32
|
+
height: templates[format][quality].width,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return defaultTemplate;
|
|
36
|
+
}, [format, quality, orientation]);
|
|
37
|
+
|
|
38
|
+
const value = {
|
|
39
|
+
format,
|
|
40
|
+
setFormat,
|
|
41
|
+
quality,
|
|
42
|
+
setQuality,
|
|
43
|
+
orientation,
|
|
44
|
+
setOrientation,
|
|
45
|
+
geojsonRef,
|
|
46
|
+
template,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return <PdfContext.Provider value={value}>{children}</PdfContext.Provider>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { PdfContextProvider };
|
|
53
|
+
export default PdfContext;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React, { useContext, useMemo, useCallback } from 'react';
|
|
2
|
+
import PdfContext from './PdfContext';
|
|
3
|
+
import {
|
|
4
|
+
FormControl,
|
|
5
|
+
MenuItem,
|
|
6
|
+
Select,
|
|
7
|
+
InputLabel,
|
|
8
|
+
Button,
|
|
9
|
+
FormLabel,
|
|
10
|
+
FormControlLabel,
|
|
11
|
+
Radio,
|
|
12
|
+
RadioGroup,
|
|
13
|
+
} from '@mui/material';
|
|
14
|
+
|
|
15
|
+
import useMap from '../../../hooks/useMap';
|
|
16
|
+
import exportMap from '../../../hooks/exportMap';
|
|
17
|
+
import { createPdfResolverParams } from '../../../hooks/exportMap/lib';
|
|
18
|
+
|
|
19
|
+
import * as turf from '@turf/turf';
|
|
20
|
+
|
|
21
|
+
import templates from './pdf.templates';
|
|
22
|
+
|
|
23
|
+
const qualityOptions = [
|
|
24
|
+
{
|
|
25
|
+
value: '72dpi',
|
|
26
|
+
label: 'Draft (72dpi)',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
value: '150dpi',
|
|
30
|
+
label: 'Medium (150dpi)',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: '300dpi',
|
|
34
|
+
label: 'High (300dpi)',
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
interface PdfFormProps {
|
|
39
|
+
/**
|
|
40
|
+
* Id of the target MapLibre instance in mapContext
|
|
41
|
+
*/
|
|
42
|
+
mapId?: string;
|
|
43
|
+
onCreatePdf?: (options:createPdfResolverParams) => createPdfResolverParams;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function PdfForm(props:PdfFormProps) {
|
|
47
|
+
const pdfContext = useContext(PdfContext);
|
|
48
|
+
const mapHook = useMap({
|
|
49
|
+
// eslint-disable-next-line react/prop-types
|
|
50
|
+
mapId: props.mapId,
|
|
51
|
+
});
|
|
52
|
+
const mapExporter = exportMap({ mapId: props.mapId });
|
|
53
|
+
|
|
54
|
+
const createPdfHandler = useCallback(() => {
|
|
55
|
+
if (
|
|
56
|
+
mapHook.map &&
|
|
57
|
+
mapExporter.createExport &&
|
|
58
|
+
pdfContext.template &&
|
|
59
|
+
pdfContext.format &&
|
|
60
|
+
pdfContext.orientation &&
|
|
61
|
+
pdfContext.geojsonRef?.current?.bbox &&
|
|
62
|
+
pdfContext.geojsonRef?.current
|
|
63
|
+
) {
|
|
64
|
+
const bbox = turf.bbox(pdfContext.geojsonRef.current);
|
|
65
|
+
|
|
66
|
+
mapExporter
|
|
67
|
+
.createExport({
|
|
68
|
+
width: pdfContext.template.width,
|
|
69
|
+
height: pdfContext.template.height,
|
|
70
|
+
bbox: bbox,
|
|
71
|
+
bboxUnrotated: pdfContext.geojsonRef.current.bbox,
|
|
72
|
+
bearing: pdfContext.geojsonRef.current?.properties?.bearing || 0,
|
|
73
|
+
format: pdfContext.format.toLowerCase(),
|
|
74
|
+
orientation: pdfContext.orientation,
|
|
75
|
+
})
|
|
76
|
+
.then((res) => res.createPdf())
|
|
77
|
+
.then((res) => {
|
|
78
|
+
if (typeof props.onCreatePdf === 'function') {
|
|
79
|
+
props.onCreatePdf(res);
|
|
80
|
+
}
|
|
81
|
+
return res.downloadPdf();
|
|
82
|
+
})
|
|
83
|
+
.catch((error) => {
|
|
84
|
+
console.log(error);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, [mapHook.map, pdfContext]);
|
|
88
|
+
|
|
89
|
+
const formControlStyles = useMemo(
|
|
90
|
+
() => {
|
|
91
|
+
return {
|
|
92
|
+
margin: '5px 0 15px 0 ',
|
|
93
|
+
//...props.formControlStyles,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
[
|
|
97
|
+
/*props.formControlStyles*/
|
|
98
|
+
]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
<FormControl fullWidth sx={formControlStyles}>
|
|
104
|
+
<InputLabel id="format-select-label">Format</InputLabel>
|
|
105
|
+
<Select
|
|
106
|
+
labelId="format-select-label"
|
|
107
|
+
id="format-select"
|
|
108
|
+
label="Format"
|
|
109
|
+
value={pdfContext.format}
|
|
110
|
+
onChange={(event) => {
|
|
111
|
+
pdfContext.setFormat?.(event.target.value);
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{Object.keys(templates).map((el) => (
|
|
115
|
+
<MenuItem key={el} value={el}>
|
|
116
|
+
{el}
|
|
117
|
+
</MenuItem>
|
|
118
|
+
))}
|
|
119
|
+
</Select>
|
|
120
|
+
</FormControl>
|
|
121
|
+
<FormControl fullWidth sx={formControlStyles}>
|
|
122
|
+
<FormLabel id="orientation-radio-buttons-group-label">Orientation</FormLabel>
|
|
123
|
+
<RadioGroup
|
|
124
|
+
row
|
|
125
|
+
aria-labelledby="orientation-radio-buttons-group-label"
|
|
126
|
+
name="orientation-radio-buttons-group"
|
|
127
|
+
value={pdfContext.orientation}
|
|
128
|
+
onChange={(event) => {
|
|
129
|
+
pdfContext.setOrientation?.(event.target.value);
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<FormControlLabel value="portrait" control={<Radio />} label="Portrait" />
|
|
133
|
+
<FormControlLabel value="landscape" control={<Radio />} label="Landscape" />
|
|
134
|
+
</RadioGroup>
|
|
135
|
+
</FormControl>
|
|
136
|
+
<FormControl fullWidth sx={formControlStyles}>
|
|
137
|
+
<InputLabel id="quality-select-label">Quality</InputLabel>
|
|
138
|
+
<Select
|
|
139
|
+
labelId="quality-select-label"
|
|
140
|
+
id="quality-select"
|
|
141
|
+
label="Qualität"
|
|
142
|
+
value={pdfContext.quality}
|
|
143
|
+
onChange={(event) => {
|
|
144
|
+
pdfContext.setQuality?.(event.target.value);
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{qualityOptions.map((el) => (
|
|
148
|
+
<MenuItem key={el.value} value={el.value}>
|
|
149
|
+
{el.label}
|
|
150
|
+
</MenuItem>
|
|
151
|
+
))}
|
|
152
|
+
</Select>
|
|
153
|
+
</FormControl>
|
|
154
|
+
<FormControl fullWidth sx={formControlStyles}>
|
|
155
|
+
<Button variant="contained" onClick={createPdfHandler}>
|
|
156
|
+
PDF erstellen
|
|
157
|
+
</Button>
|
|
158
|
+
</FormControl>
|
|
159
|
+
</>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import React, { useContext, useRef, useState, useEffect } from 'react';
|
|
2
|
+
import MlGeoJsonLayer from '../../MlGeoJsonLayer/MlGeoJsonLayer';
|
|
3
|
+
import * as turf from '@turf/turf';
|
|
4
|
+
import useMap from '../../../hooks/useMap';
|
|
5
|
+
import useLayerEvent from '../../../hooks/useLayerEvent';
|
|
6
|
+
import { BBox, Feature, Polygon } from '@turf/turf';
|
|
7
|
+
import PdfContext from './PdfContext';
|
|
8
|
+
import { MapMouseEvent, MapTouchEvent, MapLayerMouseEvent, LngLat } from 'maplibre-gl';
|
|
9
|
+
|
|
10
|
+
const createPreviewGeojson = (
|
|
11
|
+
geojsonProps: { center: LngLat; distance: number; bearing: number },
|
|
12
|
+
orientation: string
|
|
13
|
+
) => {
|
|
14
|
+
const topLeftAngle = orientation === 'portrait' ? -35.3 : -54.7;
|
|
15
|
+
const bottomRightAngle = orientation === 'portrait' ? 144.7 : 125.3;
|
|
16
|
+
const topLeft = turf.destination(
|
|
17
|
+
[geojsonProps.center.lng, geojsonProps.center.lat],
|
|
18
|
+
geojsonProps.distance,
|
|
19
|
+
topLeftAngle
|
|
20
|
+
);
|
|
21
|
+
const bottomRight = turf.destination(
|
|
22
|
+
[geojsonProps.center.lng, geojsonProps.center.lat],
|
|
23
|
+
geojsonProps.distance,
|
|
24
|
+
bottomRightAngle
|
|
25
|
+
);
|
|
26
|
+
const bbox = [
|
|
27
|
+
topLeft.geometry.coordinates[0],
|
|
28
|
+
topLeft.geometry.coordinates[1],
|
|
29
|
+
bottomRight.geometry.coordinates[0],
|
|
30
|
+
bottomRight.geometry.coordinates[1],
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
let _previewGeojson = turf.bboxPolygon(bbox as BBox);
|
|
34
|
+
_previewGeojson = turf.transformRotate(_previewGeojson, geojsonProps.bearing);
|
|
35
|
+
if (!_previewGeojson?.properties) {
|
|
36
|
+
_previewGeojson.properties = {};
|
|
37
|
+
}
|
|
38
|
+
_previewGeojson.properties.bearing = geojsonProps.bearing;
|
|
39
|
+
return _previewGeojson;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
interface PdfPreviewProps {
|
|
43
|
+
/**
|
|
44
|
+
* Id of the target MapLibre instance in mapContext
|
|
45
|
+
*/
|
|
46
|
+
mapId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Id of an existing layer in the mapLibre instance to help specify the layer order
|
|
49
|
+
* This layer will be visually beneath the layer with the "insertBeforeLayer" id.
|
|
50
|
+
*/
|
|
51
|
+
insertBeforeLayer?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface geojsonProps {
|
|
55
|
+
center: { lng: number; lat: number };
|
|
56
|
+
distance: number;
|
|
57
|
+
bearing: number;
|
|
58
|
+
geojson: Feature<Polygon> | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function PdfPreview(props: PdfPreviewProps) {
|
|
62
|
+
const pdfContext = useContext(PdfContext);
|
|
63
|
+
const initializedRef = useRef(false);
|
|
64
|
+
const activeFeature = useRef();
|
|
65
|
+
|
|
66
|
+
const dragging = useRef(false);
|
|
67
|
+
|
|
68
|
+
const draggingResizeHandle = useRef(false);
|
|
69
|
+
|
|
70
|
+
const draggingRotationHandle = useRef(false);
|
|
71
|
+
|
|
72
|
+
const [geojsonProps, setGeojsonProps] = useState<geojsonProps>({
|
|
73
|
+
center: { lng: 0, lat: 0 },
|
|
74
|
+
distance: 10,
|
|
75
|
+
bearing: 0,
|
|
76
|
+
geojson: undefined,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const mapHook = useMap({
|
|
80
|
+
mapId: props.mapId,
|
|
81
|
+
waitForLayer: props.insertBeforeLayer,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (
|
|
86
|
+
!mapHook.map ||
|
|
87
|
+
!pdfContext.geojsonRef ||
|
|
88
|
+
!pdfContext.orientation ||
|
|
89
|
+
!pdfContext.template ||
|
|
90
|
+
initializedRef.current
|
|
91
|
+
)
|
|
92
|
+
return;
|
|
93
|
+
|
|
94
|
+
initializedRef.current = true;
|
|
95
|
+
|
|
96
|
+
const center = mapHook.map.map.getCenter();
|
|
97
|
+
const canvasHeight = mapHook.map.map._canvas.height;
|
|
98
|
+
const canvasWidth = mapHook.map.map._canvas.width;
|
|
99
|
+
const bboxPixelHeight = Math.ceil(canvasHeight / 2);
|
|
100
|
+
const bboxPixelWidth = Math.ceil(
|
|
101
|
+
(pdfContext.template.width / pdfContext.template.height) * bboxPixelHeight
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const topLeft = mapHook.map.map.unproject([
|
|
105
|
+
Math.floor(canvasWidth / 2 - bboxPixelWidth / 2),
|
|
106
|
+
Math.floor(canvasHeight / 2 - bboxPixelHeight / 2),
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
const distance = turf.distance([center.lng, center.lat], [topLeft.lng, topLeft.lat]);
|
|
110
|
+
|
|
111
|
+
const tmpGeojsonProps = {
|
|
112
|
+
center,
|
|
113
|
+
distance,
|
|
114
|
+
bearing: 0,
|
|
115
|
+
geojson: createPreviewGeojson({ center, distance, bearing: 0 }, pdfContext.orientation),
|
|
116
|
+
};
|
|
117
|
+
setGeojsonProps(tmpGeojsonProps);
|
|
118
|
+
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
119
|
+
}, [mapHook.map]);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (!pdfContext.orientation || !pdfContext.geojsonRef) return;
|
|
123
|
+
|
|
124
|
+
const tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
125
|
+
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
126
|
+
setGeojsonProps(tmpGeojsonProps);
|
|
127
|
+
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
128
|
+
}, [pdfContext.orientation]);
|
|
129
|
+
|
|
130
|
+
// Resize handle events
|
|
131
|
+
useLayerEvent({
|
|
132
|
+
event: 'mouseenter',
|
|
133
|
+
layerId: 'pdfPreviewGeojsonResizeHandle',
|
|
134
|
+
eventHandler: function () {
|
|
135
|
+
if (!mapHook.map) return;
|
|
136
|
+
|
|
137
|
+
mapHook.map.map._canvas.style.cursor = 'nwse-resize';
|
|
138
|
+
mapHook.map.map.dragPan.disable();
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
useLayerEvent({
|
|
142
|
+
event: 'mouseleave',
|
|
143
|
+
layerId: 'pdfPreviewGeojsonResizeHandle',
|
|
144
|
+
eventHandler: function () {
|
|
145
|
+
if (!mapHook.map) return;
|
|
146
|
+
|
|
147
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
148
|
+
mapHook.map.map.dragPan.enable();
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
useLayerEvent({
|
|
152
|
+
event: 'mousedown',
|
|
153
|
+
layerId: 'pdfPreviewGeojsonResizeHandle',
|
|
154
|
+
addTouchEvents: true,
|
|
155
|
+
eventHandler: function (e: MapMouseEvent | MapTouchEvent) {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
if (!mapHook.map) return;
|
|
158
|
+
|
|
159
|
+
dragging.current = false;
|
|
160
|
+
draggingRotationHandle.current = false;
|
|
161
|
+
draggingResizeHandle.current = true;
|
|
162
|
+
mapHook.map.map._canvas.style.cursor = 'move';
|
|
163
|
+
|
|
164
|
+
function onMove(e: MapMouseEvent | MapTouchEvent) {
|
|
165
|
+
if (!pdfContext.geojsonRef || !draggingResizeHandle.current || !pdfContext.orientation)
|
|
166
|
+
return;
|
|
167
|
+
|
|
168
|
+
const tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
169
|
+
let _distance = turf.distance(
|
|
170
|
+
[tmpGeojsonProps.center.lng, tmpGeojsonProps.center.lat],
|
|
171
|
+
[e.lngLat.lng, e.lngLat.lat]
|
|
172
|
+
);
|
|
173
|
+
// limit max diagonal distance of PDF area to 120km as larger area lead to distortions for northern and southern areas
|
|
174
|
+
if (_distance > 60) {
|
|
175
|
+
_distance = 60;
|
|
176
|
+
}
|
|
177
|
+
tmpGeojsonProps.distance = _distance;
|
|
178
|
+
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
179
|
+
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
180
|
+
setGeojsonProps(tmpGeojsonProps);
|
|
181
|
+
}
|
|
182
|
+
function onUp() {
|
|
183
|
+
if (!draggingResizeHandle.current || !mapHook.map) return;
|
|
184
|
+
|
|
185
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
186
|
+
draggingResizeHandle.current = false;
|
|
187
|
+
|
|
188
|
+
mapHook.map.map.dragPan.enable();
|
|
189
|
+
// Unbind mouse events
|
|
190
|
+
mapHook.map.map.off('mousemove', onMove);
|
|
191
|
+
mapHook.map.map.off('touchmove', onMove);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Mouse events
|
|
195
|
+
mapHook.map.map.on('mousemove', onMove);
|
|
196
|
+
mapHook.map.map.on('touchmove', onMove);
|
|
197
|
+
mapHook.map.map.once('mouseup', onUp);
|
|
198
|
+
mapHook.map.map.once('touchend', onUp);
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Rotation handle events
|
|
203
|
+
useLayerEvent({
|
|
204
|
+
event: 'mouseenter',
|
|
205
|
+
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
206
|
+
eventHandler: function () {
|
|
207
|
+
if (!mapHook.map) return;
|
|
208
|
+
|
|
209
|
+
mapHook.map.map._canvas.style.cursor = 'nwse-resize';
|
|
210
|
+
mapHook.map.map.dragPan.disable();
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
useLayerEvent({
|
|
214
|
+
event: 'mouseleave',
|
|
215
|
+
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
216
|
+
eventHandler: function () {
|
|
217
|
+
if (!mapHook.map) return;
|
|
218
|
+
|
|
219
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
220
|
+
mapHook.map.map.dragPan.enable();
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
useLayerEvent({
|
|
224
|
+
event: 'mousedown',
|
|
225
|
+
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
226
|
+
addTouchEvents: true,
|
|
227
|
+
eventHandler: function (e: MapMouseEvent | MapTouchEvent) {
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
if (!mapHook.map || !pdfContext.orientation) return;
|
|
230
|
+
|
|
231
|
+
dragging.current = false;
|
|
232
|
+
draggingResizeHandle.current = false;
|
|
233
|
+
draggingRotationHandle.current = true;
|
|
234
|
+
mapHook.map.map._canvas.style.cursor = 'move';
|
|
235
|
+
|
|
236
|
+
function onMove(e: MapMouseEvent | MapTouchEvent) {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
if (!draggingRotationHandle.current || !pdfContext.orientation || !pdfContext.geojsonRef)
|
|
239
|
+
return;
|
|
240
|
+
|
|
241
|
+
const tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
242
|
+
const _bearing = turf.bearing(
|
|
243
|
+
[tmpGeojsonProps.center.lng, tmpGeojsonProps.center.lat],
|
|
244
|
+
[e.lngLat.lng, e.lngLat.lat]
|
|
245
|
+
);
|
|
246
|
+
tmpGeojsonProps.bearing = 144.7 + _bearing;
|
|
247
|
+
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
248
|
+
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
249
|
+
setGeojsonProps(tmpGeojsonProps);
|
|
250
|
+
}
|
|
251
|
+
function onUp() {
|
|
252
|
+
if (!draggingRotationHandle.current || !mapHook.map) return;
|
|
253
|
+
|
|
254
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
255
|
+
draggingRotationHandle.current = false;
|
|
256
|
+
|
|
257
|
+
mapHook.map.map.dragPan.enable();
|
|
258
|
+
// Unbind mouse events
|
|
259
|
+
mapHook.map.map.off('mousemove', onMove);
|
|
260
|
+
mapHook.map.map.off('touchmove', onMove);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Mouse events
|
|
264
|
+
mapHook.map.map.on('mousemove', onMove);
|
|
265
|
+
mapHook.map.map.on('touchmove', onMove);
|
|
266
|
+
mapHook.map.map.once('mouseup', onUp);
|
|
267
|
+
mapHook.map.map.once('touchend', onUp);
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// drag & drop events
|
|
272
|
+
useLayerEvent({
|
|
273
|
+
event: 'mouseenter',
|
|
274
|
+
layerId: 'pdfPreviewGeojson',
|
|
275
|
+
eventHandler: function (e: MapLayerMouseEvent) {
|
|
276
|
+
if (!mapHook.map || !e?.features?.length) return;
|
|
277
|
+
mapHook.map.map._canvas.style.cursor = 'move';
|
|
278
|
+
activeFeature.current = e.features[0];
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
useLayerEvent({
|
|
282
|
+
event: 'mouseleave',
|
|
283
|
+
layerId: 'pdfPreviewGeojson',
|
|
284
|
+
eventHandler: function () {
|
|
285
|
+
if (!mapHook.map) return;
|
|
286
|
+
|
|
287
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
288
|
+
mapHook.map.map.dragPan.enable();
|
|
289
|
+
activeFeature.current = undefined;
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
useLayerEvent({
|
|
293
|
+
event: 'mousedown',
|
|
294
|
+
addTouchEvents: true,
|
|
295
|
+
layerId: 'pdfPreviewGeojson',
|
|
296
|
+
eventHandler: function (e: MapMouseEvent | MapTouchEvent) {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
console.log('mousedown');
|
|
299
|
+
if (!mapHook.map) return;
|
|
300
|
+
|
|
301
|
+
draggingResizeHandle.current = false;
|
|
302
|
+
draggingRotationHandle.current = false;
|
|
303
|
+
dragging.current = true;
|
|
304
|
+
mapHook.map.map._canvas.style.cursor = 'move';
|
|
305
|
+
|
|
306
|
+
function onMove(e: MapMouseEvent | MapTouchEvent) {
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
if (!dragging.current || !pdfContext.geojsonRef || !pdfContext.orientation) return;
|
|
309
|
+
|
|
310
|
+
const tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
311
|
+
tmpGeojsonProps.center = e.lngLat;
|
|
312
|
+
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
313
|
+
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
314
|
+
setGeojsonProps(tmpGeojsonProps);
|
|
315
|
+
}
|
|
316
|
+
function onUp() {
|
|
317
|
+
if (!dragging.current || !mapHook.map) return;
|
|
318
|
+
|
|
319
|
+
mapHook.map.map._canvas.style.cursor = '';
|
|
320
|
+
dragging.current = false;
|
|
321
|
+
|
|
322
|
+
mapHook.map.map.dragPan.enable();
|
|
323
|
+
// Unbind mouse events
|
|
324
|
+
mapHook.map.map.off('mousemove', onMove);
|
|
325
|
+
mapHook.map.map.off('touchmove', onMove);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Mouse events
|
|
329
|
+
mapHook.map.map.on('mousemove', onMove);
|
|
330
|
+
mapHook.map.map.on('touchmove', onMove);
|
|
331
|
+
mapHook.map.map.once('mouseup', onUp);
|
|
332
|
+
mapHook.map.map.once('touchend', onUp);
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
//map.on('mouseleave', 'point', function() {
|
|
337
|
+
// map.setPaintProperty('point', 'circle-color', '#3887be');
|
|
338
|
+
// canvas.style.cursor = '';
|
|
339
|
+
// isCursorOverPoint = false;
|
|
340
|
+
// map.dragPan.enable();
|
|
341
|
+
//});
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<>
|
|
345
|
+
{geojsonProps?.geojson?.bbox && (
|
|
346
|
+
<>
|
|
347
|
+
<MlGeoJsonLayer
|
|
348
|
+
paint={{ 'line-color': '#616161', 'line-width': 4 }}
|
|
349
|
+
type="line"
|
|
350
|
+
layerId="pdfPreviewGeojsonOutline"
|
|
351
|
+
geojson={geojsonProps.geojson}
|
|
352
|
+
/>
|
|
353
|
+
<MlGeoJsonLayer
|
|
354
|
+
paint={{ 'fill-opacity': 0 }}
|
|
355
|
+
type="fill"
|
|
356
|
+
layerId="pdfPreviewGeojson"
|
|
357
|
+
geojson={geojsonProps.geojson}
|
|
358
|
+
/>
|
|
359
|
+
<MlGeoJsonLayer
|
|
360
|
+
layerId="pdfPreviewGeojsonResizeHandle"
|
|
361
|
+
paint={{
|
|
362
|
+
'circle-radius': 10,
|
|
363
|
+
'circle-color': '#1976d2',
|
|
364
|
+
'circle-stroke-width': 2,
|
|
365
|
+
'circle-stroke-color': '#ffffff',
|
|
366
|
+
}}
|
|
367
|
+
geojson={{
|
|
368
|
+
type: 'Feature',
|
|
369
|
+
geometry: {
|
|
370
|
+
type: 'Point',
|
|
371
|
+
//coordinates: [geojsonProps.geojson.bbox[2], geojsonProps.geojson.bbox[3]],
|
|
372
|
+
coordinates: geojsonProps.geojson.geometry.coordinates[0][2],
|
|
373
|
+
},
|
|
374
|
+
properties: {},
|
|
375
|
+
}}
|
|
376
|
+
/>
|
|
377
|
+
<MlGeoJsonLayer
|
|
378
|
+
layerId="pdfPreviewGeojsonRotationHandle"
|
|
379
|
+
paint={{
|
|
380
|
+
'circle-radius': 10,
|
|
381
|
+
'circle-color': '#86dd71',
|
|
382
|
+
'circle-stroke-width': 2,
|
|
383
|
+
'circle-stroke-color': '#ffffff',
|
|
384
|
+
}}
|
|
385
|
+
geojson={{
|
|
386
|
+
type: 'Feature',
|
|
387
|
+
geometry: {
|
|
388
|
+
type: 'Point',
|
|
389
|
+
//coordinates: [geojsonProps.geojson.bbox[0], geojsonProps.geojson.bbox[3]],
|
|
390
|
+
coordinates: geojsonProps.geojson.geometry.coordinates[0][3],
|
|
391
|
+
},
|
|
392
|
+
properties: {},
|
|
393
|
+
}}
|
|
394
|
+
/>
|
|
395
|
+
</>
|
|
396
|
+
)}
|
|
397
|
+
</>
|
|
398
|
+
);
|
|
399
|
+
}
|