生活随笔
收集整理的這篇文章主要介紹了
重庆3d地图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果圖:
下載echarts
npm i echarts@
4.9.0
導入
import * as echart
from 'echarts'
html結構
<div style="width: 19.2rem; height: 10.8rem" id="chongqing-map"></div>
引入重慶的json文件
const dt
= require('echarts/map/json/province/chongqing.json')
methods事件
areas數據是通過調用后端接口得到
chongqingMap(areas) {var myChart
= echart
.init(document
.getElementById('chongqing-map'))echart
.registerMap('dt', dt
)const bgColors
= [['#1770b5', '#0f6db2'], ['#2e779e', '#2a7da0'], ['#2a9fcb', '#229ecb'], ['#1fabd5', '#219dc9'], ['#23a0cf', '#2eaedc'], ['#24a1cf', '#27a3d3'], ['#249fce', '#239ac9'], ['#23a1cf', '#2eafdd'], ['#17a7be', '#18a2b8'], ['#337ba2', '#3389ae'], ['#1982b4', '#1e6098'], ['#1ea8d1', '#219eca'], ['#5197d2', '#5298d3'], ['#2081b5', '#23629e'], ['#2892b8', '#2e779e'], ['#2c689b', '#2c81ad'], ['#2896bd', '#2f7399'], ['#265d9a', '#1f70ae'], ['#2e779e', '#0ea9dd'], ['#297c9e', '#27739c'], ['#286799', '#2b6597'], ['#208cb6', '#24669d'], ['#187bb8', '#1d59a0'], ['#229bbe', '#26779e'], ['#2797c2', '#296c9e'], ['#2d709e', '#296b9d'], ['#238fb2', '#267a9f'], ['#018897', '#0292a2'], ['#2d6d9f', '#2b6c9d'], ['#24669b', '#1f6597'], ['#206499', '#1d659a'], ['#1672ae', '#1b5295'], ['#2174ad', '#225696'], ['#296ba2', '#28689d'], ['#1d6aad', '#236aad'], ['#1d74b0', '#215fa1'], ['#21719f', '#227ba8'], ['#3392c2', '#2d679e'], ]const splitList
= dt
.features
.map((v, index) => {const { name: label
} = v
.properties
const Area
= areas
.find((v) => v
['行政區劃'].substr(0, 2) === label
.substr(0, 2))return {label
,start: index
,end: index
,fzl: Area
['事故率'],color: bgColors
[index
][0],}})var option
= {series: [{type: 'map3D',name: '重慶',selectedMode: 'single', boxDepth: 95, regionHeight: 3, map: 'dt',label: {show: true, textStyle: {color: '#FFFFFF', fontSize: 14, backgroundColor: 'transparent',},formatter: function ({ data }) {return (data
.name
.substr(0, 2) +' ' +data
.fzl
+'%')},},itemStyle: {normal: {opacity: 0.9,borderColor: '#DDD',borderWidth: 1, },},emphasis: {label: {show: true, textStyle: {color: '#fff', },},itemStyle: {show: true, color: '#FEB65C', },},symbolSize: [8, 10],symbol: '../../assets/imgs/zuobiao.png', data: splitList
.map((v, index) => {return { name: v
.label
, value: index
, fzl: v
.fzl
}}),shading: 'realistic',realisticMaterial: {detailTexture: '#fff', textureTiling: 1, roughness: 1, metalness: 0, roughnessAdjust: 0,},viewControl: {distance: 125, zoomSensitivity: 1, panMouseButton: 'left',rotateMouseButton: 'right',center: [5, -10, 0],},},],dataRange: {show: false,splitList: splitList
,},animation: true,animationDurationUpdate: 5000,}myChart
.setOption(option
)myChart
.on('click', function (e) {console
.log(e
)})},
注意:echarts不能使用高于4.9.0版本,4.9.0以上版本在依賴包里已經沒有地圖json數據。
總結
以上是生活随笔為你收集整理的重庆3d地图的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。