-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/li-analysis-assets/src/widgets/SwipeControl/ComponenStyle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { css } from '@emotion/css'; | ||
import { theme } from 'antd'; | ||
|
||
const useStyle = () => { | ||
const { useToken } = theme; | ||
const { token } = useToken(); | ||
|
||
const { colorTextDescription, colorBgContainer, colorBorder, colorText, colorBgElevated, borderRadius } = token; | ||
|
||
return { | ||
swipeControl: css` | ||
border-radius: ${borderRadius}px; | ||
`, | ||
}; | ||
}; | ||
|
||
export default useStyle; |
39 changes: 39 additions & 0 deletions
39
packages/li-analysis-assets/src/widgets/SwipeControl/Component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Swipe } from '@antv/l7'; | ||
import type { ImplementWidgetProps } from '@antv/li-sdk'; | ||
import { useScene } from '@antv/li-sdk'; | ||
import type React from 'react'; | ||
import { useEffect, useRef } from 'react'; | ||
import useStyle from './ComponenStyle'; | ||
import type { Properties } from './registerForm'; | ||
|
||
/** 组件名称, 前缀 */ | ||
const CLS_PREFIX = 'li-swipe-control'; | ||
|
||
export interface SwipeControlProps extends ImplementWidgetProps, Properties {} | ||
|
||
const SwipeControl: React.FC<SwipeControlProps> = (props) => { | ||
const { position, orientation, leftLayers, rightLayers } = props; | ||
const styles = useStyle(); | ||
const [scene] = useScene(); | ||
|
||
const swipeRef = useRef( | ||
new Swipe({ | ||
orientation: orientation, | ||
ratio: 0.5, | ||
layers: [], | ||
rightLayers: [], | ||
}), | ||
); | ||
|
||
useEffect(() => { | ||
scene?.addControl(swipeRef.current); | ||
|
||
return () => { | ||
scene?.removeControl(swipeRef.current); | ||
}; | ||
}, [scene]); | ||
|
||
return null; | ||
}; | ||
|
||
export default SwipeControl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## SwipeControl |
22 changes: 22 additions & 0 deletions
22
packages/li-analysis-assets/src/widgets/SwipeControl/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { implementWidget } from '@antv/li-sdk'; | ||
import component from './Component'; | ||
import registerForm from './registerForm'; | ||
|
||
export default implementWidget({ | ||
version: 'v0.1', | ||
metadata: { | ||
name: 'SwipeControl', | ||
displayName: '卷帘对比', | ||
description: '用于分屏对比两个地图上叠加图层', | ||
type: 'Auto', | ||
category: 'MapControl', | ||
}, | ||
defaultProperties: { | ||
position: 'topright', | ||
orientation: 'vertical', | ||
leftLayers: [], | ||
rightLayers: [], | ||
}, | ||
component, | ||
registerForm, | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/li-analysis-assets/src/widgets/SwipeControl/registerForm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { PositionName } from '@antv/l7'; | ||
import type { WidgetRegisterForm } from '@antv/li-sdk'; | ||
/** | ||
* 属性面板生产的数据类型定义 | ||
*/ | ||
export type Properties = { | ||
/** 控件放置位置 */ | ||
position?: PositionName; | ||
/** 卷帘方向设置,默认 'vertical' */ | ||
orientation?: 'vertical' | 'horizontal'; | ||
/** 卷帘左侧的图层 ID */ | ||
leftLayers: string[]; | ||
/** 卷帘右侧侧的图层 ID */ | ||
rightLayers: string[]; | ||
}; | ||
|
||
export default (): WidgetRegisterForm<Properties> => { | ||
// 属性面板表单的 Schema 定义,来自表单库 formily 的 Schema | ||
const schema = { | ||
position: { | ||
title: '放置方位', | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'ControlPositionSelect', | ||
default: 'bottomright', | ||
}, | ||
// showZoom: { | ||
// title: '显示层级', | ||
// type: 'boolean', | ||
// 'x-decorator': 'FormItem', | ||
// 'x-component': 'Switch', | ||
// default: true, | ||
// }, | ||
}; | ||
return { schema }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters