antv-l7/stories/React/components/Scene.tsx

76 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-03-09 01:04:27 +08:00
import {
AMapScene,
LayerContext,
LineLayer,
Marker,
Popup,
SceneContext,
SceneEvent,
} from '@antv/l7-react';
2020-02-11 20:31:55 +08:00
import * as React from 'react';
export default React.memo(function Map() {
const [data, setData] = React.useState();
React.useEffect(() => {
const fetchData = async () => {
const response = await fetch(
'https://gw.alipayobjects.com/os/basement_prod/32e1f3ab-8588-46cb-8a47-75afb692117d.json',
);
2020-03-05 22:40:41 +08:00
const raw = await response.json();
setData(raw);
2020-02-11 20:31:55 +08:00
};
fetchData();
}, []);
return (
<>
2020-03-05 22:40:41 +08:00
<AMapScene
map={{
center: [110.19382669582967, 50.258134],
pitch: 0,
style: 'dark',
zoom: 1,
}}
2020-02-11 20:31:55 +08:00
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
>
2020-03-05 22:40:41 +08:00
<Popup lnglat={[110.1938, 50.25] as number[]}>
<p>122222</p>
</Popup>
<Marker lnglat={[110.1938, 30.25] as number[]}>
<p>122222</p>
</Marker>
<LineLayer
key={'2'}
source={{
data,
}}
size={{
values: 1,
}}
color={{
values: '#fff',
}}
shape={{
values: 'line',
}}
style={{
opacity: 1,
}}
2020-03-09 01:04:27 +08:00
>
<LayerContext.Consumer>
{(layer) => {
console.log(layer);
return null;
}}
</LayerContext.Consumer>
</LineLayer>
2020-03-05 22:40:41 +08:00
</AMapScene>
2020-02-11 20:31:55 +08:00
</>
);
});