Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增导出图片组件 #52

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"i18n-ally.keystyle": "nested",
"i18n-ally.sortKeys": true,
"i18n-ally.enabledParsers": ["ts", "json"],
"i18n-ally.sourceLanguage": "en-US",
"i18n-ally.sourceLanguage": "zh-CN",
"i18n-ally.displayLanguage": "zh-CN",
"i18n-ally.enabledFrameworks": ["react"]
}
1 change: 1 addition & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ LngLat 文本编辑器,可以通过输入 LngLat 数据实现数据展示(目
| mapAdministrativeControl | 查看当前行政区域控件 |
| logoControl | Logo 控件 |
| textLayerControl | 文本图层 控件 |
| exportImageControl | 导出图片 控件 |

#### toolbar

Expand Down
48 changes: 48 additions & 0 deletions src/components/map-control-group/export-image-control/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ExportImageControl } from '@antv/larkmap';
import { Image, Modal } from 'antd';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { downloadImg } from '.././../../utils';
import useStyle from './styles';

export const ExportImage = () => {
const styles = useStyle();
const [imageData, setImageData] = useState('');
const [isModalOpen, setIsModalOpen] = useState(false);
const { t } = useTranslation();

const onExport = (value: string) => {
setIsModalOpen(true);
setImageData(value);
};

const handle = () => {
setIsModalOpen(false);
setImageData('');
};

const onOk = () => {
setIsModalOpen(false);
downloadImg(imageData);
setImageData('');
};
return (
<>
<ExportImageControl
onExport={onExport}
className={styles.l7ExportImg}
imageType="jpeg"
position={'bottomright'}
/>
<Modal
title={t('export-img-control_title')}
open={isModalOpen}
okText={t('btn.download_btn.xiaZai')}
onOk={onOk}
onCancel={handle}
>
<Image src={imageData} />
</Modal>
</>
);
};
28 changes: 28 additions & 0 deletions src/components/map-control-group/export-image-control/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { css } from '@emotion/css';
import { theme } from 'antd';

const useStyle = () => {
const { useToken } = theme;
const { token } = useToken();

const { colorBgContainer, colorIcon, colorText } =
token;
return {
l7ExportImg: css`
background: ${colorBgContainer};
color: ${colorIcon};
svg {
fill: ${colorIcon} !important;
}

:hover {
background: ${colorBgContainer} !important;
svg {
color: ${colorText} !important;
fill: ${colorText} !important;
}
}
`,
};
};
export default useStyle;
3 changes: 3 additions & 0 deletions src/components/map-control-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AdministrativeSelect } from './administrative-select-control';
import { AutoControl } from './auto-control';
import { ClearControl } from './clear-control';
import DrawControl from './draw-control';
import { ExportImage } from './export-image-control';
import FilterControl from './filter-form-list-control';
import { L7MapOptionControl } from './l7-option-control';
import LayerColorControl from './layer-color-control';
Expand Down Expand Up @@ -46,6 +47,7 @@ const DefaultMapControl: MapControlProps = {
mapAdministrativeControl: true,
logoControl: true,
textLayerControl: true,
exportImageControl: true,
L7MapOptionControl: true,
};
export const MapControlGroup: React.FC<MapControlGroupProps> = ({
Expand Down Expand Up @@ -101,6 +103,7 @@ export const MapControlGroup: React.FC<MapControlGroupProps> = ({
)}
{layerType.includes(OfficeLayerEnum.GoogleSatellite) && <SamControl />}
{isControlGroupState.textLayerControl && <TextLayerControl />}
{isControlGroupState.exportImageControl && <ExportImage />}
{isControlGroupState.L7MapOptionControl && <L7MapOptionControl />}
</>
);
Expand Down
10 changes: 8 additions & 2 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export enum LocalStorageKey {
firstOpening = 'firstOpening',
wasmPath = 'wasmPath',
customTiles = 'customTiles',
showDrawDistance = "showDrawDistance",
showDrawArea = "showDrawArea"
showDrawDistance = 'showDrawDistance',
showDrawArea = 'showDrawArea',
}

export enum LayerId {
Expand All @@ -46,10 +46,16 @@ export const FeatureKey = {
export const MapBoxConfig = {
token:
'pk.eyJ1IjoibGl1dmlnb25nenVvc2hpIiwiYSI6ImNsaGs2czBrcTBvczUzbnFzOHU0dzk2ZWQifQ.hVvTgcbg_Ym-VQz36psLRg',
WebGLParams: {
preserveDrawingBuffer: true,
},
};

export const GaodeConfig = {
token: '5ae4492ef912cbbc93034fea0e66ff2a',
WebGLParams: {
preserveDrawingBuffer: true,
},
};

export const LayerZIndex = 100;
Expand Down
1 change: 1 addition & 0 deletions src/locales/langs/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export default {
'text-layer-control_wenBenTuCengPeiZhi': 'Text Layer Configuration',
'text-layer-control_description':
'Open the text layer configuration, you can display the serial number of all the current data, you can also use the multi-select box to properties fields in the data to select different data for display.',
'export-img-control_title': 'Preview Picture',
'btn.setting_btn.mianJi': 'Show area text when drawing',
'btn.setting_btn.juLi': 'Whether to display distance text when drawing',
'l7Options.huoqucanshu': 'Get map status parameters',
Expand Down
1 change: 1 addition & 0 deletions src/locales/langs/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export default {
'text-layer-control_wenBenTuCengPeiZhi': '文本图层配置',
'text-layer-control_description':
'开启文本图层配置,可以显示当前所有数据的序号,也可以通过多选框在数据中properties字段去选择不同的数据来进行展示',
'export-img-control_title': '预览图片',
'btn.setting_btn.mianJi': '绘制时是否展示面积文本',
'btn.setting_btn.juLi': '绘制时是否展示距离文本',
'l7Options.huoqucanshu': '获取地图状态参数',
Expand Down
1 change: 1 addition & 0 deletions src/types/l7editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface MapControlProps {
administrativeSelectControl?: boolean;
mapAdministrativeControl?: boolean;
textLayerControl?: boolean;
exportImageControl?: boolean;
L7MapOptionControl?: boolean;
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export const downloadText = (text: string, ext: string | 'json' | 'txt') => {
aTag.click();
};

export const downloadImg = (link: string) => {
const aTag = document.createElement('a');
aTag.href = link;
aTag.download = `${dayjs().format('YYYY年MM月DD日HH时mm分ss秒')}.jpeg`;
aTag.dispatchEvent(new MouseEvent('click'));
};

export const getParamsNew = (key: string) => {
const temData = new URLSearchParams(window.location.search);
return temData.get(key);
Expand Down
Loading