@mapcomponents/react-maplibre 0.1.61 → 0.1.62
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 +5 -0
- package/coverage/clover.xml +36 -48
- package/coverage/coverage-final.json +3 -3
- package/coverage/lcov-report/index.html +23 -23
- package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
- package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlCenterPosition/index.html +1 -1
- 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/MlCreatePdfForm/MlCreatePdfForm.tsx.html +2 -8
- package/coverage/lcov-report/src/components/MlCreatePdfForm/index.html +1 -1
- package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +1 -1
- 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/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/index.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +1 -1
- package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
- 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 +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlMeasureTool/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
- package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +1 -1
- 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 +11 -11
- package/coverage/lcov-report/src/hooks/useCameraFollowPath/index.html +1 -1
- package/coverage/lcov-report/src/hooks/useCameraFollowPath/useCameraFollowPath.tsx.html +1 -1
- package/coverage/lcov-report/src/hooks/useExportMap/index.html +14 -14
- package/coverage/lcov-report/src/hooks/useExportMap/index.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useExportMap/lib.ts.html +21 -108
- package/coverage/lcov-report/src/hooks/useLayer.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +9 -9
- 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/useSource.ts.html +1 -1
- package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +5 -2
- package/coverage/lcov.info +50 -72
- package/dist/components/MlCreatePdfForm/MlCreatePdfForm.stories.d.ts +1 -0
- package/dist/components/MlCreatePdfForm/lib/PdfContext.d.ts +3 -16
- package/dist/components/MlCreatePdfForm/lib/PdfPreview.d.ts +19 -6
- package/dist/components/MlCreatePdfForm/lib/_PdfPreview.d.ts +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +505 -597
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +16 -1
- package/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx +0 -2
- package/src/components/MlCreatePdfForm/lib/PdfContext.tsx +16 -18
- package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +78 -5
- package/src/components/MlCreatePdfForm/lib/PdfPreview.tsx +285 -357
- package/src/components/MlCreatePdfForm/lib/_PdfPreview.tsx +399 -0
- package/src/components/MlCreatePdfForm/lib/pdfContext.d.ts +24 -0
- package/src/components/MlCreatePdfForm/lib/preview.css +114 -0
- package/src/hooks/useExportMap/lib.ts +14 -43
- package/src/index.ts +1 -0
package/dist/index.esm.js
CHANGED
|
@@ -7,14 +7,15 @@ import { Map as Map$2, Popup } from 'maplibre-gl';
|
|
|
7
7
|
import jsPDF from 'jspdf';
|
|
8
8
|
import styled$3 from '@emotion/styled';
|
|
9
9
|
import { keyframes } from '@emotion/react';
|
|
10
|
+
import * as ReactDOM from 'react-dom';
|
|
11
|
+
import ReactDOM__default from 'react-dom';
|
|
12
|
+
import Moveable from 'react-moveable';
|
|
10
13
|
import * as turf from '@turf/turf';
|
|
11
14
|
import { point, circle, lineArc, bbox, lineOffset, distance } from '@turf/turf';
|
|
12
15
|
import { FormControl, InputLabel, Select, MenuItem, FormLabel, RadioGroup, FormControlLabel, Radio, Button as Button$2 } from '@mui/material';
|
|
13
16
|
import MapboxDraw from '@mapbox/mapbox-gl-draw';
|
|
14
17
|
import { css } from '@emotion/css';
|
|
15
18
|
import syncMove from '@mapbox/mapbox-gl-sync-move';
|
|
16
|
-
import * as ReactDOM from 'react-dom';
|
|
17
|
-
import ReactDOM__default from 'react-dom';
|
|
18
19
|
import WMSCapabilities from 'wms-capabilities';
|
|
19
20
|
import * as d3 from 'd3';
|
|
20
21
|
|
|
@@ -9923,273 +9924,6 @@ MlCreatePdfButton.defaultProps = {
|
|
|
9923
9924
|
mapId: undefined,
|
|
9924
9925
|
};
|
|
9925
9926
|
|
|
9926
|
-
var legalLayerTypes = [
|
|
9927
|
-
'fill',
|
|
9928
|
-
'line',
|
|
9929
|
-
'symbol',
|
|
9930
|
-
'circle',
|
|
9931
|
-
'heatmap',
|
|
9932
|
-
'fill-extrusion',
|
|
9933
|
-
'raster',
|
|
9934
|
-
'hillshade',
|
|
9935
|
-
'background',
|
|
9936
|
-
];
|
|
9937
|
-
function useLayer(props) {
|
|
9938
|
-
var mapHook = useMap({
|
|
9939
|
-
mapId: props.mapId,
|
|
9940
|
-
waitForLayer: props.insertBeforeLayer,
|
|
9941
|
-
});
|
|
9942
|
-
var layerTypeRef = useRef('');
|
|
9943
|
-
var layerPaintConfRef = useRef('');
|
|
9944
|
-
var layerLayoutConfRef = useRef('');
|
|
9945
|
-
var _a = useState(), layer = _a[0], setLayer = _a[1];
|
|
9946
|
-
var initializedRef = useRef(false);
|
|
9947
|
-
var layerId = useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
|
|
9948
|
-
var createLayer = useCallback(function () {
|
|
9949
|
-
var _a, _b;
|
|
9950
|
-
if (!mapHook.map)
|
|
9951
|
-
return;
|
|
9952
|
-
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
9953
|
-
mapHook.cleanup();
|
|
9954
|
-
}
|
|
9955
|
-
if (mapHook.map.map.getSource(layerId.current)) {
|
|
9956
|
-
mapHook.map.map.removeSource(layerId.current);
|
|
9957
|
-
}
|
|
9958
|
-
if (typeof props.source === 'string') {
|
|
9959
|
-
if (props.source === '' || !mapHook.map.map.getSource(props.source)) {
|
|
9960
|
-
return;
|
|
9961
|
-
}
|
|
9962
|
-
}
|
|
9963
|
-
initializedRef.current = true;
|
|
9964
|
-
mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson && !props.source
|
|
9965
|
-
? {
|
|
9966
|
-
source: {
|
|
9967
|
-
type: 'geojson',
|
|
9968
|
-
data: props.geojson,
|
|
9969
|
-
},
|
|
9970
|
-
}
|
|
9971
|
-
: {})), (props.source
|
|
9972
|
-
? {
|
|
9973
|
-
source: props.source,
|
|
9974
|
-
}
|
|
9975
|
-
: {})), { id: layerId.current }), props.insertBeforeLayer
|
|
9976
|
-
? props.insertBeforeLayer
|
|
9977
|
-
: props.insertBeforeFirstSymbolLayer
|
|
9978
|
-
? mapHook.map.firstSymbolLayer
|
|
9979
|
-
: undefined, mapHook.componentId);
|
|
9980
|
-
setLayer(mapHook.map.map.getLayer(layerId.current));
|
|
9981
|
-
if (typeof props.onHover !== 'undefined') {
|
|
9982
|
-
mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
|
|
9983
|
-
}
|
|
9984
|
-
if (typeof props.onClick !== 'undefined') {
|
|
9985
|
-
mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
|
|
9986
|
-
}
|
|
9987
|
-
if (typeof props.onLeave !== 'undefined') {
|
|
9988
|
-
mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
|
|
9989
|
-
}
|
|
9990
|
-
// recreate layer if style has changed
|
|
9991
|
-
mapHook.map.on('styledata', function () {
|
|
9992
|
-
var _a;
|
|
9993
|
-
if (initializedRef.current && !((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
|
|
9994
|
-
console.log('Recreate Layer');
|
|
9995
|
-
createLayer();
|
|
9996
|
-
}
|
|
9997
|
-
}, mapHook.componentId);
|
|
9998
|
-
layerPaintConfRef.current = JSON.stringify((_a = props.options) === null || _a === void 0 ? void 0 : _a.paint);
|
|
9999
|
-
layerLayoutConfRef.current = JSON.stringify((_b = props.options) === null || _b === void 0 ? void 0 : _b.layout);
|
|
10000
|
-
layerTypeRef.current = props.options.type;
|
|
10001
|
-
}, [props, mapHook.map]);
|
|
10002
|
-
useEffect(function () {
|
|
10003
|
-
if (!mapHook.map)
|
|
10004
|
-
return;
|
|
10005
|
-
if (initializedRef.current &&
|
|
10006
|
-
(legalLayerTypes.indexOf(props.options.type) === -1 ||
|
|
10007
|
-
(legalLayerTypes.indexOf(props.options.type) !== -1 &&
|
|
10008
|
-
props.options.type === layerTypeRef.current))) {
|
|
10009
|
-
return;
|
|
10010
|
-
}
|
|
10011
|
-
createLayer();
|
|
10012
|
-
}, [mapHook.map, props.options, createLayer]);
|
|
10013
|
-
useEffect(function () {
|
|
10014
|
-
var _a, _b, _c, _d;
|
|
10015
|
-
if (!initializedRef.current || !((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(layerId.current)))
|
|
10016
|
-
return;
|
|
10017
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10018
|
-
//@ts-ignore setData only exists on GeoJsonSource
|
|
10019
|
-
(_d = (_c = mapHook.map.map.getSource(layerId.current)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.geojson);
|
|
10020
|
-
}, [props.geojson, mapHook.map, props.options.type]);
|
|
10021
|
-
useEffect(function () {
|
|
10022
|
-
var _a, _b, _c, _d, _e;
|
|
10023
|
-
if (!mapHook.map ||
|
|
10024
|
-
!((_c = (_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getLayer) === null || _c === void 0 ? void 0 : _c.call(_b, layerId.current)) ||
|
|
10025
|
-
!initializedRef.current ||
|
|
10026
|
-
props.options.type !== layerTypeRef.current)
|
|
10027
|
-
return;
|
|
10028
|
-
var key;
|
|
10029
|
-
var layoutString = JSON.stringify(props.options.layout);
|
|
10030
|
-
if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
|
|
10031
|
-
var oldLayout = JSON.parse(layerLayoutConfRef.current);
|
|
10032
|
-
for (key in props.options.layout) {
|
|
10033
|
-
if (((_d = props.options.layout) === null || _d === void 0 ? void 0 : _d[key]) && props.options.layout[key] !== oldLayout[key]) {
|
|
10034
|
-
mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
|
|
10035
|
-
}
|
|
10036
|
-
}
|
|
10037
|
-
layerLayoutConfRef.current = layoutString;
|
|
10038
|
-
}
|
|
10039
|
-
var paintString = JSON.stringify(props.options.paint);
|
|
10040
|
-
if (paintString !== layerPaintConfRef.current) {
|
|
10041
|
-
var oldPaint = JSON.parse(layerPaintConfRef.current);
|
|
10042
|
-
for (key in props.options.paint) {
|
|
10043
|
-
if (((_e = props.options.paint) === null || _e === void 0 ? void 0 : _e[key]) && props.options.paint[key] !== oldPaint[key]) {
|
|
10044
|
-
mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
|
|
10045
|
-
}
|
|
10046
|
-
}
|
|
10047
|
-
layerPaintConfRef.current = paintString;
|
|
10048
|
-
}
|
|
10049
|
-
}, [props.options, mapHook.map]);
|
|
10050
|
-
useEffect(function () {
|
|
10051
|
-
return function () {
|
|
10052
|
-
initializedRef.current = false;
|
|
10053
|
-
mapHook.cleanup();
|
|
10054
|
-
};
|
|
10055
|
-
}, []);
|
|
10056
|
-
return {
|
|
10057
|
-
map: mapHook.map,
|
|
10058
|
-
layer: layer,
|
|
10059
|
-
layerId: layerId.current,
|
|
10060
|
-
componentId: mapHook.componentId,
|
|
10061
|
-
mapHook: mapHook,
|
|
10062
|
-
};
|
|
10063
|
-
}
|
|
10064
|
-
|
|
10065
|
-
var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
10066
|
-
switch (type) {
|
|
10067
|
-
case "fill":
|
|
10068
|
-
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.fill) {
|
|
10069
|
-
return defaultPaintOverrides.fill;
|
|
10070
|
-
}
|
|
10071
|
-
return {
|
|
10072
|
-
"fill-color": "rgba(10,240,256,0.6)",
|
|
10073
|
-
};
|
|
10074
|
-
case "line":
|
|
10075
|
-
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
|
|
10076
|
-
return defaultPaintOverrides.line;
|
|
10077
|
-
}
|
|
10078
|
-
return {
|
|
10079
|
-
"line-color": "rgb(203,211,2)",
|
|
10080
|
-
"line-width": 5,
|
|
10081
|
-
};
|
|
10082
|
-
case "circle":
|
|
10083
|
-
default:
|
|
10084
|
-
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.circle) {
|
|
10085
|
-
return defaultPaintOverrides.circle;
|
|
10086
|
-
}
|
|
10087
|
-
return {
|
|
10088
|
-
"circle-color": "rgba(10,240,256,0.8)",
|
|
10089
|
-
"circle-stroke-color": "#fff",
|
|
10090
|
-
"circle-stroke-width": 2,
|
|
10091
|
-
};
|
|
10092
|
-
}
|
|
10093
|
-
};
|
|
10094
|
-
|
|
10095
|
-
var mapGeometryTypesToLayerTypes = {
|
|
10096
|
-
Position: "circle",
|
|
10097
|
-
Point: "circle",
|
|
10098
|
-
MultiPoint: "circle",
|
|
10099
|
-
LineString: "line",
|
|
10100
|
-
MultiLineString: "line",
|
|
10101
|
-
Polygon: "fill",
|
|
10102
|
-
MultiPolygon: "fill",
|
|
10103
|
-
GeometryCollection: "circle",
|
|
10104
|
-
};
|
|
10105
|
-
var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
10106
|
-
var _a;
|
|
10107
|
-
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
|
|
10108
|
-
return (mapGeometryTypesToLayerTypes === null || mapGeometryTypesToLayerTypes === void 0 ? void 0 : mapGeometryTypesToLayerTypes[(_a = geojson === null || geojson === void 0 ? void 0 : geojson.geometry) === null || _a === void 0 ? void 0 : _a.type])
|
|
10109
|
-
? mapGeometryTypesToLayerTypes[geojson.geometry.type]
|
|
10110
|
-
: "circle";
|
|
10111
|
-
}
|
|
10112
|
-
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
|
|
10113
|
-
if (geojson.features.length) {
|
|
10114
|
-
return getDefaulLayerTypeByGeometry(geojson.features[0]);
|
|
10115
|
-
}
|
|
10116
|
-
return "circle";
|
|
10117
|
-
}
|
|
10118
|
-
return "fill";
|
|
10119
|
-
};
|
|
10120
|
-
|
|
10121
|
-
/**
|
|
10122
|
-
* Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
|
|
10123
|
-
*
|
|
10124
|
-
* @component
|
|
10125
|
-
*/
|
|
10126
|
-
var MlGeoJsonLayer = function (props) {
|
|
10127
|
-
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
10128
|
-
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
10129
|
-
useLayer({
|
|
10130
|
-
mapId: props.mapId,
|
|
10131
|
-
layerId: props.layerId || "MlGeoJsonLayer-" + v4(),
|
|
10132
|
-
geojson: props.geojson,
|
|
10133
|
-
options: __assign(__assign({ paint: props.paint ||
|
|
10134
|
-
getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides), layout: props.layout || {} }, props.options), { type: layerType }),
|
|
10135
|
-
insertBeforeLayer: props.insertBeforeLayer,
|
|
10136
|
-
onHover: props.onHover,
|
|
10137
|
-
onClick: props.onClick,
|
|
10138
|
-
onLeave: props.onLeave,
|
|
10139
|
-
});
|
|
10140
|
-
return (React__default.createElement(React__default.Fragment, null));
|
|
10141
|
-
};
|
|
10142
|
-
|
|
10143
|
-
var touchEquivalents = {
|
|
10144
|
-
mousedown: 'touchstart',
|
|
10145
|
-
mouseup: 'touchend',
|
|
10146
|
-
mousemove: 'touchmove'
|
|
10147
|
-
};
|
|
10148
|
-
var touchEquivalentsKeys = Object.keys(touchEquivalents);
|
|
10149
|
-
|
|
10150
|
-
function useLayerEvent(props) {
|
|
10151
|
-
var mapState = useMapState({
|
|
10152
|
-
mapId: props.mapId,
|
|
10153
|
-
watch: {
|
|
10154
|
-
layers: true
|
|
10155
|
-
}
|
|
10156
|
-
});
|
|
10157
|
-
var mapHook = useMap({
|
|
10158
|
-
mapId: props.mapId
|
|
10159
|
-
});
|
|
10160
|
-
useEffect(function () {
|
|
10161
|
-
if (!mapHook.map) return true;
|
|
10162
|
-
if (typeof props.condition !== 'undefined' && props.condition === false) return; //console.log('useLayerEvent');
|
|
10163
|
-
//console.log(mapState);
|
|
10164
|
-
|
|
10165
|
-
if (mapHook.map.map.getLayer(props.layerId)) {
|
|
10166
|
-
//console.log("layer avail");
|
|
10167
|
-
var _event = props.event;
|
|
10168
|
-
var _layerId = props.layerId;
|
|
10169
|
-
var _eventHandler = props.eventHandler; //console.log(_event);
|
|
10170
|
-
|
|
10171
|
-
mapHook.map.on(_event, _layerId, _eventHandler, mapHook.componentId);
|
|
10172
|
-
|
|
10173
|
-
if ((props === null || props === void 0 ? void 0 : props.addTouchEvents) === true) {
|
|
10174
|
-
if (touchEquivalentsKeys.indexOf(_event) !== -1) {
|
|
10175
|
-
mapHook.map.on(touchEquivalents[_event], _layerId, _eventHandler, mapHook.componentId);
|
|
10176
|
-
}
|
|
10177
|
-
}
|
|
10178
|
-
|
|
10179
|
-
return function () {
|
|
10180
|
-
mapHook.map.off(_event, _layerId, _eventHandler);
|
|
10181
|
-
|
|
10182
|
-
if ((props === null || props === void 0 ? void 0 : props.addTouchEvents) === true) {
|
|
10183
|
-
if (touchEquivalentsKeys.indexOf(_event) !== -1) {
|
|
10184
|
-
mapHook.map.off(touchEquivalents[_event], _layerId, _eventHandler, mapHook.componentId);
|
|
10185
|
-
}
|
|
10186
|
-
}
|
|
10187
|
-
};
|
|
10188
|
-
}
|
|
10189
|
-
}, [props, mapState, mapHook.map]);
|
|
10190
|
-
return {};
|
|
10191
|
-
}
|
|
10192
|
-
|
|
10193
9927
|
var PdfTemplates = {
|
|
10194
9928
|
A4: {
|
|
10195
9929
|
'300dpi': {
|
|
@@ -10269,11 +10003,19 @@ var PdfContextProvider = function (_a) {
|
|
|
10269
10003
|
var children = _a.children;
|
|
10270
10004
|
var _b = useState('A4'), format = _b[0], setFormat = _b[1];
|
|
10271
10005
|
var _c = useState('72dpi'), quality = _c[0], setQuality = _c[1];
|
|
10272
|
-
var _d = useState(
|
|
10006
|
+
var _d = useState({
|
|
10007
|
+
center: undefined,
|
|
10008
|
+
scale: undefined,
|
|
10009
|
+
rotate: 0,
|
|
10010
|
+
width: 210,
|
|
10011
|
+
height: 297,
|
|
10012
|
+
orientation: 'portrait',
|
|
10013
|
+
fixedScale: 0,
|
|
10014
|
+
}), options = _d[0], setOptions = _d[1];
|
|
10273
10015
|
var geojsonRef = useRef();
|
|
10274
10016
|
var template = useMemo(function () {
|
|
10275
10017
|
if (typeof PdfTemplates[format][quality] !== 'undefined') {
|
|
10276
|
-
return orientation === 'portrait'
|
|
10018
|
+
return options.orientation === 'portrait'
|
|
10277
10019
|
? PdfTemplates[format][quality]
|
|
10278
10020
|
: {
|
|
10279
10021
|
width: PdfTemplates[format][quality].height,
|
|
@@ -10281,317 +10023,243 @@ var PdfContextProvider = function (_a) {
|
|
|
10281
10023
|
};
|
|
10282
10024
|
}
|
|
10283
10025
|
return defaultTemplate;
|
|
10284
|
-
}, [format, quality, orientation]);
|
|
10026
|
+
}, [format, quality, options.orientation]);
|
|
10285
10027
|
var value = {
|
|
10028
|
+
options: options,
|
|
10029
|
+
setOptions: setOptions,
|
|
10286
10030
|
format: format,
|
|
10287
10031
|
setFormat: setFormat,
|
|
10288
10032
|
quality: quality,
|
|
10289
10033
|
setQuality: setQuality,
|
|
10290
|
-
orientation: orientation,
|
|
10291
|
-
setOrientation: setOrientation,
|
|
10292
10034
|
geojsonRef: geojsonRef,
|
|
10293
10035
|
template: template,
|
|
10294
10036
|
};
|
|
10295
10037
|
return React__default.createElement(PdfContext.Provider, { value: value }, children);
|
|
10296
10038
|
};
|
|
10297
10039
|
|
|
10298
|
-
|
|
10299
|
-
var
|
|
10300
|
-
var
|
|
10301
|
-
var
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
bottomRight.geometry.coordinates[1],
|
|
10308
|
-
];
|
|
10309
|
-
var _previewGeojson = turf.bboxPolygon(bbox);
|
|
10310
|
-
_previewGeojson = turf.transformRotate(_previewGeojson, geojsonProps.bearing);
|
|
10311
|
-
if (!(_previewGeojson === null || _previewGeojson === void 0 ? void 0 : _previewGeojson.properties)) {
|
|
10312
|
-
_previewGeojson.properties = {};
|
|
10040
|
+
function getTargetRotationAngle(target) {
|
|
10041
|
+
var el_style = window.getComputedStyle(target, null);
|
|
10042
|
+
var el_transform = el_style.getPropertyValue('transform');
|
|
10043
|
+
var deg = 0;
|
|
10044
|
+
if (el_transform !== 'none') {
|
|
10045
|
+
var values = el_transform.split('(')[1].split(')')[0].split(',');
|
|
10046
|
+
var a = parseFloat(values[0]);
|
|
10047
|
+
var b = parseFloat(values[1]);
|
|
10048
|
+
deg = Math.round(Math.atan2(b, a) * (180 / Math.PI));
|
|
10313
10049
|
}
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10050
|
+
return deg < 0 ? deg + 360 : deg;
|
|
10051
|
+
}
|
|
10052
|
+
function calcElemTransformedPoint(el, point, transformOrigin) {
|
|
10053
|
+
var style = getComputedStyle(el);
|
|
10054
|
+
var p = [point[0] - transformOrigin[0], point[1] - transformOrigin[1]];
|
|
10055
|
+
var matrix = new DOMMatrixReadOnly(style.transform);
|
|
10056
|
+
// transform pixel coordinates according to the css transform state of "el" (target)
|
|
10057
|
+
return [
|
|
10058
|
+
p[0] * matrix.a + p[1] * matrix.c + matrix.e + transformOrigin[0],
|
|
10059
|
+
p[0] * matrix.b + p[1] * matrix.d + matrix.f + transformOrigin[1],
|
|
10060
|
+
];
|
|
10061
|
+
}
|
|
10062
|
+
// measure distance in pixels that is used to determine the current css transform.scale relative to the maps viewport.zoom
|
|
10063
|
+
var scaleAnchorInPixels = 10;
|
|
10064
|
+
// used to determine the MapZoomScale modifier which is multiplied with props.options.scale to relate the scale to the current map viewport.zoom
|
|
10065
|
+
function getMapZoomScaleModifier(point, _map) {
|
|
10066
|
+
var left = _map.unproject(point);
|
|
10067
|
+
var right = _map.unproject([point[0] + scaleAnchorInPixels, point[1]]);
|
|
10068
|
+
var maxMeters = left.distanceTo(right);
|
|
10069
|
+
return scaleAnchorInPixels / maxMeters;
|
|
10070
|
+
}
|
|
10071
|
+
/**
|
|
10072
|
+
* PdfPreview component renders a transformable (drag, scale, rotate) preview of the desired export or print content
|
|
10073
|
+
*/
|
|
10317
10074
|
function PdfPreview(props) {
|
|
10318
10075
|
var _a;
|
|
10319
|
-
var
|
|
10320
|
-
var
|
|
10321
|
-
var
|
|
10322
|
-
var
|
|
10323
|
-
var
|
|
10324
|
-
|
|
10325
|
-
var _b = useState({
|
|
10326
|
-
center: { lng: 0, lat: 0 },
|
|
10327
|
-
distance: 10,
|
|
10328
|
-
bearing: 0,
|
|
10329
|
-
geojson: undefined,
|
|
10330
|
-
}), geojsonProps = _b[0], setGeojsonProps = _b[1];
|
|
10076
|
+
var mapState = useMapState({ mapId: props.mapId, watch: { layers: false, viewport: true } });
|
|
10077
|
+
var targetRef = useRef(null);
|
|
10078
|
+
var fixedScaleRef = useRef();
|
|
10079
|
+
var moveableRef = useRef(null);
|
|
10080
|
+
var mapContainerRef = useRef(document.querySelector('.mapContainer'));
|
|
10081
|
+
//const [transform, setTransform] = useState('translate(452.111px, 15.6148px)');
|
|
10331
10082
|
var mapHook = useMap({
|
|
10332
10083
|
mapId: props.mapId,
|
|
10333
|
-
waitForLayer: props.insertBeforeLayer,
|
|
10334
10084
|
});
|
|
10335
10085
|
useEffect(function () {
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
!pdfContext.orientation ||
|
|
10339
|
-
!pdfContext.template ||
|
|
10340
|
-
initializedRef.current)
|
|
10086
|
+
var _a;
|
|
10087
|
+
if (!((_a = mapState === null || mapState === void 0 ? void 0 : mapState.viewport) === null || _a === void 0 ? void 0 : _a.zoom) || !mapHook.map)
|
|
10341
10088
|
return;
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
var
|
|
10345
|
-
var
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10089
|
+
// if the component was initialized with scale or center as undefined derive those values from the current map view state
|
|
10090
|
+
//initialize props if not defined
|
|
10091
|
+
var _centerX = Math.round(mapHook.map.map._container.clientWidth / 2);
|
|
10092
|
+
var _centerY = Math.round(mapHook.map.map._container.clientHeight / 2);
|
|
10093
|
+
if (!props.options.scale) {
|
|
10094
|
+
//const scale = parseFloat(/(14/mapState.viewport.zoom));
|
|
10095
|
+
var scale_1 = 1 / getMapZoomScaleModifier([_centerX, _centerY], mapHook.map.map);
|
|
10096
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { scale: [scale_1, scale_1] })); });
|
|
10097
|
+
}
|
|
10098
|
+
if (!props.options.center) {
|
|
10099
|
+
var _center_1 = mapHook.map.map.unproject([_centerX, _centerY]);
|
|
10100
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { center: [_center_1.lng, _center_1.lat] })); });
|
|
10101
|
+
}
|
|
10102
|
+
}, [mapHook.map, (_a = mapState.viewport) === null || _a === void 0 ? void 0 : _a.zoom]);
|
|
10103
|
+
useEffect(function () {
|
|
10104
|
+
if (!mapHook.map)
|
|
10105
|
+
return;
|
|
10106
|
+
mapHook.map.map.setPitch(0);
|
|
10107
|
+
var _maxPitch = mapHook.map.map.getMaxPitch();
|
|
10108
|
+
mapHook.map.map.setMaxPitch(0);
|
|
10109
|
+
return function () {
|
|
10110
|
+
var _a;
|
|
10111
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.setMaxPitch(_maxPitch);
|
|
10358
10112
|
};
|
|
10359
|
-
setGeojsonProps(tmpGeojsonProps);
|
|
10360
|
-
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
10361
10113
|
}, [mapHook.map]);
|
|
10114
|
+
var transformOrigin = useMemo(function () {
|
|
10115
|
+
if (props.options.orientation === 'portrait') {
|
|
10116
|
+
return [props.options.width / 2, props.options.height / 2];
|
|
10117
|
+
}
|
|
10118
|
+
else {
|
|
10119
|
+
return [props.options.height / 2, props.options.width / 2];
|
|
10120
|
+
}
|
|
10121
|
+
}, [props.options.orientation, props.options.width, props.options.height]);
|
|
10122
|
+
var transform = useMemo(function () {
|
|
10123
|
+
var _a, _b;
|
|
10124
|
+
if (!mapHook.map || !props.options.scale)
|
|
10125
|
+
return 'none';
|
|
10126
|
+
var centerInPixels = mapHook.map.map.project(props.options.center);
|
|
10127
|
+
var x = centerInPixels.x;
|
|
10128
|
+
var y = centerInPixels.y;
|
|
10129
|
+
var scale = props.options.scale[0] * getMapZoomScaleModifier([x, y], mapHook.map.map);
|
|
10130
|
+
var viewportBearing = ((_a = mapState === null || mapState === void 0 ? void 0 : mapState.viewport) === null || _a === void 0 ? void 0 : _a.bearing) ? (_b = mapState.viewport) === null || _b === void 0 ? void 0 : _b.bearing : 0;
|
|
10131
|
+
var _transform = "translate(".concat(Math.floor(centerInPixels.x - transformOrigin[0]), "px,").concat(Math.floor(centerInPixels.y - transformOrigin[1]), "px) rotate(").concat(props.options.rotate - viewportBearing, "deg) scale(").concat(scale, ",").concat(scale, ")");
|
|
10132
|
+
if (targetRef.current)
|
|
10133
|
+
targetRef.current.style.transform = _transform;
|
|
10134
|
+
return _transform;
|
|
10135
|
+
}, [
|
|
10136
|
+
mapHook.map,
|
|
10137
|
+
mapState.viewport,
|
|
10138
|
+
props.options.scale,
|
|
10139
|
+
props.options.rotate,
|
|
10140
|
+
props.options.center,
|
|
10141
|
+
transformOrigin,
|
|
10142
|
+
]);
|
|
10143
|
+
useEffect(function () {
|
|
10144
|
+
var _a;
|
|
10145
|
+
(_a = moveableRef.current) === null || _a === void 0 ? void 0 : _a.updateTarget();
|
|
10146
|
+
}, [transform]);
|
|
10362
10147
|
useEffect(function () {
|
|
10363
|
-
|
|
10148
|
+
// update props.options.scale if fixedScale was changed
|
|
10149
|
+
if (!mapHook.map ||
|
|
10150
|
+
!props.options.center ||
|
|
10151
|
+
!props.options.fixedScale ||
|
|
10152
|
+
(typeof props.options.fixedScale !== 'undefined' &&
|
|
10153
|
+
fixedScaleRef.current === props.options.fixedScale))
|
|
10364
10154
|
return;
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
mapHook.map.map._canvas.style.cursor = '';
|
|
10388
|
-
mapHook.map.map.dragPan.enable();
|
|
10389
|
-
},
|
|
10390
|
-
});
|
|
10391
|
-
useLayerEvent({
|
|
10392
|
-
event: 'mousedown',
|
|
10393
|
-
layerId: 'pdfPreviewGeojsonResizeHandle',
|
|
10394
|
-
addTouchEvents: true,
|
|
10395
|
-
eventHandler: function (e) {
|
|
10396
|
-
e.preventDefault();
|
|
10397
|
-
if (!mapHook.map)
|
|
10398
|
-
return;
|
|
10399
|
-
dragging.current = false;
|
|
10400
|
-
draggingRotationHandle.current = false;
|
|
10401
|
-
draggingResizeHandle.current = true;
|
|
10402
|
-
mapHook.map.map._canvas.style.cursor = 'move';
|
|
10403
|
-
function onMove(e) {
|
|
10404
|
-
if (!pdfContext.geojsonRef || !draggingResizeHandle.current || !pdfContext.orientation)
|
|
10405
|
-
return;
|
|
10406
|
-
var tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
10407
|
-
var _distance = turf.distance([tmpGeojsonProps.center.lng, tmpGeojsonProps.center.lat], [e.lngLat.lng, e.lngLat.lat]);
|
|
10408
|
-
// limit max diagonal distance of PDF area to 120km as larger area lead to distortions for northern and southern areas
|
|
10409
|
-
if (_distance > 60) {
|
|
10410
|
-
_distance = 60;
|
|
10411
|
-
}
|
|
10412
|
-
tmpGeojsonProps.distance = _distance;
|
|
10413
|
-
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
10414
|
-
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
10415
|
-
setGeojsonProps(tmpGeojsonProps);
|
|
10416
|
-
}
|
|
10417
|
-
function onUp() {
|
|
10418
|
-
if (!draggingResizeHandle.current || !mapHook.map)
|
|
10419
|
-
return;
|
|
10420
|
-
mapHook.map.map._canvas.style.cursor = '';
|
|
10421
|
-
draggingResizeHandle.current = false;
|
|
10422
|
-
mapHook.map.map.dragPan.enable();
|
|
10423
|
-
// Unbind mouse events
|
|
10424
|
-
mapHook.map.map.off('mousemove', onMove);
|
|
10425
|
-
mapHook.map.map.off('touchmove', onMove);
|
|
10426
|
-
}
|
|
10427
|
-
// Mouse events
|
|
10428
|
-
mapHook.map.map.on('mousemove', onMove);
|
|
10429
|
-
mapHook.map.map.on('touchmove', onMove);
|
|
10430
|
-
mapHook.map.map.once('mouseup', onUp);
|
|
10431
|
-
mapHook.map.map.once('touchend', onUp);
|
|
10432
|
-
},
|
|
10433
|
-
});
|
|
10434
|
-
// Rotation handle events
|
|
10435
|
-
useLayerEvent({
|
|
10436
|
-
event: 'mouseenter',
|
|
10437
|
-
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
10438
|
-
eventHandler: function () {
|
|
10439
|
-
if (!mapHook.map)
|
|
10440
|
-
return;
|
|
10441
|
-
mapHook.map.map._canvas.style.cursor = 'nwse-resize';
|
|
10442
|
-
mapHook.map.map.dragPan.disable();
|
|
10443
|
-
},
|
|
10444
|
-
});
|
|
10445
|
-
useLayerEvent({
|
|
10446
|
-
event: 'mouseleave',
|
|
10447
|
-
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
10448
|
-
eventHandler: function () {
|
|
10449
|
-
if (!mapHook.map)
|
|
10450
|
-
return;
|
|
10451
|
-
mapHook.map.map._canvas.style.cursor = '';
|
|
10452
|
-
mapHook.map.map.dragPan.enable();
|
|
10453
|
-
},
|
|
10454
|
-
});
|
|
10455
|
-
useLayerEvent({
|
|
10456
|
-
event: 'mousedown',
|
|
10457
|
-
layerId: 'pdfPreviewGeojsonRotationHandle',
|
|
10458
|
-
addTouchEvents: true,
|
|
10459
|
-
eventHandler: function (e) {
|
|
10460
|
-
e.preventDefault();
|
|
10461
|
-
if (!mapHook.map || !pdfContext.orientation)
|
|
10462
|
-
return;
|
|
10463
|
-
dragging.current = false;
|
|
10464
|
-
draggingResizeHandle.current = false;
|
|
10465
|
-
draggingRotationHandle.current = true;
|
|
10466
|
-
mapHook.map.map._canvas.style.cursor = 'move';
|
|
10467
|
-
function onMove(e) {
|
|
10468
|
-
e.preventDefault();
|
|
10469
|
-
if (!draggingRotationHandle.current || !pdfContext.orientation || !pdfContext.geojsonRef)
|
|
10470
|
-
return;
|
|
10471
|
-
var tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
10472
|
-
var _bearing = turf.bearing([tmpGeojsonProps.center.lng, tmpGeojsonProps.center.lat], [e.lngLat.lng, e.lngLat.lat]);
|
|
10473
|
-
tmpGeojsonProps.bearing = 144.7 + _bearing;
|
|
10474
|
-
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
10475
|
-
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
10476
|
-
setGeojsonProps(tmpGeojsonProps);
|
|
10477
|
-
}
|
|
10478
|
-
function onUp() {
|
|
10479
|
-
if (!draggingRotationHandle.current || !mapHook.map)
|
|
10480
|
-
return;
|
|
10481
|
-
mapHook.map.map._canvas.style.cursor = '';
|
|
10482
|
-
draggingRotationHandle.current = false;
|
|
10483
|
-
mapHook.map.map.dragPan.enable();
|
|
10484
|
-
// Unbind mouse events
|
|
10485
|
-
mapHook.map.map.off('mousemove', onMove);
|
|
10486
|
-
mapHook.map.map.off('touchmove', onMove);
|
|
10487
|
-
}
|
|
10488
|
-
// Mouse events
|
|
10489
|
-
mapHook.map.map.on('mousemove', onMove);
|
|
10490
|
-
mapHook.map.map.on('touchmove', onMove);
|
|
10491
|
-
mapHook.map.map.once('mouseup', onUp);
|
|
10492
|
-
mapHook.map.map.once('touchend', onUp);
|
|
10493
|
-
},
|
|
10494
|
-
});
|
|
10495
|
-
// drag & drop events
|
|
10496
|
-
useLayerEvent({
|
|
10497
|
-
event: 'mouseenter',
|
|
10498
|
-
layerId: 'pdfPreviewGeojson',
|
|
10499
|
-
eventHandler: function (e) {
|
|
10500
|
-
var _a;
|
|
10501
|
-
if (!mapHook.map || !((_a = e === null || e === void 0 ? void 0 : e.features) === null || _a === void 0 ? void 0 : _a.length))
|
|
10502
|
-
return;
|
|
10503
|
-
mapHook.map.map._canvas.style.cursor = 'move';
|
|
10504
|
-
activeFeature.current = e.features[0];
|
|
10505
|
-
},
|
|
10506
|
-
});
|
|
10507
|
-
useLayerEvent({
|
|
10508
|
-
event: 'mouseleave',
|
|
10509
|
-
layerId: 'pdfPreviewGeojson',
|
|
10510
|
-
eventHandler: function () {
|
|
10511
|
-
if (!mapHook.map)
|
|
10512
|
-
return;
|
|
10513
|
-
mapHook.map.map._canvas.style.cursor = '';
|
|
10514
|
-
mapHook.map.map.dragPan.enable();
|
|
10515
|
-
activeFeature.current = undefined;
|
|
10516
|
-
},
|
|
10517
|
-
});
|
|
10518
|
-
useLayerEvent({
|
|
10519
|
-
event: 'mousedown',
|
|
10520
|
-
addTouchEvents: true,
|
|
10521
|
-
layerId: 'pdfPreviewGeojson',
|
|
10522
|
-
eventHandler: function (e) {
|
|
10523
|
-
e.preventDefault();
|
|
10524
|
-
console.log('mousedown');
|
|
10525
|
-
if (!mapHook.map)
|
|
10526
|
-
return;
|
|
10527
|
-
draggingResizeHandle.current = false;
|
|
10528
|
-
draggingRotationHandle.current = false;
|
|
10529
|
-
dragging.current = true;
|
|
10530
|
-
mapHook.map.map._canvas.style.cursor = 'move';
|
|
10531
|
-
function onMove(e) {
|
|
10532
|
-
e.preventDefault();
|
|
10533
|
-
if (!dragging.current || !pdfContext.geojsonRef || !pdfContext.orientation)
|
|
10534
|
-
return;
|
|
10535
|
-
var tmpGeojsonProps = JSON.parse(JSON.stringify(geojsonProps));
|
|
10536
|
-
tmpGeojsonProps.center = e.lngLat;
|
|
10537
|
-
tmpGeojsonProps.geojson = createPreviewGeojson(tmpGeojsonProps, pdfContext.orientation);
|
|
10538
|
-
pdfContext.geojsonRef.current = tmpGeojsonProps.geojson;
|
|
10539
|
-
setGeojsonProps(tmpGeojsonProps);
|
|
10155
|
+
fixedScaleRef.current = props.options.fixedScale;
|
|
10156
|
+
var point = turf.point(props.options.center);
|
|
10157
|
+
var distance = props.options.fixedScale * (props.options.width / 1000);
|
|
10158
|
+
var bearing = 90;
|
|
10159
|
+
var options = { units: 'meters' };
|
|
10160
|
+
var destination = turf.destination(point, distance, bearing, options);
|
|
10161
|
+
var centerInPixels = mapHook.map.map.project(point.geometry.coordinates);
|
|
10162
|
+
var destinationInPixels = mapHook.map.map.project(destination.geometry.coordinates);
|
|
10163
|
+
var scaleFactor = (Math.round(destinationInPixels.x - centerInPixels.x) / props.options.width) *
|
|
10164
|
+
(1 / getMapZoomScaleModifier([centerInPixels.x, centerInPixels.y], mapHook.map.map));
|
|
10165
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { scale: [scaleFactor, scaleFactor] })); });
|
|
10166
|
+
}, [mapHook.map, props.options.width, props.options.center, props.options.fixedScale]);
|
|
10167
|
+
// update props.geoJsonRef
|
|
10168
|
+
useEffect(function () {
|
|
10169
|
+
var _a;
|
|
10170
|
+
if (targetRef.current && mapHook.map) {
|
|
10171
|
+
// apply orientation
|
|
10172
|
+
var _width = props.options.width;
|
|
10173
|
+
var _height = props.options.height;
|
|
10174
|
+
if (props.options.orientation === 'portrait') {
|
|
10175
|
+
targetRef.current.style.width = props.options.width + 'px';
|
|
10176
|
+
targetRef.current.style.height = props.options.height + 'px';
|
|
10540
10177
|
}
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
mapHook.map.map.dragPan.enable();
|
|
10547
|
-
// Unbind mouse events
|
|
10548
|
-
mapHook.map.map.off('mousemove', onMove);
|
|
10549
|
-
mapHook.map.map.off('touchmove', onMove);
|
|
10178
|
+
else {
|
|
10179
|
+
targetRef.current.style.width = props.options.height + 'px';
|
|
10180
|
+
targetRef.current.style.height = props.options.width + 'px';
|
|
10181
|
+
_width = props.options.height;
|
|
10182
|
+
_height = props.options.width;
|
|
10550
10183
|
}
|
|
10551
|
-
|
|
10552
|
-
mapHook.map.map.
|
|
10553
|
-
mapHook.map.map.
|
|
10554
|
-
mapHook.map.map.
|
|
10555
|
-
mapHook.map.map.
|
|
10556
|
-
|
|
10557
|
-
});
|
|
10558
|
-
//map.on('mouseleave', 'point', function() {
|
|
10559
|
-
// map.setPaintProperty('point', 'circle-color', '#3887be');
|
|
10560
|
-
// canvas.style.cursor = '';
|
|
10561
|
-
// isCursorOverPoint = false;
|
|
10562
|
-
// map.dragPan.enable();
|
|
10563
|
-
//});
|
|
10564
|
-
return (React__default.createElement(React__default.Fragment, null, ((_a = geojsonProps === null || geojsonProps === void 0 ? void 0 : geojsonProps.geojson) === null || _a === void 0 ? void 0 : _a.bbox) && (React__default.createElement(React__default.Fragment, null,
|
|
10565
|
-
React__default.createElement(MlGeoJsonLayer, { paint: { 'line-color': '#616161', 'line-width': 4 }, type: "line", layerId: "pdfPreviewGeojsonOutline", geojson: geojsonProps.geojson }),
|
|
10566
|
-
React__default.createElement(MlGeoJsonLayer, { paint: { 'fill-opacity': 0 }, type: "fill", layerId: "pdfPreviewGeojson", geojson: geojsonProps.geojson }),
|
|
10567
|
-
React__default.createElement(MlGeoJsonLayer, { layerId: "pdfPreviewGeojsonResizeHandle", paint: {
|
|
10568
|
-
'circle-radius': 10,
|
|
10569
|
-
'circle-color': '#1976d2',
|
|
10570
|
-
'circle-stroke-width': 2,
|
|
10571
|
-
'circle-stroke-color': '#ffffff',
|
|
10572
|
-
}, geojson: {
|
|
10184
|
+
(_a = moveableRef.current) === null || _a === void 0 ? void 0 : _a.updateTarget();
|
|
10185
|
+
var topLeft = mapHook.map.map.unproject(calcElemTransformedPoint(targetRef.current, [0, 0], transformOrigin));
|
|
10186
|
+
var topRight = mapHook.map.map.unproject(calcElemTransformedPoint(targetRef.current, [_width, 0], transformOrigin));
|
|
10187
|
+
var bottomLeft = mapHook.map.map.unproject(calcElemTransformedPoint(targetRef.current, [0, _height], transformOrigin));
|
|
10188
|
+
var bottomRight = mapHook.map.map.unproject(calcElemTransformedPoint(targetRef.current, [_width, _height], transformOrigin));
|
|
10189
|
+
var _geoJson = {
|
|
10573
10190
|
type: 'Feature',
|
|
10191
|
+
bbox: [topLeft.lng, topLeft.lat, bottomRight.lng, bottomRight.lat],
|
|
10574
10192
|
geometry: {
|
|
10575
|
-
type: '
|
|
10576
|
-
|
|
10577
|
-
|
|
10193
|
+
type: 'Polygon',
|
|
10194
|
+
coordinates: [
|
|
10195
|
+
[
|
|
10196
|
+
[topLeft.lng, topLeft.lat],
|
|
10197
|
+
[topRight.lng, topRight.lat],
|
|
10198
|
+
[bottomRight.lng, bottomRight.lat],
|
|
10199
|
+
[bottomLeft.lng, bottomLeft.lat],
|
|
10200
|
+
[topLeft.lng, topLeft.lat],
|
|
10201
|
+
],
|
|
10202
|
+
],
|
|
10578
10203
|
},
|
|
10579
|
-
properties: {},
|
|
10580
|
-
}
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10204
|
+
properties: { bearing: getTargetRotationAngle(targetRef.current) },
|
|
10205
|
+
};
|
|
10206
|
+
props.geojsonRef.current = _geoJson;
|
|
10207
|
+
}
|
|
10208
|
+
return undefined;
|
|
10209
|
+
}, [
|
|
10210
|
+
mapHook,
|
|
10211
|
+
transform,
|
|
10212
|
+
props.options.orientation,
|
|
10213
|
+
props.geojsonRef,
|
|
10214
|
+
mapState,
|
|
10215
|
+
targetRef.current,
|
|
10216
|
+
transformOrigin,
|
|
10217
|
+
]);
|
|
10218
|
+
return mapContainerRef.current ? ReactDOM__default.createPortal(React__default.createElement(React__default.Fragment, null,
|
|
10219
|
+
React__default.createElement("div", { className: "target", ref: targetRef, style: { transform: transform, transformOrigin: 'center center' } }),
|
|
10220
|
+
React__default.createElement(Moveable
|
|
10221
|
+
// eslint-disable-next-line
|
|
10222
|
+
// @ts-ignore:
|
|
10223
|
+
, {
|
|
10224
|
+
// eslint-disable-next-line
|
|
10225
|
+
// @ts-ignore:
|
|
10226
|
+
ref: moveableRef, target: targetRef, container: null, origin: true, keepRatio: true,
|
|
10227
|
+
/* draggable */
|
|
10228
|
+
draggable: true, onDrag: function (e) {
|
|
10229
|
+
var _a;
|
|
10230
|
+
if (mapHook.map) {
|
|
10231
|
+
var _transformParts = e.transform.split('translate(');
|
|
10232
|
+
_transformParts = _transformParts[1].split('px)')[0].split('px, ');
|
|
10233
|
+
var _center_2 = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.unproject([
|
|
10234
|
+
parseInt(_transformParts[0]) + transformOrigin[0],
|
|
10235
|
+
parseInt(_transformParts[1]) + transformOrigin[1],
|
|
10236
|
+
]);
|
|
10237
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { center: [_center_2.lng, _center_2.lat] })); });
|
|
10238
|
+
}
|
|
10239
|
+
},
|
|
10240
|
+
/* scalable */
|
|
10241
|
+
scalable: props.options.fixedScale ? false : true, onScale: function (e) {
|
|
10242
|
+
if (mapHook.map) {
|
|
10243
|
+
var _transformParts = e.drag.transform.split('scale(');
|
|
10244
|
+
_transformParts = _transformParts[1].split(')')[0].split(', ');
|
|
10245
|
+
var centerInPixels = mapHook.map.map.project(props.options.center);
|
|
10246
|
+
var x = centerInPixels.x;
|
|
10247
|
+
var y = centerInPixels.y;
|
|
10248
|
+
var scale_2 = parseFloat(_transformParts[0]) *
|
|
10249
|
+
(1 / getMapZoomScaleModifier([x, y], mapHook.map.map));
|
|
10250
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { scale: [scale_2, scale_2] })); });
|
|
10251
|
+
}
|
|
10252
|
+
},
|
|
10253
|
+
/* rotatable */
|
|
10254
|
+
rotatable: true, onRotate: function (e) {
|
|
10255
|
+
var _a;
|
|
10256
|
+
if (mapHook.map && mapState.viewport) {
|
|
10257
|
+
var _transformParts = e.drag.transform.split('rotate(');
|
|
10258
|
+
var _transformPartString_1 = _transformParts[1].split('deg)')[0];
|
|
10259
|
+
var viewportBearing_1 = ((_a = mapState === null || mapState === void 0 ? void 0 : mapState.viewport) === null || _a === void 0 ? void 0 : _a.bearing) ? mapState.viewport.bearing : 0;
|
|
10260
|
+
props.setOptions(function (val) { return (__assign(__assign({}, val), { rotate: parseFloat(_transformPartString_1) + viewportBearing_1 })); });
|
|
10261
|
+
}
|
|
10262
|
+
} })), mapContainerRef.current) : React__default.createElement(React__default.Fragment, null);
|
|
10595
10263
|
}
|
|
10596
10264
|
|
|
10597
10265
|
var createExport = function (options) {
|
|
@@ -10633,38 +10301,15 @@ var createExport = function (options) {
|
|
|
10633
10301
|
attributionControl: false,
|
|
10634
10302
|
style: style,
|
|
10635
10303
|
});
|
|
10636
|
-
var
|
|
10637
|
-
|
|
10638
|
-
options.bbox[1],
|
|
10639
|
-
options.bbox[2],
|
|
10640
|
-
options.bbox[3],
|
|
10641
|
-
]);
|
|
10642
|
-
_previewGeojson = turf.transformRotate(_previewGeojson, options.bearing);
|
|
10643
|
-
// use original unrotated bbox and bearing 0 to calculate the correct zoom value as the function always adds a padding if used on the rotated feature coordinates
|
|
10644
|
-
var bboxCamera = renderMap._cameraForBoxAndBearing([options.bboxUnrotated[0], options.bboxUnrotated[1]], [options.bboxUnrotated[2], options.bboxUnrotated[3]], 0);
|
|
10645
|
-
var geometryCamera = renderMap._cameraForBoxAndBearing(_previewGeojson.geometry.coordinates[0][0], _previewGeojson.geometry.coordinates[0][2], options.bearing);
|
|
10646
|
-
geometryCamera.zoom = bboxCamera.zoom;
|
|
10647
|
-
renderMap._fitInternal(geometryCamera);
|
|
10304
|
+
var bboxCamera = renderMap._cameraForBoxAndBearing([options.bboxUnrotated[0], options.bboxUnrotated[1]], [options.bboxUnrotated[2], options.bboxUnrotated[3]], options.bearing + options.map.map.getBearing());
|
|
10305
|
+
renderMap._fitInternal(bboxCamera);
|
|
10648
10306
|
return new Promise(function (resolve) {
|
|
10307
|
+
console.log('before idle');
|
|
10649
10308
|
renderMap.once('idle', function () {
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
renderMap.setLayoutProperty('pdfPreviewGeojson', 'visibility', 'none');
|
|
10655
|
-
}
|
|
10656
|
-
if (renderMap.getLayer('pdfPreviewGeojsonResizeHandle')) {
|
|
10657
|
-
renderMap.setLayoutProperty('pdfPreviewGeojsonResizeHandle', 'visibility', 'none');
|
|
10658
|
-
}
|
|
10659
|
-
if (renderMap.getLayer('pdfPreviewGeojsonRotationHandle')) {
|
|
10660
|
-
renderMap.setLayoutProperty('pdfPreviewGeojsonRotationHandle', 'visibility', 'none');
|
|
10661
|
-
}
|
|
10662
|
-
renderMap.once('idle', function () {
|
|
10663
|
-
var params = __assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer, createPdf: function (_options) {
|
|
10664
|
-
return createJsPdf(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
|
|
10665
|
-
} });
|
|
10666
|
-
resolve(params);
|
|
10667
|
-
});
|
|
10309
|
+
var params = __assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer, createPdf: function (_options) {
|
|
10310
|
+
return createJsPdf(__assign(__assign(__assign({}, options), { renderMap: renderMap, hiddenContainer: hiddenContainer }), _options));
|
|
10311
|
+
} });
|
|
10312
|
+
resolve(params);
|
|
10668
10313
|
});
|
|
10669
10314
|
});
|
|
10670
10315
|
};
|
|
@@ -10713,6 +10358,44 @@ function useExportMap(props) {
|
|
|
10713
10358
|
};
|
|
10714
10359
|
}
|
|
10715
10360
|
|
|
10361
|
+
var scaleOptions = [
|
|
10362
|
+
{
|
|
10363
|
+
value: 0,
|
|
10364
|
+
label: 'free scale',
|
|
10365
|
+
},
|
|
10366
|
+
{
|
|
10367
|
+
value: 250,
|
|
10368
|
+
label: '1/250',
|
|
10369
|
+
},
|
|
10370
|
+
{
|
|
10371
|
+
value: 500,
|
|
10372
|
+
label: '1/500',
|
|
10373
|
+
},
|
|
10374
|
+
{
|
|
10375
|
+
value: 750,
|
|
10376
|
+
label: '1/750',
|
|
10377
|
+
},
|
|
10378
|
+
{
|
|
10379
|
+
value: 1000,
|
|
10380
|
+
label: '1/1000',
|
|
10381
|
+
},
|
|
10382
|
+
{
|
|
10383
|
+
value: 1500,
|
|
10384
|
+
label: '1/1500',
|
|
10385
|
+
},
|
|
10386
|
+
{
|
|
10387
|
+
value: 2000,
|
|
10388
|
+
label: '1/2000',
|
|
10389
|
+
},
|
|
10390
|
+
{
|
|
10391
|
+
value: 10000,
|
|
10392
|
+
label: '1/10000',
|
|
10393
|
+
},
|
|
10394
|
+
{
|
|
10395
|
+
value: 100000,
|
|
10396
|
+
label: '1/100000',
|
|
10397
|
+
},
|
|
10398
|
+
];
|
|
10716
10399
|
var qualityOptions = [
|
|
10717
10400
|
{
|
|
10718
10401
|
value: '72dpi',
|
|
@@ -10728,6 +10411,7 @@ var qualityOptions = [
|
|
|
10728
10411
|
},
|
|
10729
10412
|
];
|
|
10730
10413
|
function PdfForm(props) {
|
|
10414
|
+
var _a, _b;
|
|
10731
10415
|
var pdfContext = useContext(PdfContext);
|
|
10732
10416
|
var mapHook = useMap({
|
|
10733
10417
|
// eslint-disable-next-line react/prop-types
|
|
@@ -10735,14 +10419,14 @@ function PdfForm(props) {
|
|
|
10735
10419
|
});
|
|
10736
10420
|
var mapExporter = useExportMap({ mapId: props.mapId });
|
|
10737
10421
|
var createPdfHandler = useCallback(function () {
|
|
10738
|
-
var _a, _b, _c, _d, _e;
|
|
10422
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10739
10423
|
if (mapHook.map &&
|
|
10740
10424
|
mapExporter.createExport &&
|
|
10741
10425
|
pdfContext.template &&
|
|
10742
10426
|
pdfContext.format &&
|
|
10743
|
-
pdfContext.orientation &&
|
|
10744
|
-
((
|
|
10745
|
-
((
|
|
10427
|
+
((_a = pdfContext.options) === null || _a === void 0 ? void 0 : _a.orientation) &&
|
|
10428
|
+
((_c = (_b = pdfContext.geojsonRef) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.bbox) &&
|
|
10429
|
+
((_d = pdfContext.geojsonRef) === null || _d === void 0 ? void 0 : _d.current)) {
|
|
10746
10430
|
var bbox = turf.bbox(pdfContext.geojsonRef.current);
|
|
10747
10431
|
mapExporter
|
|
10748
10432
|
.createExport({
|
|
@@ -10750,9 +10434,9 @@ function PdfForm(props) {
|
|
|
10750
10434
|
height: pdfContext.template.height,
|
|
10751
10435
|
bbox: bbox,
|
|
10752
10436
|
bboxUnrotated: pdfContext.geojsonRef.current.bbox,
|
|
10753
|
-
bearing: ((
|
|
10437
|
+
bearing: ((_f = (_e = pdfContext.geojsonRef.current) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f.bearing) || 0,
|
|
10754
10438
|
format: pdfContext.format.toLowerCase(),
|
|
10755
|
-
orientation: pdfContext.orientation,
|
|
10439
|
+
orientation: pdfContext.options.orientation,
|
|
10756
10440
|
})
|
|
10757
10441
|
.then(function (res) { return res.createPdf(); })
|
|
10758
10442
|
.then(function (res) {
|
|
@@ -10783,9 +10467,10 @@ function PdfForm(props) {
|
|
|
10783
10467
|
} }, Object.keys(PdfTemplates).map(function (el) { return (React__default.createElement(MenuItem, { key: el, value: el }, el)); }))),
|
|
10784
10468
|
React__default.createElement(FormControl, { fullWidth: true, sx: formControlStyles },
|
|
10785
10469
|
React__default.createElement(FormLabel, { id: "orientation-radio-buttons-group-label" }, "Orientation"),
|
|
10786
|
-
React__default.createElement(RadioGroup, { row: true, "aria-labelledby": "orientation-radio-buttons-group-label", name: "orientation-radio-buttons-group", value: pdfContext.orientation, onChange: function (event) {
|
|
10787
|
-
|
|
10788
|
-
|
|
10470
|
+
React__default.createElement(RadioGroup, { row: true, "aria-labelledby": "orientation-radio-buttons-group-label", name: "orientation-radio-buttons-group", value: (_a = pdfContext.options) === null || _a === void 0 ? void 0 : _a.orientation, onChange: function (event) {
|
|
10471
|
+
if (!pdfContext.setOptions)
|
|
10472
|
+
return;
|
|
10473
|
+
pdfContext.setOptions(function (val) { return (__assign(__assign({}, val), { orientation: event.target.value })); });
|
|
10789
10474
|
} },
|
|
10790
10475
|
React__default.createElement(FormControlLabel, { value: "portrait", control: React__default.createElement(Radio, null), label: "Portrait" }),
|
|
10791
10476
|
React__default.createElement(FormControlLabel, { value: "landscape", control: React__default.createElement(Radio, null), label: "Landscape" }))),
|
|
@@ -10796,7 +10481,14 @@ function PdfForm(props) {
|
|
|
10796
10481
|
(_a = pdfContext.setQuality) === null || _a === void 0 ? void 0 : _a.call(pdfContext, event.target.value);
|
|
10797
10482
|
} }, qualityOptions.map(function (el) { return (React__default.createElement(MenuItem, { key: el.value, value: el.value }, el.label)); }))),
|
|
10798
10483
|
React__default.createElement(FormControl, { fullWidth: true, sx: formControlStyles },
|
|
10799
|
-
React__default.createElement(
|
|
10484
|
+
React__default.createElement(InputLabel, { id: "quality-select-label" }, "Scale"),
|
|
10485
|
+
React__default.createElement(Select, { labelId: "quality-select-label", id: "quality-select", label: "Qualit\u00E4t", value: (_b = pdfContext === null || pdfContext === void 0 ? void 0 : pdfContext.options) === null || _b === void 0 ? void 0 : _b.fixedScale, onChange: function (event) {
|
|
10486
|
+
var _a;
|
|
10487
|
+
(_a = pdfContext.setOptions) === null || _a === void 0 ? void 0 : _a.call(pdfContext, function (val) { return (__assign(__assign({}, val), { fixedScale: event.target.value })); });
|
|
10488
|
+
} }, scaleOptions.map(function (el, idx) { return (React__default.createElement(MenuItem, { key: idx, value: el.value }, el.label)); }))),
|
|
10489
|
+
React__default.createElement(FormControl, { fullWidth: true, sx: formControlStyles },
|
|
10490
|
+
React__default.createElement(Button$2, { variant: "contained", onClick: createPdfHandler }, "PDF erstellen")),
|
|
10491
|
+
pdfContext.options && pdfContext.setOptions && (React__default.createElement(PdfPreview, { options: pdfContext.options, setOptions: pdfContext.setOptions, geojsonRef: pdfContext.geojsonRef }))));
|
|
10800
10492
|
}
|
|
10801
10493
|
|
|
10802
10494
|
/**
|
|
@@ -10806,8 +10498,7 @@ function PdfForm(props) {
|
|
|
10806
10498
|
var MlCreatePdfForm = function (props) {
|
|
10807
10499
|
return (React__default.createElement(React__default.Fragment, null,
|
|
10808
10500
|
React__default.createElement(PdfContextProvider, null,
|
|
10809
|
-
React__default.createElement(PdfForm, __assign({}, props))
|
|
10810
|
-
React__default.createElement(PdfPreview, null))));
|
|
10501
|
+
React__default.createElement(PdfForm, __assign({}, props)))));
|
|
10811
10502
|
};
|
|
10812
10503
|
MlCreatePdfForm.defaultProps = {
|
|
10813
10504
|
mapId: undefined,
|
|
@@ -13157,6 +12848,145 @@ var MlFeatureEditor = function (props) {
|
|
|
13157
12848
|
return React__default.createElement(React__default.Fragment, null);
|
|
13158
12849
|
};
|
|
13159
12850
|
|
|
12851
|
+
var legalLayerTypes = [
|
|
12852
|
+
'fill',
|
|
12853
|
+
'line',
|
|
12854
|
+
'symbol',
|
|
12855
|
+
'circle',
|
|
12856
|
+
'heatmap',
|
|
12857
|
+
'fill-extrusion',
|
|
12858
|
+
'raster',
|
|
12859
|
+
'hillshade',
|
|
12860
|
+
'background',
|
|
12861
|
+
];
|
|
12862
|
+
function useLayer(props) {
|
|
12863
|
+
var mapHook = useMap({
|
|
12864
|
+
mapId: props.mapId,
|
|
12865
|
+
waitForLayer: props.insertBeforeLayer,
|
|
12866
|
+
});
|
|
12867
|
+
var layerTypeRef = useRef('');
|
|
12868
|
+
var layerPaintConfRef = useRef('');
|
|
12869
|
+
var layerLayoutConfRef = useRef('');
|
|
12870
|
+
var _a = useState(), layer = _a[0], setLayer = _a[1];
|
|
12871
|
+
var initializedRef = useRef(false);
|
|
12872
|
+
var layerId = useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
|
|
12873
|
+
var createLayer = useCallback(function () {
|
|
12874
|
+
var _a, _b;
|
|
12875
|
+
if (!mapHook.map)
|
|
12876
|
+
return;
|
|
12877
|
+
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
12878
|
+
mapHook.cleanup();
|
|
12879
|
+
}
|
|
12880
|
+
if (mapHook.map.map.getSource(layerId.current)) {
|
|
12881
|
+
mapHook.map.map.removeSource(layerId.current);
|
|
12882
|
+
}
|
|
12883
|
+
if (typeof props.source === 'string') {
|
|
12884
|
+
if (props.source === '' || !mapHook.map.map.getSource(props.source)) {
|
|
12885
|
+
return;
|
|
12886
|
+
}
|
|
12887
|
+
}
|
|
12888
|
+
initializedRef.current = true;
|
|
12889
|
+
mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson && !props.source
|
|
12890
|
+
? {
|
|
12891
|
+
source: {
|
|
12892
|
+
type: 'geojson',
|
|
12893
|
+
data: props.geojson,
|
|
12894
|
+
},
|
|
12895
|
+
}
|
|
12896
|
+
: {})), (props.source
|
|
12897
|
+
? {
|
|
12898
|
+
source: props.source,
|
|
12899
|
+
}
|
|
12900
|
+
: {})), { id: layerId.current }), props.insertBeforeLayer
|
|
12901
|
+
? props.insertBeforeLayer
|
|
12902
|
+
: props.insertBeforeFirstSymbolLayer
|
|
12903
|
+
? mapHook.map.firstSymbolLayer
|
|
12904
|
+
: undefined, mapHook.componentId);
|
|
12905
|
+
setLayer(mapHook.map.map.getLayer(layerId.current));
|
|
12906
|
+
if (typeof props.onHover !== 'undefined') {
|
|
12907
|
+
mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
|
|
12908
|
+
}
|
|
12909
|
+
if (typeof props.onClick !== 'undefined') {
|
|
12910
|
+
mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
|
|
12911
|
+
}
|
|
12912
|
+
if (typeof props.onLeave !== 'undefined') {
|
|
12913
|
+
mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
|
|
12914
|
+
}
|
|
12915
|
+
// recreate layer if style has changed
|
|
12916
|
+
mapHook.map.on('styledata', function () {
|
|
12917
|
+
var _a;
|
|
12918
|
+
if (initializedRef.current && !((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
|
|
12919
|
+
console.log('Recreate Layer');
|
|
12920
|
+
createLayer();
|
|
12921
|
+
}
|
|
12922
|
+
}, mapHook.componentId);
|
|
12923
|
+
layerPaintConfRef.current = JSON.stringify((_a = props.options) === null || _a === void 0 ? void 0 : _a.paint);
|
|
12924
|
+
layerLayoutConfRef.current = JSON.stringify((_b = props.options) === null || _b === void 0 ? void 0 : _b.layout);
|
|
12925
|
+
layerTypeRef.current = props.options.type;
|
|
12926
|
+
}, [props, mapHook.map]);
|
|
12927
|
+
useEffect(function () {
|
|
12928
|
+
if (!mapHook.map)
|
|
12929
|
+
return;
|
|
12930
|
+
if (initializedRef.current &&
|
|
12931
|
+
(legalLayerTypes.indexOf(props.options.type) === -1 ||
|
|
12932
|
+
(legalLayerTypes.indexOf(props.options.type) !== -1 &&
|
|
12933
|
+
props.options.type === layerTypeRef.current))) {
|
|
12934
|
+
return;
|
|
12935
|
+
}
|
|
12936
|
+
createLayer();
|
|
12937
|
+
}, [mapHook.map, props.options, createLayer]);
|
|
12938
|
+
useEffect(function () {
|
|
12939
|
+
var _a, _b, _c, _d;
|
|
12940
|
+
if (!initializedRef.current || !((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(layerId.current)))
|
|
12941
|
+
return;
|
|
12942
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12943
|
+
//@ts-ignore setData only exists on GeoJsonSource
|
|
12944
|
+
(_d = (_c = mapHook.map.map.getSource(layerId.current)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.geojson);
|
|
12945
|
+
}, [props.geojson, mapHook.map, props.options.type]);
|
|
12946
|
+
useEffect(function () {
|
|
12947
|
+
var _a, _b, _c, _d, _e;
|
|
12948
|
+
if (!mapHook.map ||
|
|
12949
|
+
!((_c = (_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getLayer) === null || _c === void 0 ? void 0 : _c.call(_b, layerId.current)) ||
|
|
12950
|
+
!initializedRef.current ||
|
|
12951
|
+
props.options.type !== layerTypeRef.current)
|
|
12952
|
+
return;
|
|
12953
|
+
var key;
|
|
12954
|
+
var layoutString = JSON.stringify(props.options.layout);
|
|
12955
|
+
if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
|
|
12956
|
+
var oldLayout = JSON.parse(layerLayoutConfRef.current);
|
|
12957
|
+
for (key in props.options.layout) {
|
|
12958
|
+
if (((_d = props.options.layout) === null || _d === void 0 ? void 0 : _d[key]) && props.options.layout[key] !== oldLayout[key]) {
|
|
12959
|
+
mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
|
|
12960
|
+
}
|
|
12961
|
+
}
|
|
12962
|
+
layerLayoutConfRef.current = layoutString;
|
|
12963
|
+
}
|
|
12964
|
+
var paintString = JSON.stringify(props.options.paint);
|
|
12965
|
+
if (paintString !== layerPaintConfRef.current) {
|
|
12966
|
+
var oldPaint = JSON.parse(layerPaintConfRef.current);
|
|
12967
|
+
for (key in props.options.paint) {
|
|
12968
|
+
if (((_e = props.options.paint) === null || _e === void 0 ? void 0 : _e[key]) && props.options.paint[key] !== oldPaint[key]) {
|
|
12969
|
+
mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
|
|
12970
|
+
}
|
|
12971
|
+
}
|
|
12972
|
+
layerPaintConfRef.current = paintString;
|
|
12973
|
+
}
|
|
12974
|
+
}, [props.options, mapHook.map]);
|
|
12975
|
+
useEffect(function () {
|
|
12976
|
+
return function () {
|
|
12977
|
+
initializedRef.current = false;
|
|
12978
|
+
mapHook.cleanup();
|
|
12979
|
+
};
|
|
12980
|
+
}, []);
|
|
12981
|
+
return {
|
|
12982
|
+
map: mapHook.map,
|
|
12983
|
+
layer: layer,
|
|
12984
|
+
layerId: layerId.current,
|
|
12985
|
+
componentId: mapHook.componentId,
|
|
12986
|
+
mapHook: mapHook,
|
|
12987
|
+
};
|
|
12988
|
+
}
|
|
12989
|
+
|
|
13160
12990
|
/**
|
|
13161
12991
|
* Adds a fill extrusion layer to the MapLibre instance reference by props.mapId
|
|
13162
12992
|
*
|
|
@@ -13193,6 +13023,84 @@ MlFillExtrusionLayer.defaultProps = {
|
|
|
13193
13023
|
},
|
|
13194
13024
|
};
|
|
13195
13025
|
|
|
13026
|
+
var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
|
|
13027
|
+
switch (type) {
|
|
13028
|
+
case "fill":
|
|
13029
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.fill) {
|
|
13030
|
+
return defaultPaintOverrides.fill;
|
|
13031
|
+
}
|
|
13032
|
+
return {
|
|
13033
|
+
"fill-color": "rgba(10,240,256,0.6)",
|
|
13034
|
+
};
|
|
13035
|
+
case "line":
|
|
13036
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
|
|
13037
|
+
return defaultPaintOverrides.line;
|
|
13038
|
+
}
|
|
13039
|
+
return {
|
|
13040
|
+
"line-color": "rgb(203,211,2)",
|
|
13041
|
+
"line-width": 5,
|
|
13042
|
+
};
|
|
13043
|
+
case "circle":
|
|
13044
|
+
default:
|
|
13045
|
+
if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.circle) {
|
|
13046
|
+
return defaultPaintOverrides.circle;
|
|
13047
|
+
}
|
|
13048
|
+
return {
|
|
13049
|
+
"circle-color": "rgba(10,240,256,0.8)",
|
|
13050
|
+
"circle-stroke-color": "#fff",
|
|
13051
|
+
"circle-stroke-width": 2,
|
|
13052
|
+
};
|
|
13053
|
+
}
|
|
13054
|
+
};
|
|
13055
|
+
|
|
13056
|
+
var mapGeometryTypesToLayerTypes = {
|
|
13057
|
+
Position: "circle",
|
|
13058
|
+
Point: "circle",
|
|
13059
|
+
MultiPoint: "circle",
|
|
13060
|
+
LineString: "line",
|
|
13061
|
+
MultiLineString: "line",
|
|
13062
|
+
Polygon: "fill",
|
|
13063
|
+
MultiPolygon: "fill",
|
|
13064
|
+
GeometryCollection: "circle",
|
|
13065
|
+
};
|
|
13066
|
+
var getDefaulLayerTypeByGeometry = function (geojson) {
|
|
13067
|
+
var _a;
|
|
13068
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "Feature") {
|
|
13069
|
+
return (mapGeometryTypesToLayerTypes === null || mapGeometryTypesToLayerTypes === void 0 ? void 0 : mapGeometryTypesToLayerTypes[(_a = geojson === null || geojson === void 0 ? void 0 : geojson.geometry) === null || _a === void 0 ? void 0 : _a.type])
|
|
13070
|
+
? mapGeometryTypesToLayerTypes[geojson.geometry.type]
|
|
13071
|
+
: "circle";
|
|
13072
|
+
}
|
|
13073
|
+
if ((geojson === null || geojson === void 0 ? void 0 : geojson.type) === "FeatureCollection") {
|
|
13074
|
+
if (geojson.features.length) {
|
|
13075
|
+
return getDefaulLayerTypeByGeometry(geojson.features[0]);
|
|
13076
|
+
}
|
|
13077
|
+
return "circle";
|
|
13078
|
+
}
|
|
13079
|
+
return "fill";
|
|
13080
|
+
};
|
|
13081
|
+
|
|
13082
|
+
/**
|
|
13083
|
+
* Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
|
|
13084
|
+
*
|
|
13085
|
+
* @component
|
|
13086
|
+
*/
|
|
13087
|
+
var MlGeoJsonLayer = function (props) {
|
|
13088
|
+
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
13089
|
+
// Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
|
|
13090
|
+
useLayer({
|
|
13091
|
+
mapId: props.mapId,
|
|
13092
|
+
layerId: props.layerId || "MlGeoJsonLayer-" + v4(),
|
|
13093
|
+
geojson: props.geojson,
|
|
13094
|
+
options: __assign(__assign({ paint: props.paint ||
|
|
13095
|
+
getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides), layout: props.layout || {} }, props.options), { type: layerType }),
|
|
13096
|
+
insertBeforeLayer: props.insertBeforeLayer,
|
|
13097
|
+
onHover: props.onHover,
|
|
13098
|
+
onClick: props.onClick,
|
|
13099
|
+
onLeave: props.onLeave,
|
|
13100
|
+
});
|
|
13101
|
+
return (React__default.createElement(React__default.Fragment, null));
|
|
13102
|
+
};
|
|
13103
|
+
|
|
13196
13104
|
var GpsFixed = {};
|
|
13197
13105
|
|
|
13198
13106
|
var _interopRequireDefault$4 = interopRequireDefault.exports;
|
|
@@ -19891,5 +19799,5 @@ SimpleDataProvider.propTypes = {
|
|
|
19891
19799
|
children: PropTypes.node.isRequired
|
|
19892
19800
|
};
|
|
19893
19801
|
|
|
19894
|
-
export { GeoJsonContext, GeoJsonProvider, MapComponentsProvider, MapContext, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlCreatePdfForm, MlFeatureEditor, MlFillExtrusionLayer, MlFollowGps, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlMarker, MlMeasureTool, MlNavigationCompass, MlNavigationTools, MlOsmLayer, MlScaleReference, MlSpatialElevationProfile, MlTransitionGeoJsonLayer, MlVectorTileLayer, MlWmsLayer, SimpleDataContext, SimpleDataProvider, useCameraFollowPath, useExportMap, useLayer, useMap, useMapState, useSource, useWms };
|
|
19802
|
+
export { GeoJsonContext, GeoJsonProvider, MapComponentsProvider, MapContext, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlCreatePdfForm, MlFeatureEditor, MlFillExtrusionLayer, MlFollowGps, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlMarker, MlMeasureTool, MlNavigationCompass, MlNavigationTools, MlOsmLayer, PdfPreview as MlPdfPreview, MlScaleReference, MlSpatialElevationProfile, MlTransitionGeoJsonLayer, MlVectorTileLayer, MlWmsLayer, SimpleDataContext, SimpleDataProvider, useCameraFollowPath, useExportMap, useLayer, useMap, useMapState, useSource, useWms };
|
|
19895
19803
|
//# sourceMappingURL=index.esm.js.map
|