Skip to content

Commit

Permalink
Merge pull request #1531 from terrestris/add-XYZ-Serializer
Browse files Browse the repository at this point in the history
feat: adds XYZ Serializer
  • Loading branch information
dnlkoch authored Nov 7, 2024
2 parents eabc926 + a0141cf commit 02c71a6
Showing 1 changed file with 129 additions and 108 deletions.
237 changes: 129 additions & 108 deletions src/components/PrintForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React, {
useCallback, useEffect, useState
useCallback,
useEffect,
useState
} from 'react';

import { faDownload } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import {
Alert, Button, Form
Alert,
Button,
Form
} from 'antd';
import { FormProps } from 'antd/lib/form/Form';

import ClientConfiguration from 'clientConfig';

import _isNil from 'lodash/isNil';

import OlLayerGroup from 'ol/layer/Group';
Expand All @@ -23,23 +29,32 @@ import { useTranslation } from 'react-i18next';

import Logger from '@terrestris/base-util/dist/Logger';

import { MapFishPrintV3Manager } from '@terrestris/mapfish-print-manager';
import { MapFishPrintV3ManagerOpts } from '@terrestris/mapfish-print-manager/dist/manager/MapFishPrintV3Manager';
import {
MapFishPrintV3Manager,
MapFishPrintV3ManagerOpts
} from '@terrestris/mapfish-print-manager/dist/manager/MapFishPrintV3Manager';
import { MapFishPrintV3GeoJsonSerializer }
from '@terrestris/mapfish-print-manager/dist/serializer/MapFishPrintV3GeoJsonSerializer';
import { MapFishPrintV3OSMSerializer } from '@terrestris/mapfish-print-manager/dist/serializer/MapFishPrintV3OSMSerializer';
import { MapFishPrintV3StamenSerializer } from '@terrestris/mapfish-print-manager/dist/serializer/MapFishPrintV3StamenSerializer';
import { MapFishPrintV3WMTSSerializer }
from '@terrestris/mapfish-print-manager/dist/serializer/MapFishPrintV3WMTSSerializer';
import { MapFishPrintV3XYZSerializer } from '@terrestris/mapfish-print-manager/dist/serializer/MapFishPrintV3XYZSerializer';

import LayerUtil from '@terrestris/ol-util/dist/LayerUtil/LayerUtil';
import { MapUtil } from '@terrestris/ol-util/dist/MapUtil/MapUtil';

import { useAsyncEffect } from '@terrestris/react-util/dist/Hooks/useAsyncEffect/useAsyncEffect';
import { useMap } from '@terrestris/react-util/dist/Hooks/useMap/useMap';

import { getBearerTokenHeader } from '@terrestris/shogun-util/dist/security/getBearerTokenHeader';

import useAppDispatch from '../../hooks/useAppDispatch';
import useAppSelector from '../../hooks/useAppSelector';
import useSHOGunAPIClient from '../../hooks/useSHOGunAPIClient';

import { addCustomParam } from '../../store/print';

import SHOGunMapFishPrintV3TiledWMSSerializer from '../PrintForm/Serializer/SHOGunMapFishPrintV3TiledWMSSerializer';
import SHOGunMapFishPrintV3WMSSerializer from '../PrintForm/Serializer/SHOGunMapFishPrintV3WMSSerializer';

