Vue+Openlayer批量設(shè)置閃爍點(diǎn)的實(shí)現(xiàn)代碼(基于postrender機(jī)制)
效果圖:
實(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)文章希望大家以后多多支持腳本之家!
- VUE + OPENLAYERS實(shí)現(xiàn)實(shí)時(shí)定位功能
- 基于Vue+Openlayer實(shí)現(xiàn)動(dòng)態(tài)加載geojson的方法
- Vue中使用Openlayer實(shí)現(xiàn)加載動(dòng)畫(huà)效果
- vue+openlayers繪制省市邊界線
- vue項(xiàng)目中openlayers繪制行政區(qū)劃
- vue-openlayers實(shí)現(xiàn)地圖坐標(biāo)彈框效果
- vue集成openlayers加載geojson并實(shí)現(xiàn)點(diǎn)擊彈窗教程
- Vue+Openlayers自定義軌跡動(dòng)畫(huà)
相關(guān)文章
vue tab切換,解決echartst圖表寬度只有100px的問(wèn)題
這篇文章主要介紹了vue tab切換,解決echartst圖表寬度只有100px的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07vue(element ui)使用websocket及心跳檢測(cè)方式
這篇文章主要介紹了vue(element ui)使用websocket及心跳檢測(cè)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07基于vue 實(shí)現(xiàn)token驗(yàn)證的實(shí)例代碼
這篇文章主要介紹了基于vue 實(shí)現(xiàn)token驗(yàn)證的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-12-12Vue 通過(guò)自定義指令回顧v-內(nèi)置指令(小結(jié))
這篇文章主要介紹了Vue 通過(guò)自定義指令回顧v-內(nèi)置指令(小結(jié)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09Vue中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-11vue3利用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