06-ArcGIS For JavaScript-requestAnimationFrame动画渲染

news/2024/10/19 12:31:38/

文章目录

    • 概述
    • setInterval()与setTimeout()
    • requestAnimationFrame()
    • requestAnimationFrame在ArcGIS For JavaScript的应用
    • 结果

概述

本节主要讲解与时间相关的三个方法setTimeout()、setInterval()和requestAnimationFrame(),这三个方法都属于浏览器的window对象的方法,这三个函数能够更好的服务于2Dcanvas动画、WebGL动画等方面。

setInterval()与setTimeout()

setInterval()函数为周期定时器,可以选择每过一个固定时间段调用一次指定函数。如下,每100毫秒调用一次回调函数:

javascript">setInterval(function(){console.log("It is setInterval");
}, 100);

setTimeout()为倒计时定时器,例如可以指定100毫秒后调用回调函数,然后结束当前定时。

javascript">setTimeout(function(){console.log("It is setTimeout");
}, 100);

这两个方法都是可以人为的指定回调函数被调用的时间。
如果不想使用该定时器的时候,可以选择取消。方法如下:

javascript">clearInterval();  //取消setInterval()设置的定时
clearTimeout();  //取消setTimeout()设置的定时器

requestAnimationFrame()

requestAnimationFrame主要用途是按帧对网页进行重绘,让各种网页动画效果(DOM动画、Canvas动画、SVG动画、WebGL动画)能够有一个统一的刷新机制,从而节省系统资源,提高系统性能,改善视觉效果。

调用方式如下:

javascript">function callback(){console.log(requestAnimationFrame)requestAnimationFrame(callback)
}
requestAnimationFrame(callback)

requestAnimationFrame在ArcGIS For JavaScript的应用

javascript"><!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /><script src="https://js.arcgis.com/4.30/"></script><style>html,body,#viewDiv {margin: 0;padding: 0;height: 100%;width: 100%;}</style><script>require(["esri/geometry/Mesh","esri/views/SceneView","esri/Map","esri/Graphic","esri/symbols/MeshSymbol3D","esri/symbols/FillSymbol3DLayer","esri/geometry/Point","esri/core/reactiveUtils"], (Mesh, SceneView, Map, Graphic, MeshSymbol3D, FillSymbol3DLayer, Point, reactiveUtils) => {let waterHeight = 422;async function createMeshGLTF(glbUrl, point, i = [0, 0, 0], r = 1, n = 0) {const s = await Mesh.createFromGLTF(point, glbUrl, {vertexSpace: "georeferenced"}), o = i.map(h => h * r);return s.scale(r),s.offset(o[0], o[1], o[2]),s.rotate(0, 0, n),new Graphic({geometry: s,symbol: new MeshSymbol3D({symbolLayers: [new FillSymbol3DLayer]})})}let map = new Map({basemap: 'satellite'})let view = new SceneView({container: "viewDiv",map})let animatingPinpoint = true;view.when(async function () {let sailBoat = await createMeshGLTF("./pinpoint.glb", new Point({x: -1354454634895185e-8,y: 4307521548889681e-9,z: waterHeight,spatialReference: {wkid: 102100}}));view.graphics.add(sailBoat);view.extent = sailBoat.geometry.extent;function setupCameraHeadingListener() {reactiveUtils.watch(() => Math.round(view.camera.heading), e => {const i = sailBoat.geometry;i.transform.rotationAngle = -e + 20,i.transform.rotationAxis = [0, 0, 1]}, {initial: !0})}let startTime = Date.now() / 1000;function animatePinpoint(graphic) {let startTime = null;animatingPinpoint = true;const animate = (elapsedTime) => {if (!startTime) {startTime = elapsedTime;}const timeDif = (elapsedTime - startTime) / 1000;const scale = 1 + Math.abs(Math.sin(timeDif * 2));const geometry = graphic.geometry;geometry.transform ??= new MeshTransform();geometry.transform.scale = [scale, scale, scale];if (animatingPinpoint) {requestAnimationFrame(animate);}}requestAnimationFrame(animate);}function stopAnimatingPinpoint() {animatingPinpoint = false;}animatePinpoint(sailBoat);setupCameraHeadingListener();})})</script>
</head><body><div id="viewDiv"></div>
</body></html>

结果

在这里插入图片描述


http://www.ppmy.cn/news/1540252.html

相关文章

【pyspark学习从入门到精通4】弹性分布式数据集_2

目录 Lambda 表达式 全局作用域与局部作用域 Transformations .map(...) 转换 .filter(...) 转换 .flatMap(...) 转换 .distinct(...) 转换 .sample(...) 转换 .leftOuterJoin(...) 转换 .repartition(...) 转换 Lambda 表达式 在这个例子中&#xff0c;我们将从 dat…

系统架构设计师教程 第18章 18.6 数据库系统的安全设计 笔记

18.6 数据库系统的安全设计 从数据库管理系统的 角度而言&#xff0c;要采取的安全策略一般为用户管理、存取控制、数据加密、审计跟踪和攻击检测。 18.6.1 数据库安全设计的评估标准 可信计算机系统评估标准 (Trusted Computer System Evaluation Criteria,TCSEC) 桔皮书 (…

Linux系统层面问题总结

一、Linux系统层面 系统故障排查关注 应用日志查询&#xff1a; tailf /var/log/messages登录日志查询&#xff1a; tailf /var/log/secure系统日志查询&#xff1a; dmesg容易攻击点查询 &#xff1a;/var/tmp /tmp计划任务查询&#xff08;经常攻击对象&#xff09;&#xf…

C++算法练习-day7——707.设计链表

题目来源&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 题目思路分析 在编程中&#xff0c;链表是一种常见的数据结构&#xff0c;用于存储一系列元素&#xff0c;但与数组不同&#xff0c;链表中的元素在内存中不必连续存储。每个元素&#xff08;称为节点&#xf…

MatrixOne助力江铜集团打造炉前智慧作业AIoT大数据系统

客户简介 江西铜业集团有限公司是世界500强企业&#xff0c;同时也是中国最大的铜生产商之一&#xff0c;成立于1979年&#xff0c;总部位于江西省南昌市。 公司专注于铜及其相关产品的开采、冶炼和加工&#xff0c;业务覆盖矿产资源开发、冶炼加工、产品制造和国际贸易等领域…

实践笔记 - 微服务架构下RESTful风格api之我为何抛弃了路由参数

在如今关于 RESTful API 的实践中&#xff0c;许多设计示例经常遵循类似以下的动态路径方案&#xff1a; 方案一&#xff1a;动态路径 方法路径描述GET/zoos列出所有的动物园POST/zoos新增一个新的动物园GET/zoos/{zoo}获取指定动物园详情PUT/zoos/{zoo}更新指定动物园DELETE…

Threejs 实现3D 地图(01)创建基本场景

"d3": "^7.9.0", "three": "^0.169.0", "vue": "^3.5.10" <script setup> import { onMounted,ref } from vue import * as THREE from three import * as d3 from "d3"; //莫开托坐标 矫正地图…

mysql学习教程,从入门到精通,SQL 约束(Constraints)(41)

在数据库设计中&#xff0c;约束&#xff08;Constraints&#xff09;用于确保数据的准确性和完整性。它们通过限制可以插入到数据库表中的数据类型来防止无效数据。SQL 中有几种常见的约束类型&#xff0c;包括主键约束&#xff08;Primary Key&#xff09;、外键约束&#xf…