echarts加載區(qū)域地圖并標注點的簡單步驟
更新時間:2024年09月28日 13:49:49 作者:kang5789
這篇文章提供了南海區(qū)域地圖加載以及氣象站點標注的詳細步驟,首先通過DataV.GeoAtlas地理小工具下載南海區(qū)域的JSON地圖文件,接著使用Echarts進行地圖的展示,可以選擇是否顯示省下所有市的名字,需要的朋友可以參考下
效果如下,加載了南海區(qū)域的地圖,并標注幾個氣象站點;
1、下載區(qū)域地圖的JSON:DataV.GeoAtlas地理小工具系列
新建nanhai.json,把下載的JSON數據放進來
說明:如果第二步不打勾,只顯示省的名字,
如果打勾的話,會顯示省下所有市的名字,看個人需求
如果要把多個省放在一起展示,則把多個JSON文件里的features數據合并即可
2、使用Echarts展示地圖
<!--地圖--> <div ref="chartRef" class="chart"/> <script setup> import {ref, onMounted} from 'vue' import * as echarts from 'echarts' import nanhaiJson from '@/assets/map/nanhai.json' //地圖json數據: https://datav.aliyun.com/portal/school/atlas/area_selector const chartRef = ref() const formRef = ref() let myChart = null; const stationData = ref([]) //加載數據 onMounted(() => { //加載南海地圖 echarts.registerMap('nanhai', nanhaiJson) loadData() }) const loadData = () => { xxApi.xxPage().then((data) => { if (data && data.total > 0) { stationData.value = [] //拼接地圖上需要標注的點 data.records.forEach((item) => { stationData.value.push( { name: item.name, value: [item.longitude, item.latitude] } ) }) } loadChart() }) } //加載圖表 const loadChart = () => { // 如果實例已經存在,則先銷毀再重新創(chuàng)建 if (myChart != null && myChart.dispose) { myChart.dispose(); } myChart = echarts.init(chartRef.value) myChart.showLoading({text: 'loading'}) let option = { geo: { map: 'nanhai', zoom: 1.2,//縮放比例 roam: true, // 是否允許縮放和平移 itemStyle: { areaColor: 'lightskyblue', borderColor: '#404a59' }, label: { show: true }, }, //氣象站點列表 series: [{ type: 'scatter', coordinateSystem: 'geo', data: stationData.value, symbolSize: 10, label: { show: true, formatter: function (params) { return params.name; // 顯示點的name }, position: 'top', // 或其他位置 color: '#FF4500' // 設置標簽字體顏色為紅色 }, itemStyle: { normal: { color: '#FFA500' // 設置為橘黃色 } }, }] } myChart.hideLoading() myChart.setOption(option) // 自適應屏幕 window.addEventListener('resize', function () { myChart.resize() }) } </script> <style scoped> .chart { height: 550px; } .detail-chart { height: 100%; overflow: auto; } </style>
OK,大功搞定?。。?/p>
到此這篇關于echarts加載區(qū)域地圖并標注點的文章就介紹到這了,更多相關echarts加載區(qū)域地圖標注點內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
IE6下出現JavaScript未結束的字符串常量錯誤的解決方法
JavaScript文件只在IE6下出錯(“未結束的字符串常量”)的解決辦法。2010-11-11