2017网站建设报价方案,免费特效素材网站,网站建设查看框架的源代码,ppt模板免费下载哪个网站好echarts地图的简单使用 文章说明核心源码效果展示源码下载 文章说明 主要介绍echarts地图组件的简单使用#xff0c;记录为文章#xff0c;供后续查阅使用 目前只是简单的示例#xff0c;然后还存在着一些小bug#xff0c;主要是首个Legend的点击会导致颜色全部不展示的问题… echarts地图的简单使用 文章说明核心源码效果展示源码下载 文章说明 主要介绍echarts地图组件的简单使用记录为文章供后续查阅使用 目前只是简单的示例然后还存在着一些小bug主要是首个Legend的点击会导致颜色全部不展示的问题以及世界地图的区域展示有一些小问题等待后续完善 核心源码 地图绘制组件 script setup
import * as echarts from echarts;
import china from /assets/china.json;
import world from /assets/world.json;
import {onBeforeMount, onMounted, reactive} from vue;
import {getAreaList} from /assets/getAreaList;
import {calculateColor} from /util;const data reactive({mapName: china,chinaAreaList: [],selectedChinaAreaList: [],worldAreaList: [],selectedWorldAreaList: [],
});onBeforeMount(() {const {chinaAreaList, worldAreaList} getAreaList();data.chinaAreaList chinaAreaList;data.worldAreaList worldAreaList;
});const mapList [{name: china,data: china,},{name: world,data: world,}
];let myChart;onMounted(() {for (let i 0; i mapList.length; i) {echarts.registerMap(mapList[i].name, mapList[i].data);}const chartDom document.getElementById(basic-chart);myChart echarts.init(chartDom);setOption();window.onresize () {myChart.resize();};
});const mapNameMap {china: 中国地图,world: 世界地图,
}let min 0;
let max 10000;
let selectedAreaDataList [];function setOption() {let selectedAreaList [];if (data.mapName china) {selectedAreaList data.selectedChinaAreaList;} else if (data.mapName world) {selectedAreaList data.selectedWorldAreaList;}const series [];const colors [];const notSortArray [];for (let i 0; i selectedAreaList.length; i) {let selectedAreaData;for (let j 0; j selectedAreaDataList.length; j) {if (selectedAreaDataList[j].name selectedAreaList[i]) {selectedAreaData selectedAreaDataList[j];break;}}let value;if (selectedAreaData) {value selectedAreaData.value;} else {value Math.ceil(Math.random() * max);selectedAreaDataList.push({value: value,name: selectedAreaList[i],});}notSortArray.push({value: value,name: selectedAreaList[i],});}notSortArray.sort(function (o1, o2) {return o1.value - o2.value;});if (!notSortArray.length) {colors.push(#ffffff, #000000);}const legendNames [];for (let i 0; i notSortArray.length; i) {const color calculateColor(notSortArray[i].value, min, max);colors.push(color);const seriesItem {name: notSortArray[i].name,type: map,geoIndex: 0,data: [{name: notSortArray[i].name,value: notSortArray[i].value}],color: color,};series.push(seriesItem);legendNames.push(notSortArray[i].name);}myChart.setOption({title: {text: mapNameMap[data.mapName],left: center,},geo: {map: data.mapName,label: {show: false,},},legend: {orient: vertical,bottom: 50px,left: 50px,itemHeight: 10,itemWidth: 30,textStyle: {fontSize: 12,rich: {a: {verticalAlign: middle,},},padding: [2, 0, 0, 0],},data: legendNames},series: series,visualMap: {left: right,min: min,max: max,inRange: {color: colors},text: [High, Low],calculable: true},toolbox: {show: true,feature: {saveAsImage: {show: true}}},}, true);
}
/scripttemplatediv classcontainerdiv styleheight: 6rem; display: flex; align-items: center; justify-content: centerel-select v-modeldata.mapName stylewidth: 10rem; margin-right: 2rem changesetOptionel-option label中国地图 valuechina/el-option label世界地图 valueworld//el-selectel-select v-showdata.mapName china v-modeldata.selectedChinaAreaList collapse-tagscollapse-tags-tooltip filterable multiple placeholder请选择地区 stylewidth: 30remchangesetOptiontemplate v-foritem in data.chinaAreaList :keyitem.idel-option :labelitem.name :valueitem.name//template/el-selectel-select v-showdata.mapName world v-modeldata.selectedWorldAreaList collapse-tagscollapse-tags-tooltip filterable multiple placeholder请选择地区 stylewidth: 30remchangesetOptiontemplate v-foritem in data.worldAreaList :keyitem.idel-option :labelitem.name :valueitem.name//template/el-select/divdiv styleflex: 1div idbasic-chart classchart/div/div/div
/templatestyle langscss
* {margin: 0;padding: 0;box-sizing: border-box;
}.container {width: 100vw;height: 100vh;display: flex;flex-direction: column;
}.chart {width: 100%;height: 100%;
}
/style根据值生成颜色的工具函数 function hsvToRgb(h, s, v) {const f n {const k (n h / 60) % 6;return v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);};return [Math.round(f(5) * 255),Math.round(f(3) * 255),Math.round(f(1) * 255)];
}export function calculateColor(value, minValue, maxValue) {value Math.max(minValue, Math.min(maxValue, value));const factor (value - minValue) / (maxValue - minValue);const hue (factor * 360) % 360;const saturation 1 - factor;const valueV 1;const [r, g, b] hsvToRgb(hue, saturation, valueV);return rgb(${r}, ${g}, ${b});
}地图数据的下载可以在该网站下载较为全面的中国地图的数据DataV.GeoAtlas地理小工具系列 效果展示 中国地图 世界地图 源码下载 echarts地图组件的基本使用
文章转载自: http://www.morning.bnrnb.cn.gov.cn.bnrnb.cn http://www.morning.tqsgt.cn.gov.cn.tqsgt.cn http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn http://www.morning.mprtj.cn.gov.cn.mprtj.cn http://www.morning.slnz.cn.gov.cn.slnz.cn http://www.morning.gqcd.cn.gov.cn.gqcd.cn http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn http://www.morning.gzzxlp.com.gov.cn.gzzxlp.com http://www.morning.xxzjb.cn.gov.cn.xxzjb.cn http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn http://www.morning.yhxhq.cn.gov.cn.yhxhq.cn http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn http://www.morning.xnqjs.cn.gov.cn.xnqjs.cn http://www.morning.kjgrg.cn.gov.cn.kjgrg.cn http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn http://www.morning.nnrqg.cn.gov.cn.nnrqg.cn http://www.morning.jpydf.cn.gov.cn.jpydf.cn http://www.morning.rwmp.cn.gov.cn.rwmp.cn http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn http://www.morning.pmlgr.cn.gov.cn.pmlgr.cn http://www.morning.rtjhw.cn.gov.cn.rtjhw.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.wrwcf.cn.gov.cn.wrwcf.cn http://www.morning.ytmx.cn.gov.cn.ytmx.cn http://www.morning.npbnc.cn.gov.cn.npbnc.cn http://www.morning.rfljb.cn.gov.cn.rfljb.cn http://www.morning.pmghz.cn.gov.cn.pmghz.cn http://www.morning.jwrcz.cn.gov.cn.jwrcz.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.mfnjk.cn.gov.cn.mfnjk.cn http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.yrbq.cn.gov.cn.yrbq.cn http://www.morning.wfttq.cn.gov.cn.wfttq.cn http://www.morning.qgjxy.cn.gov.cn.qgjxy.cn http://www.morning.txnqh.cn.gov.cn.txnqh.cn http://www.morning.nqmdc.cn.gov.cn.nqmdc.cn http://www.morning.kmqwp.cn.gov.cn.kmqwp.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.qzzmc.cn.gov.cn.qzzmc.cn http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn http://www.morning.jrksk.cn.gov.cn.jrksk.cn http://www.morning.yfzld.cn.gov.cn.yfzld.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.hdwjb.cn.gov.cn.hdwjb.cn http://www.morning.bbyqz.cn.gov.cn.bbyqz.cn http://www.morning.gsjfn.cn.gov.cn.gsjfn.cn http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn http://www.morning.lydtr.cn.gov.cn.lydtr.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.bmbnc.cn.gov.cn.bmbnc.cn http://www.morning.xbdrc.cn.gov.cn.xbdrc.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.wanjia-sd.com.gov.cn.wanjia-sd.com http://www.morning.hjlsll.com.gov.cn.hjlsll.com http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.pqqhl.cn.gov.cn.pqqhl.cn http://www.morning.jfqpc.cn.gov.cn.jfqpc.cn http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.kqzxk.cn.gov.cn.kqzxk.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.mbrbg.cn.gov.cn.mbrbg.cn http://www.morning.lkhfm.cn.gov.cn.lkhfm.cn http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.mkyny.cn.gov.cn.mkyny.cn http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.qlkzl.cn.gov.cn.qlkzl.cn http://www.morning.krbjb.cn.gov.cn.krbjb.cn http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.thpns.cn.gov.cn.thpns.cn http://www.morning.ngkng.cn.gov.cn.ngkng.cn