-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
c7c419b
commit e5fda7e
Showing
9 changed files
with
246 additions
and
11 deletions.
There are no files selected for viewing
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,42 @@ | ||
import React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react'; | ||
import { buildCreateOptions } from '@pansy/react-amap/es/utils/control'; | ||
import { usePropsReactive } from '@pansy/react-amap-core'; | ||
import { allProps, converterMap, setterMap } from './config'; | ||
|
||
import type { PulseLinkLayerProps } from './types'; | ||
|
||
export const PulseLinkLayer = forwardRef<Loca.PulseLinkLayer, React.PropsWithChildren<PulseLinkLayerProps>>(( | ||
props = {}, | ||
ref | ||
) => { | ||
const ins = useRef<Loca.PulseLinkLayer>(); | ||
|
||
const { onInstanceCreated } = usePropsReactive( | ||
props, | ||
ins, | ||
{ | ||
setterMap, | ||
converterMap | ||
} | ||
); | ||
|
||
useEffect(() => { | ||
const options = buildCreateOptions<PulseLinkLayerProps, Loca.PulseLinkLayer.Options>( | ||
props, | ||
allProps, | ||
converterMap, | ||
); | ||
|
||
ins.current = new window.Loca.PulseLinkLayer(options); | ||
|
||
onInstanceCreated?.(ins.current); | ||
}, []) | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ins.current, | ||
[ins.current] | ||
); | ||
|
||
return null; | ||
}) |
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,25 @@ | ||
export const configurableProps = [ | ||
/** 动态属性 */ | ||
'loca', | ||
'zIndex', | ||
'zooms', | ||
'opacity', | ||
] | ||
|
||
export const allProps = configurableProps.concat([ | ||
'visible', | ||
]); | ||
|
||
export const setterMap = { | ||
visible(val: boolean, instance: Loca.ScatterLayer) { | ||
if (instance) { | ||
if (val) { | ||
instance.show() | ||
} else { | ||
instance.hide() | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
export const converterMap = {} |
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,121 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Map } from '@pansy/react-amap'; | ||
import { Button } from 'antd'; | ||
import { Loca, useLoca, ScatterLayer, PulseLinkLayer } from '@pansy/react-amap-loca'; | ||
|
||
const Demo = () => { | ||
const { loca } = useLoca(); | ||
const [visible, setVisible] = useState(true) | ||
const [scatter, setScatter] = useState<Loca.ScatterLayer>(); | ||
const [pulseLink, setPulseLink] = useState<Loca.PulseLinkLayer>(); | ||
|
||
useEffect(() => { | ||
if (scatter && loca && pulseLink) { | ||
const pointGeo = new window.Loca.GeoJSONSource({ | ||
url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/pulselink-china-city-point.json', | ||
}); | ||
scatter.setSource(pointGeo); | ||
|
||
scatter.setStyle({ | ||
unit: 'meter', | ||
size: [200000, 200000], | ||
borderWidth: 0, | ||
texture: 'https://a.amap.com/Loca/static/static/green.png', | ||
duration: 2000, | ||
animate: true, | ||
}); | ||
|
||
loca.add(scatter); | ||
|
||
const geo = new window.Loca.GeoJSONSource({ | ||
url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-out.json', | ||
}); | ||
pulseLink.setSource(geo); | ||
pulseLink.setStyle({ | ||
unit: 'meter', | ||
dash: [40000, 0, 40000, 0], | ||
lineWidth: () => { | ||
return [8000, 8000]; | ||
}, | ||
height: (_, feat) => { | ||
return feat.distance / 3 + 10; | ||
}, | ||
smoothSteps: 30, | ||
speed: () => { | ||
return 1000 + Math.random() * 100000; | ||
}, | ||
flowLength: 100000, | ||
lineColors: () => { | ||
return ['rgba(44, 119, 248, 0.9)', 'rgba(44, 119, 248, 0.5)', 'rgba(44, 119, 248, 0.2)']; | ||
}, | ||
maxHeightScale: 0.3, | ||
headColor: 'rgb(3, 214, 252)', | ||
trailColor: 'rgba(255, 255,0,0)', | ||
}); | ||
|
||
loca.add(pulseLink); | ||
loca.animate.start(); | ||
} | ||
}, [scatter, pulseLink, loca]) | ||
|
||
return ( | ||
<> | ||
<Button onClick={() => { setVisible((val) => !val) }}>切换显隐</Button> | ||
<ScatterLayer | ||
zIndex={10} | ||
opacity={0.6} | ||
visible={visible} | ||
zooms={[2, 22]} | ||
events={{ | ||
created: (instance) => { | ||
setScatter(instance); | ||
} | ||
}} | ||
/> | ||
|
||
<ScatterLayer | ||
zIndex={10} | ||
opacity={0.6} | ||
visible={visible} | ||
zooms={[2, 22]} | ||
events={{ | ||
created: (instance) => { | ||
setScatter(instance); | ||
} | ||
}} | ||
/> | ||
|
||
<PulseLinkLayer | ||
zIndex={10} | ||
opacity={1} | ||
visible={visible} | ||
zooms={[2, 22]} | ||
depth | ||
events={{ | ||
created: (instance) => { | ||
setPulseLink(instance); | ||
} | ||
}} | ||
/> | ||
</> | ||
) | ||
} | ||
export default () => { | ||
return ( | ||
<div style={{ height: 500 }}> | ||
<Map | ||
Loca={{}} | ||
viewMode="3D" | ||
pitch={35} | ||
center={[104.780269, 34.955403]} | ||
zoom={5} | ||
mapStyle="amap://styles/grey" | ||
> | ||
<Loca> | ||
<Demo /> | ||
</Loca> | ||
</Map> | ||
</div> | ||
); | ||
}; | ||
|
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,21 @@ | ||
--- | ||
title: PulseLinkLayer | ||
nav: | ||
title: 组件 | ||
path: /components | ||
order: 1 | ||
group: | ||
path: /loca | ||
title: Loca | ||
order: 1500 | ||
--- | ||
|
||
# PulseLinkLayer 动画图层 | ||
|
||
大地面上的点,可展示三种类型:颜色圆、图标、动画图标 | ||
|
||
## 代码示例 | ||
|
||
### 闪烁效果 | ||
|
||
<code src="./demo/demo01.tsx"></code> |
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,2 @@ | ||
export { PulseLinkLayer } from './ScatterLayer'; | ||
export type { PulseLinkLayerProps } from './types'; |
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,9 @@ | ||
export interface EventMap { | ||
/** 创建事件 */ | ||
created?: (instance: Loca.PulseLinkLayer) => void; | ||
} | ||
|
||
export interface PulseLinkLayerProps extends Loca.PulseLinkLayer.Options { | ||
/** 绑定事件 */ | ||
events?: EventMap; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export { Loca, useLoca } from './Loca'; | ||
export { ScatterLayer } from './ScatterLayer'; | ||
export type { ScatterLayerProps } from './ScatterLayer'; | ||
|
||
export { PulseLinkLayer } from './PulseLinkLayer'; | ||
export type { PulseLinkLayerProps } from './PulseLinkLayer'; |
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