<template>
<div ref="map3d" style="width: 100%; height: 400px;"></div>
</template>
<script>
import * as echarts from 'echarts/core';
import { Map3D, Graph3D } from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import { map3DRegist } from 'echarts-gl/core';
import { geo3D } from 'echarts/extension/dataTool';
import { getMap3DData } from './map3DData';
echarts.use([
Map3D,
Graph3D,
CanvasRenderer,
geo3D,
map3DRegist
]);
export default {
mounted() {
const myChart = echarts.init(this.$refs.map3d);
const option = this.getOption();
myChart.setOption(option);
},
methods: {
getOption() {
const map3DData = getMap3DData();
const option = {
// 省略其他配置项...
series: [
{
type: 'map3D',
// 省略地图配置...
},
{
type: 'graph3D',
coordinateSystem: 'map3D',
// 省略图形配置...
},
{
type: 'lines3D',
coordinateSystem: 'map3D',
// 省略线条配置...
}
]
};
return option;
}
}
};
</script>
这个代码实例展示了如何在Vue中使用ECharts的map3D
和graph3D
组件来绘制3D地图,并插入自定义图标。首先,通过echarts.use()
注册所需的组件。然后,在mounted
钩子函数中初始化ECharts实例,并设置配置项。配置项中定义了三个series
,分别用于展示3D地图、图形和线条,这些都是Apache ECharts 3D地图功能的核心组件。