|
@@ -25,20 +25,64 @@ class WorldMap extends React.Component {
|
|
|
window.removeEventListener("resize", this.resizeChart);
|
|
|
}
|
|
|
|
|
|
+ componentDidUpdate() {
|
|
|
+ this.initChart();
|
|
|
+ }
|
|
|
+
|
|
|
resizeChart = () => {
|
|
|
if (this.chartInstance) {
|
|
|
this.chartInstance.resize();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // 根据国家名获取中心经纬度
|
|
|
+ getGeoCenterByName(name) {
|
|
|
+ const feature = worldJson.features.find((f) => f.properties.name === name);
|
|
|
+ if (feature) {
|
|
|
+ // 计算多边形的中心点
|
|
|
+ const coords = feature.geometry.coordinates.flat(Infinity);
|
|
|
+ let lng = 0,
|
|
|
+ lat = 0;
|
|
|
+ for (let i = 0; i < coords.length; i += 2) {
|
|
|
+ lng += coords[i];
|
|
|
+ lat += coords[i + 1];
|
|
|
+ }
|
|
|
+ lng /= coords.length / 2;
|
|
|
+ lat /= coords.length / 2;
|
|
|
+ return [lng, lat];
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
initChart() {
|
|
|
if (!this.chartRef.current) return;
|
|
|
this.chartInstance = echarts.init(this.chartRef.current);
|
|
|
-
|
|
|
+ console.log(this.props.data, "--sdsdsd");
|
|
|
+ // const seriesData = [
|
|
|
+ // { name: "China", value: [116.4074, 39.9042, 100] },
|
|
|
+ // { name: "United States", value: [-100.0, 40.0, 80] },
|
|
|
+ // { name: "Brazil", value: [-47.9292, -15.7801, 60] },
|
|
|
+ // { name: "Russia", value: [37.6173, 55.7558, 70] },
|
|
|
+ // { name: "India", value: [77.1025, 28.7041, 90] },
|
|
|
+ // ];
|
|
|
+ // const seriesData = countries
|
|
|
+ // ?.map((item) => {
|
|
|
+ // const coord = this.getGeoCenterByName(item.name);
|
|
|
+ // if (coord) {
|
|
|
+ // return { name: item.name, value: [...coord, item.value] };
|
|
|
+ // }
|
|
|
+ // return null;
|
|
|
+ // })
|
|
|
+ // .filter(Boolean);
|
|
|
const option = {
|
|
|
tooltip: {
|
|
|
formatter: (params) => {
|
|
|
- return `${params.name}`;
|
|
|
+ return `${params.name} <br> ${params.value[2]}`;
|
|
|
+ },
|
|
|
+ textStyle: {
|
|
|
+ fontSize: 28, // 字体大小
|
|
|
+ // color: "#fff", // 字体颜色
|
|
|
+ fontWeight: "bold", // 可选加粗
|
|
|
},
|
|
|
},
|
|
|
geo3D: {
|
|
@@ -48,10 +92,10 @@ class WorldMap extends React.Component {
|
|
|
|
|
|
boxWidth: 200, // 宽度加大
|
|
|
boxHeight: 20,
|
|
|
- regionHeight: 2,
|
|
|
+ regionHeight: 1,
|
|
|
viewControl: {
|
|
|
distance: 120, // 相机拉远一点
|
|
|
- alpha: 60,
|
|
|
+ alpha: 30,
|
|
|
beta: 0,
|
|
|
},
|
|
|
shading: "lambert",
|
|
@@ -63,21 +107,36 @@ class WorldMap extends React.Component {
|
|
|
backgroundColor: "rgba(0,0,0,0)",
|
|
|
},
|
|
|
},
|
|
|
+ // itemStyle: {
|
|
|
+ // color: "#1d5e98",
|
|
|
+ // opacity: 0.8,
|
|
|
+ // borderWidth: 0.8,
|
|
|
+ // borderColor: "#111",
|
|
|
+ // },
|
|
|
itemStyle: {
|
|
|
- color: "#1d5e98",
|
|
|
- opacity: 0.8,
|
|
|
+ // 区域透明但微亮
|
|
|
+ color: "rgba(255,255,255,0.05)",
|
|
|
+ borderColor: "#66ccff", // 边界亮色
|
|
|
borderWidth: 0.8,
|
|
|
- borderColor: "#111",
|
|
|
},
|
|
|
+
|
|
|
emphasis: {
|
|
|
itemStyle: {
|
|
|
- color: "#2a333d",
|
|
|
- },
|
|
|
- label: {
|
|
|
- show: false,
|
|
|
+ color: "rgba(255,255,255,0.1)",
|
|
|
+ borderColor: "#99ffff",
|
|
|
+ borderWidth: 1,
|
|
|
},
|
|
|
},
|
|
|
|
|
|
+ // emphasis: {
|
|
|
+ // itemStyle: {
|
|
|
+ // color: "#2a333d",
|
|
|
+ // },
|
|
|
+ // label: {
|
|
|
+ // show: false,
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+
|
|
|
light: {
|
|
|
main: {
|
|
|
intensity: 1.2,
|
|
@@ -100,13 +159,10 @@ class WorldMap extends React.Component {
|
|
|
coordinateSystem: "geo3D",
|
|
|
shading: "lambert",
|
|
|
barSize: 1, // 柱子粗细
|
|
|
- data: [
|
|
|
- { name: "China", value: [116.4074, 39.9042, 100] },
|
|
|
- { name: "United States", value: [-100.0, 40.0, 80] },
|
|
|
- { name: "Brazil", value: [-47.9292, -15.7801, 60] },
|
|
|
- { name: "Russia", value: [37.6173, 55.7558, 70] },
|
|
|
- { name: "India", value: [77.1025, 28.7041, 90] },
|
|
|
- ],
|
|
|
+ itemStyle: {
|
|
|
+ color: "#DE701C",
|
|
|
+ },
|
|
|
+ data: this.props.data,
|
|
|
},
|
|
|
],
|
|
|
};
|