亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼(基于postrender機(jī)制)

 更新時(shí)間:2021年09月01日 17:26:21   作者:~疆  
本篇文章給大家介紹基于postrender機(jī)制使用Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

效果圖:

實(shí)現(xiàn)代碼:

<template>
  <div id="map" style="width: 100vw; height: 100vh" />
</template>
<script>
import "ol/ol.css";
import TileLayer from "ol/layer/Tile";
import VectorLayer from "ol/layer/Vector";
import VectorSource from "ol/source/Vector";
import XYZ from "ol/source/XYZ";
import { Map, View, Feature } from "ol";
import { Style, Circle, Stroke } from "ol/style";
import { Point } from "ol/geom";
import { getVectorContext } from "ol/render";
 
// 邊界json數(shù)據(jù)
export default {
  data() {
    return {
      map: {},
      coordinates: [
        { x: "106.918082", y: "31.441314" }, //重慶
        { x: "86.36158200334317", y: "41.42448570787448" }, //新疆
        { x: "89.71757707811526", y: "31.02619817424643" }, //西藏
        { x: "116.31694544853109", y: "39.868508850821115" }, //北京
        { x: "103.07940932026341", y: "30.438580338450862" }, //成都
      ],
      speed: 0.3,
    };
  },
  mounted() {
    this.initMap();
    this.addDynamicPoints(this.coordinates);
  },
  methods: {
    /**
     * 初始化地圖
     */
    initMap() {
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new XYZ({
              url: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
            }),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [108.522097, 37.272848],
          zoom: 4.7,
        }),
      });
    },
    /**
     * 批量添加閃爍點(diǎn)
     */
    addDynamicPoints(coordinates) {
      // 設(shè)置圖層
      let pointLayer = new VectorLayer({ source: new VectorSource() });
      // 添加圖層
      this.map.addLayer(pointLayer);
      // 循環(huán)添加feature
      let pointFeature = [];
      for (let i = 0; i < coordinates.length; i++) {
        // 創(chuàng)建feature,一個(gè)feature就是一個(gè)點(diǎn)坐標(biāo)信息
        const feature = new Feature({
          geometry: new Point([coordinates[i].x, coordinates[i].y]),
        });
        pointFeature.push(feature);
      }
      //把要素集合添加到圖層
      pointLayer.getSource().addFeatures(pointFeature);
      // 關(guān)鍵的地方在此:監(jiān)聽(tīng)postrender事件,在里面重新設(shè)置circle的樣式
      let radius = 0;
      pointLayer.on("postrender", (e) => {
        if (radius >= 20) radius = 0;
        let opacity = (20 - radius) * (1 / 20); //不透明度
        let pointStyle = new Style({
          image: new Circle({
            radius: radius,
            stroke: new Stroke({
              color: "rgba(255,0,0" + opacity + ")",
              width: 3 - radius / 10, //設(shè)置寬度
            }),
          }),
        });
        // 獲取矢量要素上下文
        let vectorContext = getVectorContext(e);
        vectorContext.setStyle(pointStyle);
        pointFeature.forEach((feature) => {
          vectorContext.drawGeometry(feature.getGeometry());
        });
        radius = radius + this.speed; //調(diào)整閃爍速度
        //請(qǐng)求地圖渲染(在下一個(gè)動(dòng)畫(huà)幀處)
        this.map.render();
      });
    },
  },
};
</script>

參考文章

到此這篇關(guān)于Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼(基于postrender機(jī)制)的文章就介紹到這了,更多相關(guān)Vue Openlayer閃爍點(diǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue中的封裝常用工具類(lèi)

    vue中的封裝常用工具類(lèi)

    這篇文章主要介紹了vue中的封裝常用工具類(lèi),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • vue tab切換,解決echartst圖表寬度只有100px的問(wèn)題

    vue tab切換,解決echartst圖表寬度只有100px的問(wèn)題

    這篇文章主要介紹了vue tab切換,解決echartst圖表寬度只有100px的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • vue(element ui)使用websocket及心跳檢測(cè)方式

    vue(element ui)使用websocket及心跳檢測(cè)方式

    這篇文章主要介紹了vue(element ui)使用websocket及心跳檢測(cè)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vue3使用ref的性能警告問(wèn)題

    vue3使用ref的性能警告問(wèn)題

    這篇文章主要介紹了vue3使用ref的性能警告問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • 基于vue 實(shí)現(xiàn)token驗(yàn)證的實(shí)例代碼

    基于vue 實(shí)現(xiàn)token驗(yàn)證的實(shí)例代碼

    這篇文章主要介紹了基于vue 實(shí)現(xiàn)token驗(yàn)證的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-12-12
  • Vue 通過(guò)自定義指令回顧v-內(nèi)置指令(小結(jié))

    Vue 通過(guò)自定義指令回顧v-內(nèi)置指令(小結(jié))

    這篇文章主要介紹了Vue 通過(guò)自定義指令回顧v-內(nèi)置指令(小結(jié)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • 一文完全掌握Vue中的$set方法

    一文完全掌握Vue中的$set方法

    這篇文章主要給大家介紹了關(guān)于如何完全掌握Vue中$set方法的相關(guān)資料,vue中$set方法對(duì)數(shù)組和對(duì)象的處理本質(zhì)上的一樣的,對(duì)新增的值添加響應(yīng)然后手動(dòng)觸發(fā)派發(fā)更新,需要的朋友可以參考下
    2023-11-11
  • Vue數(shù)據(jù)雙向綁定原理實(shí)例解析

    Vue數(shù)據(jù)雙向綁定原理實(shí)例解析

    這篇文章主要介紹了Vue數(shù)據(jù)雙向綁定原理實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • Vue中nprogress頁(yè)面加載進(jìn)度條的方法實(shí)現(xiàn)

    Vue中nprogress頁(yè)面加載進(jìn)度條的方法實(shí)現(xiàn)

    這篇文章主要介紹了Vue中nprogress頁(yè)面加載進(jìn)度條的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • vue3利用v-model實(shí)現(xiàn)父子組件之間數(shù)據(jù)同步的代碼詳解

    vue3利用v-model實(shí)現(xiàn)父子組件之間數(shù)據(jù)同步的代碼詳解

    在Vue 3中,v-model這一指令也得到了升級(jí),使得父子組件之間的數(shù)據(jù)同步變得更加容易和靈活,本文將探討一下Vue 3中如何利用v-model來(lái)實(shí)現(xiàn)父子組件之間的數(shù)據(jù)同步,需要的朋友可以參考下
    2024-03-03

最新評(píng)論