最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue 百度地圖(vue-baidu-map)繪制方向箭頭折線實(shí)例代碼詳解

 更新時間:2020年04月28日 08:38:43   作者:L1mbolv-1  
這篇文章主要介紹了vue 百度地圖(vue-baidu-map)繪制方向箭頭折線,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

在開發(fā)過程中發(fā)現(xiàn) vue-baidu-map 封裝的 BmPolyline 折線組件不能順利繪制出帶箭頭的紋理。

原因是 BmPolyline 文檔中雖然有 icons 屬性,但是對應(yīng)的源文件中并沒有props接收 icons

最初的開發(fā)思路:

根據(jù) vue-baidu-map 折線組件的官方文檔,在vue中通過Prop,為 BmPolyline 組件傳遞一個 icons 數(shù)組,數(shù)組的元素必須為 IconSequence 類的實(shí)例對象。

IconSequence 類的實(shí)例對象則是在 BaiduMap 組件的 ready 事件中拿到 BMap 類和 map 地圖實(shí)例對象,然后依次調(diào)用 BMap 基類的 Symbol , IconSequence 子類,完成 IconSequence 對象的初始化。具體參數(shù)含義及代碼實(shí)現(xiàn)見上文發(fā)的官方案例地址。

按照上述思路完成代碼編寫后并不能得到預(yù)期中的結(jié)果。因?yàn)?BmPolyline 對應(yīng)的源文件中并沒有props接收 icons 。

解決方案

/node_modules/vue-baidu-map/components/overlays 目錄下的 BmPolyline 源文件復(fù)制,粘貼到另一個vue文件中,然后手動為折線組件配置 icons

詳細(xì)解決方案見下方代碼:

new_polyline.vue新的折線組件文件

<script>
/**
 * 注意此處三個引入路徑
 * 在源文件中使用的是相對路徑
 * 但是因?yàn)楝F(xiàn)在是自定義組件,所以要重新調(diào)整路徑
 */
import commonMixin from "vue-baidu-map/components/base/mixins/common.js";
import bindEvents from "vue-baidu-map/components/base/bindEvent.js";
import { createPoint } from "vue-baidu-map/components/base/factory.js";

export default {
 // 起一個新名字
 name: "new-polyline",
 render() {},
 mixins: [commonMixin("overlay")],
 props: {
  path: {
   type: Array
  },
  // 新聲明一個icons
  icons: {
   type: Array
  },
  strokeColor: {
   type: String
  },
  strokeWeight: {
   type: Number
  },
  strokeOpacity: {
   type: Number
  },
  strokeStyle: {
   type: String
  },
  massClear: {
   type: Boolean,
   default: true
  },
  clicking: {
   type: Boolean,
   default: true
  },
  editing: {
   type: Boolean,
   default: false
  }
 },
 watch: {
  path: {
   handler(val, oldVal) {
    this.reload();
   },
   deep: true
  },
  strokeColor(val) {
   this.originInstance.setStrokeColor(val);
  },
  strokeOpacity(val) {
   this.originInstance.setStrokeOpacity(val);
  },
  strokeWeight(val) {
   this.originInstance.setStrokeWeight(val);
  },
  strokeStyle(val) {
   this.originInstance.setStrokeStyle(val);
  },
  editing(val) {
   val
    ? this.originInstance.enableEditing()
    : this.originInstance.disableEditing();
  },
  massClear(val) {
   val
    ? this.originInstance.enableMassClear()
    : this.originInstance.disableMassClear();
  },
  clicking(val) {
   this.reload();
  }
 },
 methods: {
  load() {
   const {
    BMap,
    map,
    path,
    // 參數(shù)解構(gòu) 加入icons
    icons,
    strokeColor,
    strokeWeight,
    strokeOpacity,
    strokeStyle,
    editing,
    massClear,
    clicking
   } = this;
   const overlay = new BMap.Polyline(
    path.map(item =>
     createPoint(BMap, {
      lng: parseFloat(item.lng),
      lat: parseFloat(item.lat)
     })
    ),
    {
     strokeColor,
     strokeWeight,
     strokeOpacity,
     strokeStyle,
     // 配置icons
     icons,
     enableEditing: editing,
     enableMassClear: massClear,
     enableClicking: clicking
    }
   );
   this.originInstance = overlay;
   map.addOverlay(overlay);
   bindEvents.call(this, overlay);
  }
 }
};
</script>

地圖文件

<template>
 <div class="container">
  <baidu-map class="map" :scroll-wheel-zoom="true" :center="center" :zoom="zoom" @ready="ready">
   <new-polyline
    v-if="points && points.length >= 2 && checkPoints({ points })"
    :path="points"
    :icons="icons"
    stroke-color="#0091ea"
    :stroke-opacity="0.8"
    :stroke-weight="10"
   ></new-polyline>
  </baidu-map>
 </div>
