当前位置: 首页 > news >正文

vue3-openlayers marker 光晕扩散(光环扩散)(postrender 事件和 render 方法)

本篇介绍一下使用 vue3-openlayers marker 光晕扩散(光环扩散)(postrender 事件和 render 方法)

1 需求

  • marker 光晕扩散(光环扩散)

2 分析

marker 光晕扩散(光环扩散)使用 postrender 事件和 render 方法
关于即时渲染的知识点请看上篇《openlayers marker 光晕扩散(光环扩散)(postrender 事件和 render 方法)》

3 实现

<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>
http://www.lryc.cn/news/383089.html

相关文章:

  • 新型防勒索病毒方案分享无需依靠病毒库
  • 《Mybatis-Plus》系列文章目录
  • 在Matplotlib中,`xlim()` 函数用于设置x轴的显示范围,原因和作用如下:
  • win7使用vue-cli创建vue3工程
  • 为何云原生是未来?企业IT架构的颠覆与重构
  • 构建家庭NAS之三:在TrueNAS SCALE上安装qBittorrent
  • Matplotlib中文显示解决方案:字体渲染机制与font.sans-serif设置
  • docker +tmux 远程本地gdb调试
  • 计算机视觉全系列实战教程 (十三):图像形态学操作
  • python的 pyside2 安装
  • R语言——数据与运算
  • 非强化学习的对齐方法
  • 写一个坏越的个人天地(三)
  • 【学习笔记】CSS
  • 与亚马逊云科技深度合作,再获WAPP、ISV认证
  • idea 如何查看项目启动的端口号
  • 年薪超过30万的网工,需要具备什么技能?
  • 【杂记-浅谈OSPF协议中的邻居关系与邻接关系】
  • 白银价格行情分析兼顾基本面和技术面
  • 搜维尔科技推出绿幕抠屏虚拟制作演示项目
  • 大数据集群搭建基础:Linux下MySQL安装!!!
  • FLASH闪存
  • GPT-5智能新纪元的曙光
  • Qt | QPalette 类(调色版)
  • Linux操作系统进程同步的几种方式及基本原理
  • android 责任链模式
  • 【可控图像生成系列论文(四)】IP-Adapter 具体是如何训练的?1公式篇
  • 堆的实现详解
  • iptables配置NAT实现端口转发
  • 【启明智显产品介绍】Model3C工业级HMI芯片详解专题(一)芯片性能