vue-baidu-map實(shí)現(xiàn)區(qū)域圈線和路徑的漸變色
vue-baidu-map區(qū)域圈線和路徑的漸變色

代碼:
- 圈的部分有兩種寫(xiě)法一種是用組件直接寫(xiě),一種是不用組件。
- 這里因?yàn)槲业臄?shù)據(jù)是動(dòng)態(tài)的,上面地圖的點(diǎn)還有路線需要切換,但是區(qū)域的線不用切換。
- 就采用了不是組件的寫(xiě)法。
圈的地區(qū)
方法一:采用畫(huà)線組件bm-polyline
<bm-polyline
:path="polylinePath"
stroke-color="#00ccff"
:stroke-opacity="1"
:stroke-weight="2"
:editing="false"
></bm-polyline>
// 漸變色是在app.vue里面寫(xiě)的
svg path{
filter: drop-shadow(2px 4px 6px #00ccff);
}方法二:自己手動(dòng)添加
// 我是把這個(gè)方法單獨(dú)拿出來(lái)了,使用的時(shí)候引用就好
getArea(){
var polyliness = []
this.polylinePath.forEach((i) => {
polyliness.push(new this.BMap.Point(i.lng, i.lat));
});
var polylinea = new this.BMap.Polyline(polyliness, {strokeColor: "#00ccff", strokeWeight: 1, strokeOpacity: 3}); //創(chuàng)建折線
//參數(shù):顏色,線的寬度,線的透明度
this.map.addOverlay(polylinea);
polylinea.disableMassClear();//這個(gè)是防止下面我刪除線的時(shí)候它不刪除
},路徑的折線
同樣我也是分出來(lái)了。
但因?yàn)樗臄?shù)據(jù)是根據(jù)后臺(tái)獲得的,會(huì)有延遲,所以在調(diào)用它的時(shí)候需要加個(gè)延遲器
//添加路線箭頭
getPoly(){
//創(chuàng)建路線
var sy = new this.BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
scale: 0.6, //圖標(biāo)縮放大小
strokeColor: "#24a9fa", //設(shè)置矢量圖標(biāo)的線填充顏色
strokeWeight: "2", //設(shè)置線寬
});
var icons = new this.BMap.IconSequence(sy, "10", "30");
this.pointList = JSON.parse(JSON.stringify(this.pointList))
// 創(chuàng)建polyline對(duì)象
var pois = [];
this.pointList.forEach((i) => {
pois.push(new this.BMap.Point(i.lng, i.lat));
});
// 插入漸變
// let mapE = document.getElementsByClassName("bm-view")[1];
setTimeout(()=>{
let svgE = document.getElementsByTagName("svg")[0];
console.log("svg",svgE)
let def = `<defs>
<linearGradient id="MyGradient">
<stop offset="0%" stop-color="#2c468b" />
<stop offset="50%" stop-color="#2f5d95" />
<stop offset="100%" stop-color="#24a9fa" />
</linearGradient>
</defs>`;
// if (svgE.length==0) {
// for(let i in svgE) {
// console.log("i",i)
svgE.insertAdjacentHTML("afterBegin",def);
// }
// }
},1000)
var sj = new this.BMap.Polyline(pois, {
enableEditing: false, //是否啟用線編輯,默認(rèn)為false
enableClicking: true, //是否響應(yīng)點(diǎn)擊事件,默認(rèn)為true
icons: [icons],
strokeWeight: "3", //折線的寬度,以像素為單位
strokeOpacity: 0.8, //折線的透明度,取值范圍0 - 1
strokeColor: "url(#MyGradient)", //折線顏色
// strokeColor: "red", //折線顏色
});
this.map.addOverlay(sj); //增加折線
},
//調(diào)用,在需要調(diào)用的地方加上它
setTimeout(()=>{
this.getPoly()
},300)總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
基于element-ui對(duì)話框el-dialog初始化的校驗(yàn)問(wèn)題解決
這篇文章主要介紹了基于element-ui對(duì)話框el-dialog初始化的校驗(yàn)問(wèn)題解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09
Vue數(shù)據(jù)回顯表單無(wú)法編輯的解決方案
這篇文章主要介紹了Vue數(shù)據(jù)回顯表單無(wú)法編輯的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
vue3?v-bind="$attrs"繼承組件全部屬性的解決方案
這篇文章主要介紹了vue3?v-bind=“$attrs“?繼承組件全部屬性的解決方案,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
vue cli 3.0下配置開(kāi)發(fā)環(huán)境下的sourcemap問(wèn)題
這篇文章主要介紹了vue cli 3.0下配置開(kāi)發(fā)環(huán)境下的sourcemap問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
Vite多環(huán)境配置項(xiàng)目高定制化能力詳解
這篇文章主要為大家介紹了Vite多環(huán)境配置項(xiàng)目高定制化能力詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
vue中el-autocomplete支持分頁(yè)上拉加載功能
最近在項(xiàng)目中使用了ElementUI的el-autocomplete,下面這篇文章主要介紹了vue中el-autocomplete支持分頁(yè)上拉加載功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
vue2.0設(shè)置proxyTable使用axios進(jìn)行跨域請(qǐng)求的方法
這篇文章主要介紹了vue2.0設(shè)置proxyTable使用axios進(jìn)行跨域請(qǐng)求,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10