Expand Down Expand Up @@ -69,7 +84,6 @@ export type LayerType = OlLayer<OlSource, OlLayerRenderer<OlLayerVector<OlSource
export const PrintForm: React.FC<PrintFormProps> = ({
active,
customPrintScales = [],

layerBlackList = [],
outputFormats = ['pdf', 'png'],
...restProps
Expand Down Expand Up @@ -167,7 +181,7 @@ export const PrintForm: React.FC<PrintFormProps> = ({
return allAttributions.join(', ').trim();
}, [getPrintableLayers]);

const initializeMapProvider = useCallback(async () => {
const initializePrintManager = useCallback(async () => {
if (_isNil(map)) {
return;
}
Expand Down Expand Up @@ -198,9 +212,11 @@ export const PrintForm: React.FC<PrintFormProps> = ({
rotate: false
},
serializers: [
new MapFishPrintV3StamenSerializer(),
new MapFishPrintV3GeoJsonSerializer(),
new MapFishPrintV3OSMSerializer(),
new MapFishPrintV3WMTSSerializer(),
new MapFishPrintV3XYZSerializer(),
new SHOGunMapFishPrintV3WMSSerializer(),
new SHOGunMapFishPrintV3TiledWMSSerializer()
],
Expand Down Expand Up @@ -235,7 +251,8 @@ export const PrintForm: React.FC<PrintFormProps> = ({
pManager.setOutputFormat(pManager.getOutputFormats()[0]);
pManager.setDpi(pManager.getDpis()[0]);
pManager.setLayout(pManager.getLayouts()[0]?.name);
setPrintManager(pManager);

return pManager;
} catch (error) {
setErrorMsg(() => t('PrintForm.managerErrorMessage'));
Logger.error('Could not initialize print manager: ', error);
Expand All @@ -250,17 +267,20 @@ export const PrintForm: React.FC<PrintFormProps> = ({
}
}, [dispatch, getAttributions, printManager]);

useEffect(() => {
useAsyncEffect(async () => {
if (active) {
if (!printManager) {
form.resetFields();
initializeMapProvider();
const manager = await initializePrintManager();
if (manager) {
setPrintManager(manager);
}
}
} else {
printManager?.shutdownManager();
setPrintManager(null);
}
}, [printManager, active, initializeMapProvider, form]);
}, [printManager, active, initializePrintManager, form]);

useEffect(() => {
if (printManager) {
Expand Down Expand Up @@ -308,7 +328,7 @@ export const PrintForm: React.FC<PrintFormProps> = ({
return (
<div
className="print"
aria-label='print-form'
aria-label="print-form"
>
{
errorMsg && (
Expand All @@ -322,103 +342,104 @@ export const PrintForm: React.FC<PrintFormProps> = ({
/>
)
}
{
printManager?.isInitiated() && (
<>
<Form
form={form}
className="print-form"
labelAlign="left"
labelCol={{
flex: '90px'
}}
{...restProps}
>
<Form.Item
aria-label='print-title'
name="title"
label={t('PrintForm.title')}
initialValue={t('PrintForm.initialTitle')}
>
<CustomFieldInput
aria-label='print-title-input'
maxLength={50}
placeholder={t('PrintForm.titlePlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-comment'
name="comment"
label={t('PrintForm.comment')}
>
<CustomFieldInput
aria-label='print-comment-input'
maxLength={200}
placeholder={t('PrintForm.commentPlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-layout'
name="layout"
label={t('PrintForm.layout')}
initialValue={printManager?.getLayouts()[0]?.name}
>
<LayoutSelect
aria-label='print-layout-input'
printManager={printManager}
onValueChange={handleLayoutChange}
/>
</Form.Item>
<Form.Item
aria-label='print-scale'
name='scale'
label={t('PrintForm.scale')}
initialValue={printManager?.getClosestScaleToFitMap()}
>
<ScaleSelect
aria-label='print-scale-input'
printManager={printManager}
/>
</Form.Item>
<Form.Item
aria-label='print-dpi'
name="dpi"
label={t('PrintForm.dpi')}
initialValue={printManager.getDpis()[0]}
>
<ResolutionSelect
aria-label='print-dpi-input'
printManager={printManager}
placeholder={t('PrintForm.resolutionPlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-format'
name="format"
label={t('PrintForm.format')}
initialValue="pdf"
>
<OutputFormatSelect
aria-label='print-format-input'
printManager={printManager}
outputFormats={outputFormats}
placeholder={t('PrintForm.outputFormatPlaceholder')}
/>
</Form.Item>
</Form>
<Button
aria-label='create-print'
className='print-button tool-menu-button'
disabled={!printManager?.isInitiated()}
icon={<FontAwesomeIcon icon={faDownload} />}
loading={loading}
onClick={onDownloadClick}
>
{t('PrintForm.downloadBtnText')}
</Button>
</>
)
}
<>
<Form
form={form}
className="print-form"
labelAlign="left"
labelCol={{
flex: '90px'
}}
{...restProps}
>
{
printManager?.isInitiated() && (
<>
<Form.Item
aria-label='print-title'
name="title"
label={t('PrintForm.title')}
initialValue={t('PrintForm.initialTitle')}
>
<CustomFieldInput
aria-label='print-title-input'
maxLength={50}
placeholder={t('PrintForm.titlePlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-comment'
name="comment"
label={t('PrintForm.comment')}
>
<CustomFieldInput
aria-label='print-comment-input'
maxLength={200}
placeholder={t('PrintForm.commentPlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-layout'
name="layout"
label={t('PrintForm.layout')}
initialValue={printManager?.getLayouts()[0]?.name}
>
<LayoutSelect
aria-label='print-layout-input'
printManager={printManager}
onValueChange={handleLayoutChange}
/>
</Form.Item>
<Form.Item
aria-label='print-scale'
name='scale'
label={t('PrintForm.scale')}
initialValue={printManager?.getClosestScaleToFitMap()}
>
<ScaleSelect
aria-label='print-scale-input'
printManager={printManager}
/>
</Form.Item>
<Form.Item
aria-label='print-dpi'
name="dpi"
label={t('PrintForm.dpi')}
initialValue={printManager.getDpis()[0]}
>
<ResolutionSelect
aria-label='print-dpi-input'
printManager={printManager}
placeholder={t('PrintForm.resolutionPlaceholder')}
/>
</Form.Item>
<Form.Item
aria-label='print-format'
name="format"
label={t('PrintForm.format')}
initialValue="pdf"
>
<OutputFormatSelect
aria-label='print-format-input'
printManager={printManager}
outputFormats={outputFormats}
placeholder={t('PrintForm.outputFormatPlaceholder')}
/>
</Form.Item>
</>
)}
</Form>
<Button
aria-label='create-print'
className='print-button tool-menu-button'
disabled={!printManager?.isInitiated()}
icon={<FontAwesomeIcon icon={faDownload} />}
loading={loading}
onClick={onDownloadClick}
>
{t('PrintForm.downloadBtnText')}
</Button>
</>
</div>
);
};
Expand Down

0 comments on commit 02c71a6

Please sign in to comment.