echarts地圖設(shè)置背景圖片及海岸線實(shí)例代碼

1、地圖設(shè)置背景圖片
// data
domImg: require('@/assets/images/largescreen/nation/map_bg.png'),
// js 渲染地圖之前
var domImg = document.createElement("img");
domImg.style.height = domImg.height = domImg.width = domImg.style.width = "100px";
domImg.src = that.domImg;
// js 渲染地址時(shí),在地圖配置項(xiàng)geo中itemStyle
normal: {
areaColor: {
type: "pattern",
image: domImg, //配置圖片
repeat: "repeat", //可選值repeat、no-repeat、repeat-x、repeat-y
},
}
2、地圖外部多層輪廓線
首先來(lái)看單層加粗外邊框,其實(shí)很簡(jiǎn)單。咱們看一下效果
// 在地圖配置項(xiàng)series中添加樣式,效果如下圖
itemStyle: {
normal: {
areaColor: '#3075b2',
borderColor: '#4c99f9',
borderWidth: 1
},
emphasis: {
areaColor: '#01215c'
}
}
// 在地圖的配置項(xiàng)geo中設(shè)置,效果如下圖
itemStyle: {
normal: {
areaColor: '#01215c',
borderWidth: 5,//設(shè)置外層邊框
borderColor:'#9ffcff',
}
}
在地圖配置項(xiàng)series、geo中設(shè)置邊框,單獨(dú)設(shè)置就是上圖所示。一起設(shè)置如下圖,中間邊框細(xì),外輪廓邊框粗的效果。
外輪廓加投影就是在 geo中添加 shadowColor設(shè)置,以及偏移shadowOffsetX、shadowOffsetY、shadowBlur。
如果想要多層外輪廓,就是在geo設(shè)置多個(gè)對(duì)象。
// 通過(guò)偏移,縮放來(lái)實(shí)現(xiàn)多層外輪廓的效果
this.option.geo = [
{
// 主圖
map: map,
zlevel: 0,
zoom: 1.2, //當(dāng)前視角的縮放比例
roam: false, //是否開(kāi)啟平游或縮放
center: undefined,
show: true,
label: {
normal: {
show: false,
},
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
borderColor: "rgba(141, 199, 255,1)",
borderWidth: 1,
areaColor: {
type: "pattern",
image: domImg, //配置圖片
repeat: "repeat", //可選值repeat、no-repeat、repeat-x、repeat-y
},
},
emphasis: {
areaColor: "#2d9eff", //懸浮區(qū)背景
shadowColor: "rgba(20, 113, 255,1)",
shadowOffsetX: -2,
shadowOffsetY: 5,
shadowBlur: 10,
},
},
},
//第一層投影
{
map: map,
zlevel: -1,
zoom: 1.22, //當(dāng)前視角的縮放比例
roam: false, //是否開(kāi)啟平游或縮放
center: undefined,
show: true,
label: {
normal: {
show: false,
},
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
borderJoin: "round",
borderColor: "rgba(176,228,252,1)",
borderWidth: 3,
areaColor: "rgba(133,188,232,1)",
shadowColor: "rgba(133,188,232,.7)",
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 25,
},
emphasis: {
show: false,
},
},
},
// 第二層投影
{
map: map,
zlevel: -2,
zoom: 1.2, //當(dāng)前視角的縮放比例
roam: false, //是否開(kāi)啟平游或縮放
center: undefined,
show: true,
label: {
normal: {
show: false,
},
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
borderJoin: "round",
areaColor: "rgba(30,49,105,1)",
shadowColor: "rgba(30,49,105,1)",
shadowOffsetX: -5,
shadowOffsetY: 6,
},
emphasis: {
show: false,
},
},
},
}
3、地圖海岸線
在echarts中regions是對(duì)特定的區(qū)域配置樣式,opacity中0的時(shí)候不會(huì)繪制該圖形,所以根據(jù)regions配置項(xiàng)來(lái)清除一部分圖形。這樣一來(lái),直接在一個(gè)map上是不能實(shí)現(xiàn)海岸線效果的。那就需要兩個(gè)div地圖來(lái)實(shí)現(xiàn)海岸線效果。一層map是頂層的,完整數(shù)據(jù)的地圖,一層是去掉海岸想相關(guān)數(shù)據(jù)的地圖層。


// 首先把一部分圖形隱藏
regionsOption:[
{
name: "北京市",
itemStyle: {
// 隱藏地圖
normal: {
opacity: 0, // 為 0 時(shí)不繪制該圖形
}
},
label: {
show: false // 隱藏文字
}
},
......
{
name: "南海諸島",
itemStyle: {
// 隱藏地圖
normal: {
opacity: 0, // 為 0 時(shí)不繪制該圖形
}
},
label: {
show: false // 隱藏文字
}
},
]完整的地圖數(shù)據(jù)我是從DataV.GeoAtlas下載的。
對(duì)某些省份圖形的隱藏之后,發(fā)現(xiàn),遼寧、廣西在海岸線中只占一部分,就不能根據(jù)隱藏圖形來(lái)實(shí)現(xiàn)了。但是可以修改地圖繪制的經(jīng)緯度,把遼寧、廣西的一部分經(jīng)緯度繪制去掉就可以得到下圖效果。 下載海岸線除去遼寧廣西部分經(jīng)緯度json數(shù)據(jù)

