vue3-openlayers marker 光暈擴散(光環擴散)(postrender 事件和 render 方法)

本篇介紹一下使用 vue3-openlayers marker 光暈擴散(光環擴散)(postrender 事件和 render 方法)

1 需求

  • marker 光暈擴散(光環擴散)

2 分析

marker 光暈擴散(光環擴散)使用 postrender 事件和 render 方法
關于即時渲染的知識點請看上篇《openlayers marker 光暈擴散(光環擴散)(postrender 事件和 render 方法)》

3 實現

3.1 實現一(光環)

<template><ol-map:loadTilesWhileAnimating="true":loadTilesWhileInteracting="true"style="width: 100%; height: 100%"ref="mapRef"><ol-view ref="view" :center="center" :zoom="zoom" :projection="projection" /><ol-tile-layer><ol-source-tianditulayerType="img":projection="projection":tk="key":hidpi="true"ref="sourceRef"></ol-source-tianditu></ol-tile-layer><ol-tile-layer><ol-source-tianditu:isLabel="true"layerType="img":projection="projection":tk="key":hidpi="true"></ol-source-tianditu></ol-tile-layer><ol-vector-layer ref="vectorLayerRef" @postrender="handlePostRender"><ol-source-vector><ol-feature><ol-geom-point :coordinates="[110, 30]"></ol-geom-point><ol-style><ol-style-icon :src="iconSrc" :scale="0.05"></ol-style-icon></ol-style></ol-feature><ol-feature><ol-geom-point :coordinates="[112, 31]"></ol-geom-point><ol-style><ol-style-icon :src="iconSrc" :scale="0.05"></ol-style-icon></ol-style></ol-feature></ol-source-vector></ol-vector-layer></ol-map><div class="toolbar"><el-button type="primary" @click="handleClick">{{ animationFlag ? '停止' : '開始' }}</el-button></div>
</template><script setup lang="ts">
import iconSrc from '@/assets/image/truck.png';
import { getVectorContext } from 'ol/render.js';
import { easeOut } from 'ol/easing.js';
import { Circle, Stroke, Style } from 'ol/style';const center = ref([121, 31]);
const projection = ref('EPSG:4326');
const zoom = ref(5);
const mapRef = ref();
const key = '替換為天地圖key';
const sourceRef = ref(null);
const vectorLayerRef = ref(null);
const animationFlag = ref(false);
const duration = ref([3000, 1000]);
const start = ref([0, 0]);const handleClick = () => {if (!animationFlag.value) {start.value = start.value.map(i => Date.now());vectorLayerRef.value.vectorLayer.changed();}animationFlag.value = !animationFlag.value;
};const handlePostRender = e => {if (animationFlag.value) {const time = e.frameState.time;vectorLayerRef.value.vectorLayer.getSource().getFeatures().forEach((f, idx) => {// 時間戳差(毫秒)let elapsedTime = time - start.value[idx];if (elapsedTime >= duration.value[idx]) {start.value[idx] = Date.now();elapsedTime = duration.value[idx];}// 獲取矢量上下文const vectorContext = getVectorContext(e);// elapsedRatio值0到1之間const elapsedRatio = elapsedTime / duration.value[idx];const radius = easeOut(elapsedRatio) * 25 + 5;const opacity = easeOut(1 - elapsedRatio);const style = new Style({image: new Circle({radius: radius,stroke: new Stroke({color: 'rgba(255, 0, 0, ' + opacity + ')',width: 1 + opacity})})});// 將feature渲染到畫布中。vectorContext.drawFeature(f.clone(), style);});mapRef.value.map.render();}
};
</script>
<style scoped lang="scss">
.toolbar {position: absolute;top: 20px;left: 100px;display: flex;justify-content: center;align-items: center;
}
</style>

3.2 實現二(光暈)

<template><ol-map:loadTilesWhileAnimating="true":loadTilesWhileInteracting="true"style="width: 100%; height: 100%"ref="mapRef"><ol-view ref="view" :center="center" :zoom="zoom" :projection="projection" /><ol-tile-layer><ol-source-tianditulayerType="img":projection="projection":tk="key":hidpi="true"ref="sourceRef"></ol-source-tianditu></ol-tile-layer><ol-tile-layer><ol-source-tianditu:isLabel="true"layerType="img":projection="projection":tk="key":hidpi="true"></ol-source-tianditu></ol-tile-layer><ol-vector-layer ref="vectorLayerRef" @postrender="handlePostRender"><ol-source-vector><ol-feature><ol-geom-point :coordinates="[110, 30]"></ol-geom-point></ol-feature><ol-feature><ol-geom-point :coordinates="[112, 31]"></ol-geom-point></ol-feature></ol-source-vector></ol-vector-layer><ol-vector-layer ><ol-source-vector><ol-feature><ol-geom-point :coordinates="[110, 30]"></ol-geom-point><ol-style><ol-style-icon :src="iconSrc" :scale="0.05"></ol-style-icon></ol-style></ol-feature><ol-feature><ol-geom-point :coordinates="[112, 31]"></ol-geom-point><ol-style><ol-style-icon :src="iconSrc" :scale="0.05"></ol-style-icon></ol-style></ol-feature></ol-source-vector></ol-vector-layer></ol-map><div class="toolbar"><el-button type="primary" @click="handleClick">{{ animationFlag ? '停止' : '開始' }}</el-button></div>
</template><script setup lang="ts">
import iconSrc from '@/assets/image/truck.png';
import { getVectorContext } from 'ol/render.js';
import { easeOut } from 'ol/easing.js';
import { Circle, Fill, Stroke, Style } from 'ol/style';const center = ref([121, 31]);
const projection = ref('EPSG:4326');
const zoom = ref(5);
const mapRef = ref();
const key = '替換為天地圖key';
const sourceRef = ref(null);
const vectorLayerRef = ref(null);
const animationFlag = ref(false);
const duration = ref([3000, 1000]);
const start = ref([0, 0]);const handleClick = () => {if (!animationFlag.value) {start.value = start.value.map(i => Date.now());vectorLayerRef.value.vectorLayer.changed();}animationFlag.value = !animationFlag.value;
};const handlePostRender = e => {if (animationFlag.value) {const time = e.frameState.time;vectorLayerRef.value.vectorLayer.getSource().getFeatures().forEach((f, idx) => {// 時間戳差(毫秒)let elapsedTime = time - start.value[idx];if (elapsedTime >= duration.value[idx]) {start.value[idx] = Date.now();elapsedTime = duration.value[idx];}// 獲取矢量上下文const vectorContext = getVectorContext(e);// elapsedRatio值0到1之間const elapsedRatio = elapsedTime / duration.value[idx];const radius = easeOut(elapsedRatio) * 25 + 5;const opacity = easeOut(1 - elapsedRatio);const style = new Style({image: new Circle({radius: radius,fill: new Fill({color: 'rgba(228, 147, 87, ' + opacity + ')'}),stroke: new Stroke({color: 'rgba(255, 0, 0, ' + opacity + ')',width: 1 + opacity})})});// 將feature渲染到畫布中。vectorContext.drawFeature(f.clone(), style);});mapRef.value.map.render();}
};
</script>
<style scoped lang="scss">
.toolbar {position: absolute;top: 20px;left: 100px;display: flex;justify-content: center;align-items: center;
}
</style>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/38483.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/38483.shtml
英文地址,請注明出處:http://en.pswp.cn/web/38483.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

中級java每日一道面試題-2024年7月2日

題目&#xff1a; 請解釋一下 Java 中的線程安全問題&#xff0c;并提供一些常見的解決方法。 答案&#xff1a; 線程安全問題是指在多線程環境下&#xff0c;多個線程同時訪問共享資源時可能出現的數據不一致或錯誤的情況。這可能導致程序的不可預測性和錯誤的結果。 常見的…

徐州三線服務器租用的優勢有哪些?

對于單線服務器與雙線服務器來說&#xff0c;三線服務器是能夠同時擁有電信、聯通和移動三條線路的服務器&#xff0c;同時也被稱為三線路由器或者是三線寬帶路由器&#xff0c;有著三個獨立的網卡和三個IP地址&#xff0c;使用戶無論是通過哪些線路連接都能夠進入服務器&#…

android.bp 靜態庫 依賴 動態庫

在Android平臺上&#xff0c;使用Android.bp文件來定義和構建Android靜態庫&#xff08;.so文件&#xff09;和動態庫&#xff08;.so文件&#xff09;之間的依賴關系是很常見的。以下是一個簡單的例子&#xff0c;展示了如何在Android.bp文件中定義一個靜態庫&#xff0c;它依…

SPI NAND、SD NAND和eMMC對比—MK米客方德

目錄 1. 容量: 2.封裝類型&#xff1a; 3.速度: 4.性能: 5.壽命: 6. 使用方式: 7. 其他優缺點: 8.常見應用場景: 1. 容量: SPI NAND通常提供從幾百MB到幾GB的存儲容量。 SD NAND的容量覆蓋范圍比SPI NAND更廣&#xff0c;從幾GB到幾十GB不等。 eMMC的容量范圍更大&a…

代碼隨想錄第41天|動態規劃

322. 零錢兌換 dp[j] : 最小硬幣數量, j 為金額(相當于背包空間)遞推公式 : dp[j] min(dp[j - coins[i]] 1, dp[j])初始化: 需要一個最大值, 避免覆蓋, dp[0] 0遍歷順序: 錢幣有序無序不影響, 因為求解最小個數, 結果相同(先遍歷物品后背包, 先背包后物品都可) class Solut…

【chatgpt】兩層gcn提取最后一層節點輸出特征,如何自定義簡單數據集

文章目錄 兩層gcn&#xff0c;提取最后一層節點輸出特征&#xff0c;10個節點&#xff0c;每個節點8個特征&#xff0c;連接關系隨機生成&#xff08;無全連接層&#xff09;如何計算MSE 100個樣本&#xff0c;并且使用批量大小為32進行訓練第一個版本定義數據集出錯&#xff0…

怎樣在《語文世界》期刊上發表論文?

怎樣在《語文世界》期刊上發表論文&#xff1f; 《語文世界》知網國家級 1.5-2版 2500字符左右 正常收25年4-6月版面 可加急24年內&#xff08;初中&#xff0c;高中&#xff0c;中職&#xff0c;高職&#xff0c;大學均可&#xff0c;操作周期2個月左右&#xff09; 《語文世…

【084】基于SpringBoot實現的家鄉特色推薦系統

系統介紹 視頻演示 點擊查看演示視頻 基于SpringBoot實現的家鄉特色推薦系統主要采用SpringBootVue進行開發&#xff0c;系統整體分為管理員、用戶兩種角色&#xff0c;主要功能包括首頁&#xff0c;個人中心&#xff0c;用戶管理&#xff0c;文章分類管理&#xff0c;文章分…

C語言結構體深入解析【結構體嵌套結構體,結構體變量和指針,結構體和函數,計算結構體大小,結構體數組,結構體成員的訪問,結構體與聯合】

C語言結構體深入解析 目錄 C語言結構體深入解析前言結構體的定義結構體在內存中的表示結構體變量初始化直接定義并初始化使用自己定義的結構體變量初始化新變量結構體數組初始化 結構體中嵌套結構體結構體成員訪問點操作符(.)箭頭操作符(->) 結構體變量和指針結構體指針定義…

TensorFlow代碼邏輯 vs PyTorch代碼邏輯

文章目錄 一、TensorFlow&#xff08;一&#xff09;導入必要的庫&#xff08;二&#xff09;加載MNIST數據集&#xff08;三&#xff09;數據預處理&#xff08;四&#xff09;構建神經網絡模型&#xff08;五&#xff09;編譯模型&#xff08;六&#xff09;訓練模型&#xf…

@RequestMapping屬性詳解及案例演示

RequestMapping源碼 Target({ElementType.TYPE, ElementType.METHOD}) Retention(RetentionPolicy.RUNTIME) Documented Mapping public interface RequestMapping {String name() default "";AliasFor("path")String[] value() default {};AliasFor(&quo…

智能寫作與痕跡消除:AI在創意文案和論文去痕中的應用

作為一名AI愛好者&#xff0c;我積累了許多實用的AI生成工具。今天&#xff0c;我想分享一些我經常使用的工具&#xff0c;這些工具不僅能幫助提升工作效率&#xff0c;還能激發創意思維。 我們都知道&#xff0c;隨著技術的進步&#xff0c;AI生成工具已經變得越來越智能&…

簡單分享 for循環,從基礎到高級

1. 基礎篇&#xff1a;Hello, For Loop! 想象一下&#xff0c;你想給班上的每位同學發送“Hello!”&#xff0c;怎么辦&#xff1f;那就是for循環啦&#xff0c; eg&#xff1a;首先有個名字的列表&#xff0c;for循環取出&#xff0c;分別打印 names ["Alice", …

Apache APISIX 介紹

Apache APISIX 是一個動態、實時、高性能的云原生API網關&#xff0c;屬于Apache軟件基金會旗下的項目。以下是對Apache APISIX的詳細介紹&#xff1a; 一、基本概述 定義&#xff1a;Apache APISIX是一個提供豐富流量管理功能的云原生API網關。功能&#xff1a;包括負載均衡…

git出現Permission denied問題

Warning: Permanently added ‘icode.baidu.com,10.11.81.103’ (RSA) to the list of known hosts. Permission denied (baas,keyboard-interactive,publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the…

nodejs操作excel文件實例,讀取sheets, 設置cell顏色

本代碼是我幫客戶做的兼職的實例&#xff0c;涉及用node讀取excel文件&#xff0c;遍歷sheets&#xff0c;給單元格設置顏色等操作&#xff0c;希望對大家接活有所幫助。 gen.js let dir"D:\\武漢煙廠\\山東區域\\備檔資料\\銷區零售終端APP維護清單\\走訪檔案\\2024年6月…

Spring之事務失效的場景

Spring事務失效的場景 異常捕獲處理&#xff1a;自己處理了異常&#xff0c;沒有拋出。解決&#xff1a;手動拋出拋出檢查異常&#xff1a;配置rollbackFor屬性為Excetion非public方法導致事務失效&#xff0c;改為public 1、異常捕獲處理 示例&#xff1a; 張三1000元&#…

7月形勢分析-您下一步該如何做,才能走出困境?

馬上工程項目&#xff0c;再有三五天就要結束的了。即便推后也不會超過一周時間了。所以需要考慮將來干啥呢&#xff1f;  一方面就是繼續去濟寧做建筑工程的活。管吃住&#xff0c;但是因為至親之間&#xff0c;難免咋說呢&#xff0c;總之還是不太舒服的樣子。管事情多&…

bigNumber的部分使用方法與屬性

場景&#xff1a;最近做IoT項目的時候碰到一個問題&#xff0c;涉及到雙精度浮點型的數據范圍的校驗問題。業務上其實有三種類型&#xff1a;int、float和double類型三種。他們的范圍分別是&#xff1a; //int int: [-2147483648, 2147483647],//float float: [-3402823466385…

PHP7源碼結構

PHP7程序的執行過程 1.PHP代碼經過詞法分析轉換為有意義的Token&#xff1b; 2.Token經過語法分析生成AST&#xff08;Abstract Synstract Syntax Tree&#xff0c;抽象語法樹&#xff09;&#xff1b; 3.AST生成對應的opcode&#xff0c;被虛擬機執行。 源碼結構&#xff1…