echarts加載區(qū)域地圖并標(biāo)注點(diǎn)的簡(jiǎn)單步驟
效果如下,加載了南海區(qū)域的地圖,并標(biāo)注幾個(gè)氣象站點(diǎn);

1、下載區(qū)域地圖的JSON:DataV.GeoAtlas地理小工具系列

新建nanhai.json,把下載的JSON數(shù)據(jù)放進(jìn)來(lái)
說(shuō)明:如果第二步不打勾,只顯示省的名字,
如果打勾的話,會(huì)顯示省下所有市的名字,看個(gè)人需求
如果要把多個(gè)省放在一起展示,則把多個(gè)JSON文件里的features數(shù)據(jù)合并即可

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數(shù)據(jù): https://datav.aliyun.com/portal/school/atlas/area_selector
const chartRef = ref()
const formRef = ref()
let myChart = null;
const stationData = ref([])
//加載數(shù)據(jù)
onMounted(() => {
//加載南海地圖
echarts.registerMap('nanhai', nanhaiJson)
loadData()
})
const loadData = () => {
xxApi.xxPage().then((data) => {
if (data && data.total > 0) {
stationData.value = []
//拼接地圖上需要標(biāo)注的點(diǎn)
data.records.forEach((item) => {
stationData.value.push(
{
name: item.name,
value: [item.longitude, item.latitude]
}
)
})
}
loadChart()
})
}
//加載圖表
const loadChart = () => {
// 如果實(shí)例已經(jīng)存在,則先銷毀再重新創(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
},
},
//氣象站點(diǎn)列表
series: [{
type: 'scatter',
coordinateSystem: 'geo',
data: stationData.value,
symbolSize: 10,
label: {
show: true,
formatter: function (params) {
return params.name; // 顯示點(diǎn)的name
},
position: 'top', // 或其他位置
color: '#FF4500' // 設(shè)置標(biāo)簽字體顏色為紅色
},
itemStyle: {
normal: {
color: '#FFA500' // 設(shè)置為橘黃色
}
},
}]
}
myChart.hideLoading()
myChart.setOption(option)
// 自適應(yīng)屏幕
window.addEventListener('resize', function () {
myChart.resize()
})
}
</script>
<style scoped>
.chart {
height: 550px;
}
.detail-chart {
height: 100%;
overflow: auto;
}
</style>OK,大功搞定?。?!
到此這篇關(guān)于echarts加載區(qū)域地圖并標(biāo)注點(diǎn)的文章就介紹到這了,更多相關(guān)echarts加載區(qū)域地圖標(biāo)注點(diǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS實(shí)現(xiàn)的貪吃蛇游戲完整實(shí)例
這篇文章主要介紹了JS實(shí)現(xiàn)的貪吃蛇游戲,結(jié)合完整實(shí)例形式分析了javascript實(shí)現(xiàn)貪吃蛇游戲的具體步驟、原理與相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
Postman參數(shù)化實(shí)現(xiàn)過(guò)程及原理解析
這篇文章主要介紹了Postman參數(shù)化實(shí)現(xiàn)過(guò)程及原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
用js實(shí)現(xiàn)層隨著內(nèi)容大小動(dòng)態(tài)漸變改變 推薦
以前做谷歌的小工具時(shí),api里提供了一個(gè)很有用的函數(shù),那就是在程序運(yùn)行時(shí)可以使層動(dòng)態(tài)隨內(nèi)容大小而變化,而且是平滑變換,在一些jquery的lightbox里也普遍有這種效果,看起來(lái)很酷的樣子。2009-12-12
IE6下出現(xiàn)JavaScript未結(jié)束的字符串常量錯(cuò)誤的解決方法
JavaScript文件只在IE6下出錯(cuò)(“未結(jié)束的字符串常量”)的解決辦法。2010-11-11
小程序?qū)崿F(xiàn)點(diǎn)擊動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)點(diǎn)擊動(dòng)畫(huà)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Js調(diào)用Java方法并互相傳參的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇Js調(diào)用Java方法并互相傳參的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08