4、地圖中高亮顯示有數(shù)據(jù)的城市
數(shù)據(jù)高亮顯示,在地圖配置項(xiàng)series中data中設(shè)置itemStyle.areaColor。還可以加scatter,effectScatter都可以,根據(jù)需求來(lái)定。
// series-map.data.itemStyle地圖數(shù)據(jù)高亮顯示
var data = [
{ name: '天津', value: 4075, itemStyle: {areaColor: '#faa'} },
{ name: '湖北', value: 500, itemStyle: {areaColor: '#faa'} }
];
// series-effectScatter帶有漣漪特效動(dòng)畫(huà)的散點(diǎn)(氣泡)圖
// this.convertData() 的數(shù)據(jù)格式:根據(jù)獲取地圖的數(shù)據(jù),篩選出和data對(duì)應(yīng)的數(shù)據(jù),格式:[{name: 'name', value: 'value'}]
{
type: "effectScatter",
coordinateSystem: "geo",
data: this.convertData(),
// geoIndex:1,
symbolSize: function (val) {
return 10;
},
showEffectOn: "render",
rippleEffect: {
brushType: "stroke",
},
hoverAnimation: true,
label: {
normal: {
formatter: "",
position: "top",
show: true,
color: "#fff",
fontSize: 10,
fontWeight: 800,
},
},
itemStyle: {
normal: {
color: "#fdfbcc",
shadowBlur: 10,
shadowColor: "#fdfbcc",
},
},
zlevel: 1,
},
5、滾動(dòng)高亮輪播
根據(jù)dispatchAction來(lái)設(shè)置地圖的配置項(xiàng),和定時(shí)器相結(jié)合來(lái)實(shí)現(xiàn)滾動(dòng)高亮顯示
// 設(shè)置鼠標(biāo)移入移出地圖以及點(diǎn)擊地圖
mounted() {
this.$nextTick(() => {
this.initEcharts();
let that = this;
this.chart.on("click", this.echartsMapClick);
this.chart.on("mouseover", this.echartsMapMouseover);
this.chart.on("mouseout", this.echartsMapMouseout);
})
}
// 地圖鼠標(biāo)移入事件
echartsMapMouseover() {
clearInterval(this.tooltipAutoplay);
},
// 地圖鼠標(biāo)移出事件
echartsMapMouseout() {
this.setTooltipAutoplay();
},
// 動(dòng)態(tài)顯示tooltip
setTooltipAutoplay() {
clearInterval(this.tooltipAutoplay);
var index = 0; //播放所在下標(biāo)
var itemIndexList = new Array(this.mapDataList.length); //固定數(shù)組長(zhǎng)度為3
for (var i = 0; i < itemIndexList.length; i++) {
itemIndexList[i] = i;
}
this.tooltipAutoplay = setInterval(() => {
this.chart.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: itemIndexList,
});
this.chart.dispatchAction({
type: "showTip",
seriesIndex: 0,
dataIndex: this.tooltipAutoplayIndex,
});
this.chart.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: this.tooltipAutoplayIndex,
});
this.tooltipAutoplayIndex++;
if (this.tooltipAutoplayIndex >= this.mapDataList.length) {
this.tooltipAutoplayIndex = 0;
this.setTooltipAutoplay();
}
}, 6666);
},
總結(jié)
到此這篇關(guān)于echarts地圖設(shè)置背景圖片及海岸線的文章就介紹到這了,更多相關(guān)echarts地圖設(shè)置背景圖片 海岸線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS實(shí)現(xiàn)上傳圖片實(shí)時(shí)預(yù)覽功能
這篇文章主要介紹了JS實(shí)現(xiàn)上傳圖片實(shí)時(shí)預(yù)覽功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05
控制臺(tái)報(bào)錯(cuò):Cannot?access?'xxx'?before?initializatio
這篇文章主要給大家介紹了關(guān)于控制臺(tái)報(bào)錯(cuò):Cannot?access?'xxx'?before?initialization的解決方法,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-11-11
在Javascript類(lèi)中使用setTimeout
2008-01-01
淺談Webpack多頁(yè)應(yīng)用HMR卡住問(wèn)題
這篇文章主要介紹了淺談Webpack多頁(yè)應(yīng)用HMR卡住問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-04-04
uni-app微信小程序使用echarts的詳細(xì)圖文教程
為了兼容小程序Canvas,ECharts提供了一個(gè)小程序的組件,用這種方式可以方便地使用ECharts,下面這篇文章主要給大家介紹了關(guān)于uni-app微信小程序使用echarts的相關(guān)資料,需要的朋友可以參考下2022-10-10
uniapp組件傳值的方法(父?jìng)髯?子傳父,對(duì)象傳值)實(shí)戰(zhàn)案例
現(xiàn)在的前端開(kāi)發(fā)中基本上都是組件化開(kāi)發(fā)的,下面這篇文章主要給大家介紹了關(guān)于uniapp組件傳值(父?jìng)髯?子傳父,對(duì)象傳值)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03
es6函數(shù)name屬性功能與用法實(shí)例分析
這篇文章主要介紹了es6函數(shù)name屬性,結(jié)合實(shí)例形式分析了es6函數(shù)name屬性基本原理、功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
JS使用面向?qū)ο蠹夹g(shù)實(shí)現(xiàn)的tab選項(xiàng)卡效果示例
這篇文章主要介紹了JS使用面向?qū)ο蠹夹g(shù)實(shí)現(xiàn)的tab選項(xiàng)卡效果,結(jié)合具體實(shí)例形式分析了js面向?qū)ο蠹夹g(shù)與tab選項(xiàng)卡功能的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-02-02
JS實(shí)現(xiàn)將人民幣金額轉(zhuǎn)換為大寫(xiě)的示例代碼
本篇文章主要是對(duì)使用JS實(shí)現(xiàn)將人民幣金額轉(zhuǎn)換為大寫(xiě)的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02