</template>
<script>
import newPolyline from "./new_polyline";
export default {
 components: {
  newPolyline
 },
 data() {
  return {
   center: {
    lng: 116.404,
    lat: 39.915
   },
   zoom: 5,
   points: [],
   icons: []
  };
 },
 methods: {
  ready({ BMap, map }) {
   this.points = this.getPointsSomehow();
   var sy = new BMap.Symbol(BMap_Symbol_SHAPE_FORWARD_OPEN_ARROW, {
    scale: 0.5, // 圖標(biāo)縮放大小
    strokeColor: "#fff", // 設(shè)置矢量圖標(biāo)的線填充顏色
    strokeWeight: "3" // 設(shè)置線寬
   });
   var icons = new BMap.IconSequence(sy, "5%", "15%");
   this.icons.push(icons)
  },
  getPointsSomehow() {
   // 116.324356,39.980648
   // 118.532031,32.010158
   // 121.475599,31.380939
   var arr = [
    { lng: 116.324356, lat: 39.980648 },
    { lng: 118.532031, lat: 32.010158 },
    { lng: 121.475599, lat: 31.380939 }
   ];
   return arr;
  },
  // 查重 如果數(shù)組中只有一組有意義的坐標(biāo),繪制折線時可能會報錯,因?yàn)槔L制一條折線需要兩組不同的坐標(biāo)點(diǎn)
  checkPoints({ points }) {
   // 拿到第一組點(diǎn)
   var originPoint = points[0];
   // 將第一組點(diǎn)與后續(xù)點(diǎn)進(jìn)行對比 如果坐標(biāo)集合中只有一組實(shí)際坐標(biāo)點(diǎn)則return false
   // 只要坐標(biāo)集合中有兩組不同的實(shí)際坐標(biāo)點(diǎn),則return true
   for (var i = 1; i < points.length; i++) {
    if (
     points[i].lat !== originPoint.lat ||
     points[i].lng !== originPoint.lng
    ) {
     return true;
    }
   }
   return false;
  }
 }
};
</script>

<style>
.map {
 width: 100%;
 height: 300px;
}
</style>

到此這篇關(guān)于vue 百度地圖(vue-baidu-map)繪制方向箭頭折線實(shí)例代碼詳解的文章就介紹到這了,更多相關(guān)vue 百度地圖方向箭頭折線內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue結(jié)合vant實(shí)現(xiàn)聯(lián)動效果

    vue結(jié)合vant實(shí)現(xiàn)聯(lián)動效果

    這篇文章主要為大家詳細(xì)介紹了vue結(jié)合vant實(shí)現(xiàn)聯(lián)動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • vue中的vue-router?query方式和params方式詳解

    vue中的vue-router?query方式和params方式詳解

    這篇文章主要介紹了vue中的vue-router?query方式和params方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue3在單個組件中實(shí)現(xiàn)類似mixin的事件調(diào)用

    vue3在單個組件中實(shí)現(xiàn)類似mixin的事件調(diào)用

    這篇文章主要為大家詳細(xì)介紹了vue3如何在單個組件中實(shí)現(xiàn)類似mixin的事件調(diào)用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • el-form表單驗(yàn)證的一些實(shí)用方法總結(jié)

    el-form表單驗(yàn)證的一些實(shí)用方法總結(jié)

    表單校驗(yàn)是注冊環(huán)節(jié)中必不可少的操作,表單校驗(yàn)通過一定的規(guī)則來確保用戶提交數(shù)據(jù)的有效性,下面這篇文章主要給大家介紹了關(guān)于el-form表單驗(yàn)證的一些實(shí)用方法,需要的朋友可以參考下
    2023-01-01
  • vue通信方式EventBus的實(shí)現(xiàn)代碼詳解

    vue通信方式EventBus的實(shí)現(xiàn)代碼詳解

    這篇文章主要介紹了vue通信方法EventBus的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06
  • 使用vue指令解決文本的溢出提示的問題

    使用vue指令解決文本的溢出提示的問題

    在我們項(xiàng)目開發(fā)中,經(jīng)常會有超長文本溢出提示,未溢出則不提示的場景,接下來我們將一步步用vue指令實(shí)現(xiàn)這個需求,文中有詳細(xì)的代碼講解,感興趣的朋友跟著小編一起來看看吧
    2023-08-08
  • vue?router進(jìn)行路由跳轉(zhuǎn)并攜帶參數(shù)的實(shí)例詳解(params/query)

    vue?router進(jìn)行路由跳轉(zhuǎn)并攜帶參數(shù)的實(shí)例詳解(params/query)

    在使用`router.push`進(jìn)行路由跳轉(zhuǎn)到另一個組件時,可以通過`params`或`query`來傳遞參數(shù),這篇文章主要介紹了vue?router進(jìn)行路由跳轉(zhuǎn)并攜帶參數(shù)(params/query),需要的朋友可以參考下
    2023-09-09
  • Vue3播放m3u8視頻的兩種實(shí)現(xiàn)方式示例

    Vue3播放m3u8視頻的兩種實(shí)現(xiàn)方式示例

    這篇文章主要介紹了Vue3播放m3u8視頻的兩種實(shí)現(xiàn)方式,兩種視頻播放器組件分別是vue3-video-play和chimee-player,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-01-01
  • Vue.js上下滾動加載組件的實(shí)例代碼

    Vue.js上下滾動加載組件的實(shí)例代碼

    本篇文章主要介紹了Vue.js上下滾動加載組件的實(shí)例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • vue3 自定義loading的操作方法

    vue3 自定義loading的操作方法

    這篇文章主要介紹了vue3 自定義loading的操作方法,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11

最新評論

花莲市| 仁怀市| 启东市| 富顺县| 新密市| 宁海县| 台湾省| 城口县| 耿马| 通州市| 安阳县| 白玉县| 景谷| 兴隆县| 通河县| 盱眙县| 诏安县| 时尚| 邳州市| 临澧县| 兴山县| 航空| 晋州市| 乐亭县| 博客| 开鲁县| 康平县| 大同市| 平塘县| 布拖县| 江城| 赣榆县| 三都| 太和县| 宝山区| 清徐县| 大方县| 微山县| 陵水| 苏州市| 白朗县|