/
ChinaCitys.tsx
108 lines (98 loc) 路 2.53 KB
/
ChinaCitys.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { Component } from 'react';
import { Scene, Mapbox } from '@antv/l7';
import { ChoroplethLayer } from '@antv/l7-composite-layers';
class ChinaCitys extends Component {
public scene: Scene | undefined;
public choroplethLayer: ChoroplethLayer | undefined;
constructor(props) {
super(props);
}
async initMap() {
this.scene = new Scene({
id: 'container',
map: new Mapbox({
pitch: 0,
style: 'light',
zoom: 3,
center: [120.19660949707033, 30.234747338474293],
}),
});
fetch('https://gw.alipayobjects.com/os/bmw-prod/707cd4be-8ffe-4778-b863-3335eefd5fd5.json')
.then((response) => response.json())
.then((data) => {
this.choroplethLayer = new ChoroplethLayer({
source: {
data: data,
parser: {
type: 'geojson',
},
},
fillColor: {
field: 'name',
value: ['#fee5d9', '#fcae91', '#fb6a4a', '#de2d26', '#a50f15'],
},
opacity: 0.8,
strokeColor: '#ccc',
lineType: 'solid',
lineWidth: 0.6,
lineOpacity: 1,
label: {
field: 'name',
style: {
fill: '#000',
opacity: 0.8,
fontSize: 10,
stroke: '#fff',
strokeWidth: 2,
textAllowOverlap: false,
padding: [5, 5],
},
},
state: {
active: {
strokeColor: 'blue',
},
select: {
strokeColor: 'yellow',
lineWidth: 1,
lineOpacity: 0.8,
},
},
enabledMultiSelect: true,
});
this.scene && this.choroplethLayer.addTo(this.scene);
});
}
componentDidMount() {
this.initMap();
}
componentWillUnmount() {
this.scene && this.scene.destroy();
}
update = () => {
if (this.scene) {
this.choroplethLayer?.update({ fillColor: 'rgb(239,243,255)', autoFit: true, strokeColor: 'blue' });
}
};
render() {
return (
<div
id="container"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
>
<div style={{ position: 'absolute', left: '10px', zIndex: 1 }}>
<button type="button" onClick={this.update} style={{ marginTop: 8 }}>
update
</button>
</div>
</div>
);
}
}
export default ChinaCitys;