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

112 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-03-09 01:04:27 +08:00
import {
AMapScene,
LayerContext,
LayerEvent,
2020-03-09 01:04:27 +08:00
LineLayer,
2020-09-07 15:26:16 +08:00
MapboxScene,
2020-03-09 01:04:27 +08:00
Marker,
PolygonLayer,
2020-03-09 01:04:27 +08:00
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();
}, []);
const popupClick = (e: any) => {
console.log(e);
// e.stopPropagation();
2020-04-22 17:09:24 +08:00
alert('11333');
};
const markerClick = (e: any) => {
console.log(e);
// e.stopPropagation();
alert('marker');
};
2020-02-11 20:31:55 +08:00
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-04-22 17:09:24 +08:00
<Popup
option={{
closeOnClick: false,
stopPropagation: false,
2020-04-22 17:09:24 +08:00
}}
lnglat={[115, 30.25] as number[]}
2020-04-22 17:09:24 +08:00
>
2020-09-07 15:26:16 +08:00
<p onClick={popupClick}>122224</p>
2020-03-05 22:40:41 +08:00
</Popup>
<Marker lnglat={[100.1938, 27.25] as number[]}>
<div
style={{
border: '1px solid #fff',
background: '#FFF',
fontSize: '24px',
}}
>
<p onClick={markerClick}>tes</p>
</div>
2020-03-05 22:40:41 +08:00
</Marker>
2020-09-07 15:26:16 +08:00
<PolygonLayer
2020-03-05 22:40:41 +08:00
key={'2'}
source={{
data,
}}
size={{
values: 1,
}}
color={{
2020-12-14 17:33:11 +08:00
field: 'name',
values: [
'#2E8AE6',
'#69D1AB',
'#DAF291',
'#FFD591',
'#FF7A45',
'#CF1D49',
],
2020-03-05 22:40:41 +08:00
}}
shape={{
2020-09-07 15:26:16 +08:00
values: 'fill',
2020-03-05 22:40:41 +08:00
}}
style={{
opacity: 1,
}}
2020-03-09 01:04:27 +08:00
>
<LayerEvent
type="click"
handler={(e) => {
console.log('LayerEvent', e);
2020-03-09 01:04:27 +08:00
}}
/>
2020-09-07 15:26:16 +08:00
</PolygonLayer>
2020-03-05 22:40:41 +08:00
</AMapScene>
2020-02-11 20:31:55 +08:00
</>
);
});