当前位置:网站首页>OpenLayers实例-Animated GIF-GIF动画
OpenLayers实例-Animated GIF-GIF动画
2022-07-23 20:04:00 【GISer小辉】
Animated GIF-GIF动画
知识要点
- (主要)使用GIF动画作为图标进行可视化,官方推荐借助Gifler库实现。
- (次要)map.on(‘pointermove’, function (e) {});可以改变鼠标经过gif图标时的光标样式,详见源码。
官网原文及译文
Example of using an animated GIF as an icon. Animation is achieved using the Gifler library.
使用GIF动画作为图标的例子。动画是使用Gifler库实现的。
源码
<!DOCTYPE html>
<html lang="zn">
<head>
<meta charset="UTF-8">
<!-- 引入OpenLayers CSS样式 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/[email protected]/en/v6.13.0/css/ol.css"
type="text/css">
<!-- 引入OpenLayers JS库 -->
<script src="https://cdn.jsdelivr.net/gh/openlayers/[email protected]/en/v6.13.0/build/ol.js"></script>
<!-- 引入Gifler JS库 -->
<script src="https://unpkg.com/[email protected]/gifler.min.js"></script>
<!-- css代码 -->
<style>
.map {
width: 100%;
height: 400px;
}
</style>
<title>Animated GIF GIF动画</title>
</head>
<body>
<!-- html代码 -->
<div id="map" class="map"></div>
<!-- script代码 -->
<script>
// 定义一个点
const iconFeature = new ol.Feature({
geometry: new ol.geom.Point([0, 0]),
});
// 定义一个点的矢量资源
const vectorSource = new ol.source.Vector({
features: [iconFeature],
});
// 定义一个点的矢量图层
const vectorLayer = new ol.layer.Vector({
source: vectorSource,
});
// 定义光栅图层
const rasterLayer = new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'toner',
}),
});
// 初始化地图
const map = new ol.Map({
// 将光栅图层、一个点的矢量图层添加到地图中
layers: [rasterLayer, vectorLayer],
// 绑定页面元素
target: document.getElementById('map'),
// 设置视图
view: new ol.View({
center: [0, 0],
zoom: 2,
}),
});
// gif动图的url的链接
const gifUrl = 'https://openlayers.org/en/latest/examples/data/globe.gif';
// 使用Gifler将链接转化为gif图片
const gif = gifler(gifUrl);
// gif图片按刷新
gif.frames(
document.createElement('canvas'),
function (ctx, frame) {
if (!iconFeature.getStyle()) {
iconFeature.setStyle(
new ol.style.Style({
image: new ol.style.Icon({
img: ctx.canvas,
imgSize: [frame.width, frame.height],
opacity: 0.8,
}),
})
);
}
ctx.clearRect(0, 0, frame.width, frame.height);
ctx.drawImage(frame.buffer, frame.x, frame.y);
map.render();
},
true
);
// 改变鼠标经过gif图标时的光标样式为pointer
map.on('pointermove', function (e) {
const pixel = map.getEventPixel(e.originalEvent);
const hit = map.hasFeatureAtPixel(pixel);
map.getTarget().style.cursor = hit ? 'pointer' : '';
});
</script>
</body>
</html>
效果截图

边栏推荐
- Lyscript plug-in command return encapsulation
- 【力扣】三数之和
- Mysql的前世今生,Hello,Mysql
- Adobe Acrobat two powerful plug-ins
- Solve the problem that the user clicks quickly and repeats the request within 1 second
- 游戏服务器中的排行榜设计
- JDK安装包和Mysql安装包整理
- 网上开通证券账户安全吗?
- New product listing | A-share floor derivatives market point
- task03笔记2
猜你喜欢

Parity rearrangement of Bm14 linked list

dokcer镜像理解

如何在OneFlow中新增算子

next数值型数据类型()出现输入错误后,下次依然能正常输入

Lyscript plug-in command return encapsulation
![[untitled]](/img/2f/cfac9dcac7466cf3ac5601b0fadf03.png)
[untitled]

剑指 Offer II 115. 重建序列

How to solve the problem that the solid state disk cannot be found when installing win11?
![[ar learning] - II. Environment construction](/img/e8/c20de6a46ef70b6eb49684d685e4cd.png)
[ar learning] - II. Environment construction

How to add to-do items for win11 widgets? Win11 method of adding to-do widget
随机推荐
Drools(1):Drools简介
Baidu map data visualization
平安证券低佣金开户链接安全吗,怎么办理低佣金
LyScriptTools 扩展Script模块
数组——977. 有序数组的平方
Is the link of Huatai Securities' low commission account opening safe? How to handle low commission
Yiwen teaches you how to install MySQL
实践数据湖iceberg 第三十七课 kakfa写入iceberg的 icberg表的 enfource ,not enfource测试
Leetcode 238. product of arrays other than itself
数组——704. 二分查找
Failure after reinstalling the system (error: Reboot and select proper boot device or insert boot media in selected boot device)
[ar learning] - II. Environment construction
task03笔记2
Leetcode 209. subarray with the smallest length
When using polymorphism, two ideas to judge whether it can be transformed downward
ant接口用什么天线_电视后面有个接口写的是 标准ANT 75 欧输入,请问是什么意思,是天线吗?可不可以接闭路线啊?…「建议收藏」
小程序頭像組樣式
【pdd面试】分析手机中的应用(相机)的活跃情况
Relevant interfaces of [asp.net core] option mode
scanf()和getchar()的用法讨论