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、地圖外部多層輪廓線
首先來看單層加粗外邊框,其實(shí)很簡單。咱們看一下效果
// 在地圖配置項(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è)對象。
// 通過偏移,縮放來實(shí)現(xiàn)多層外輪廓的效果 this.option.geo = [ { // 主圖 map: map, zlevel: 0, zoom: 1.2, //當(dāng)前視角的縮放比例 roam: false, //是否開啟平游或縮放 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, //是否開啟平游或縮放 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, //是否開啟平游或縮放 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是對特定的區(qū)域配置樣式,opacity中0的時(shí)候不會繪制該圖形,所以根據(jù)regions配置項(xiàng)來清除一部分圖形。這樣一來,直接在一個(gè)map上是不能實(shí)現(xiàn)海岸線效果的。那就需要兩個(gè)div地圖來實(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下載的。
對某些省份圖形的隱藏之后,發(fā)現(xiàn),遼寧、廣西在海岸線中只占一部分,就不能根據(jù)隱藏圖形來實(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ù)需求來定。
// series-map.data.itemStyle地圖數(shù)據(jù)高亮顯示 var data = [ { name: '天津', value: 4075, itemStyle: {areaColor: '#faa'} }, { name: '湖北', value: 500, itemStyle: {areaColor: '#faa'} } ]; // series-effectScatter帶有漣漪特效動(dòng)畫的散點(diǎn)(氣泡)圖 // this.convertData() 的數(shù)據(jù)格式:根據(jù)獲取地圖的數(shù)據(jù),篩選出和data對應(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來設(shè)置地圖的配置項(xiàng),和定時(shí)器相結(jié)合來實(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ù)組長度為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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript實(shí)現(xiàn)二級菜單的制作
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)二級菜單的制作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10BootStrap Fileinput初始化時(shí)的一些參數(shù)
本文通過一個(gè)例子給大家簡單介紹了bootstrap fileinput初始化時(shí)的一些參數(shù),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2016-12-12利用javaScript實(shí)現(xiàn)點(diǎn)擊輸入框彈出窗體選擇信息
這篇文章主要是對利用javaScript實(shí)現(xiàn)點(diǎn)擊輸入框彈出窗體選擇信息進(jìn)的實(shí)例行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12