当前位置:网站首页>openlayers 好玩的效果之流动线
openlayers 好玩的效果之流动线
2022-08-06 05:24:00 【Giser_往事随风】
老规矩先看效果图

使用的是vue + openlayers
思路:加载一个线的geojson 数据,实例化geojsonLayer 加载到地图上,拿到图层的features ,将feature 的style stroke 中的 lineDashoffset 定时改变即可
部分核心代码:(不好意思哈各位,只能上部分核心代码了,完整的vue 页面和示例数据,我放到资源中心去下载,最近囊中羞涩,积分严重不足,赚点积分)
geojsonLayer.getSource().on('featuresloadend',evt=>{
geojsonLayer.getSource().getFeatures().forEach(item=>{
setInterval(()=>{
let style = item.getStyle();
if(style == undefined){
item.setStyle(
[new Style({
stroke: new Stroke({
color: "rgba(30,144,255, 0.7)",
width: 2,
})
}),
new Style({
stroke:new Stroke({
color: [255, 250, 250, 1],
width: 2,
lineDash: [20, 27],
lineDashOffset:0
})
})]
)
}else {
let lineDashOffset = item.getStyle()[1].getStroke().getLineDashOffset();
item.setStyle(
[new Style({
stroke: new Stroke({
color: "rgba(30,144,255, 0.7)",
width: 2,
})
}),
new Style({
stroke:new Stroke({
color: [255, 250, 250, 1],
width: 2,
lineDash: [2, 7],
lineDashOffset:lineDashOffset==8 ?0:lineDashOffset+1
})
})]
)
}
},100)
})
})其中拿取到的feature 是没有style 的,然后给他设置的style ,所以多判断了一个,如果你刚开始创建的feature 加载到图层就可以省略这个判断。
边栏推荐
猜你喜欢

大型跨国公司如何“躺赢”IT趋势挑战

《Gartner 2022年网络防火墙关键能力报告》发布,Fortinet获得三大用例最高得分

对象存储布局,对象如何定位,对象如何分配

Docker 快速安装&搭建 Mysql 环境

高危漏洞预警 | Atlassian Confluence OGNL注入命令执行漏洞复现与分析报告

LVS 引入keepalived自动切换机制

Distributed, Microservices, Cluster Concepts and Differences

揭示OT安全四大挑战!Fortinet 发布《2022年全球运营技术和网络安全态势报告》

Difference between ordinary factory class and abstract factory class

MySql data table structure optimization summary
随机推荐
字节流:InputStream:读文件、OutputStream:写文件
Kindle接入HomeAssistant:实现锁屏壁纸显示HA内设备信息并在HA内获取Kindle电量
勒索软件攻击防御的9件事
二叉搜索树BST
mysql数据库
高危漏洞预警 | Atlassian Confluence OGNL注入命令执行漏洞复现与分析报告
谷歌浏览器反复提示PageOffice安装
MySQL optimization query details and index optimization examples
LVS负载均衡服务器搭建
MySql 数据表结构优化总结
学好shell条件判断处事果断
集合应用,展示学生信息
线程的六种状态
ZTNA方案守住随时随地办公的安全防线
Serial USART and UART
How to jailbreak the Kindle series 5.12.2.2 ~ 5.14.2 without disassembly?How to install third-party plugins
arcgis js 4.18新体验:阴影滤镜图层
学好免交互expect解放双手
Build your own V Rising self-built server, and solutions to common V Rising server problems
软件测试基本概念知识