Samples_Event explorer_watch properties注释解读研究

2024-02-24 17:38

本文主要是介绍Samples_Event explorer_watch properties注释解读研究,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这个例子可以学习事件和属性,挺有意思的,故格了这个程序一个礼拜了,大概明白了一点,全端出来共享一下了

<html><head><meta charset="utf-8" /><meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /><title>Event explorer / watch properties | Sample | ArcGIS API for JavaScript 4.19</title><link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" /><script src="https://js.arcgis.com/4.19/"></script><script>require(["esri/Map", "esri/views/SceneView"], (Map, SceneView) => {const map = new Map({basemap: "topo-vector",ground: "world-elevation"});const view = new SceneView({container: "viewDiv",map: map,qualityMode: "high",camera: {position: [-101.17, 20.76793656, 12908164.47184],heading: 0.0,tilt: 0.5}});//此处添加了——arr表明这是个数组,下面的属性也是一样const events_arr = ["pointer-enter","pointer-leave","pointer-move","pointer-down","pointer-up","immediate-click","click","immediate-double-click","double-click","mouse-wheel","drag","hold","key-down","key-up","focus","blur","resize"];// for the purpose of the sample, this is only a selection of properties,为了达到演示的目的,这只是属性的一小部分,// but any properties on the View can be watched for 但是任何View的属性均可以被观察被watch for //个人添加了_arr表明这是个数组const properties_arr = ["focused","interacting","updating","resolution","scale","zoom","stationary","camera.position.z","camera.tilt","camera.heading"];// Dynamically create the table of events and properties from the defined array//从预定义好的数组中动态地创建事件表和属性表function createTables() {const eventsTable = document.getElementById("events");//得到右上角的events的元素console.log("get events_node:"+eventsTable);let content = eventsTable.innerHTML;//让内容等于元素的innerHTMLconsole.log("get events_node_innerhtml :"+content);//循环events_arr这个数组,为这个content赋值,每一个事件条目都是div 记住这个。for (let i = 0; i < events_arr.length; i++) {//创建了一个div 元素,class 为 event,id依此为数组中的各个单个值,pointer-enter,pointer-leave......//用这种方式也创建了新的元素,创建了新的元素content += '<div class="event" id="' + events_arr[i] + '">' +"I am "+ events_arr[i];content += "</div>";console.log(i+"of"+events_arr.length+"event is created in the for loops:"+content);}eventsTable.innerHTML = content;//让events元素的innerHTML等于content,不懂为啥又来了这么一句,因为前面有content=eventsTable.innerHTMLconsole.log("after eventTable_innerHTML equal console_content:"+content);//上面是event即事件的区域,下面的是properties即属性的区域const propertiesTable = document.getElementById("properties");console.log("after const propertyTable:"+propertiesTable);//这个content还是上面声明过的那个contentcontent = propertiesTable.innerHTML;console.log("after let content equal propertiesTable_innerHTML:"+content);for (let i = 0; i < properties_arr.length; i++) {//创建了一个div 元素,class为property,id依此为属性数组中的各个单个值,如focused,interacting......//用这种方式也创建了新的元素,创建了新的元素content += '<div class="property" id="' + properties_arr[i] + '">' + "I am "+ properties_arr[i] + " = </div>";console.log(i+"of"+properties_arr.length+"properties is created in the for loops:"+content);}propertiesTable.innerHTML = content;console.log("after property_innerHTML equal console_content:"+content);}//函数:建立Event的监听器,name是某个元素的id,注意:同时它也是一个事件名哦,可以用于xxx.on(name,func)这种情况下的哦。function setupEventListener(view, name) {const eventRow = document.getElementById(name);console.log(eventRow);view.on(name, (value) => {eventRow.className = "event active";//元素的className为:event active ,active之后就变得是实心的字了,inactive的时候是灰色的console.log(name);//往控制台输出这个eventif (eventRow.highlightTimeout) {clearTimeout(eventRow.highlightTimeout);}eventRow.highlightTimeout = setTimeout(() => {// after a timeout of one second disable the highlight//过了timeout的秒数了,就使得高亮不能用eventRow.className = "event inactive";}, 1000);});}function setupPropertiesListener(view, name) {const propertiesRow = document.getElementById(name);view.watch(name, (value) => {propertiesRow.className = "property active";propertiesRow.innerHTML = propertiesRow.innerHTML.substring(0, propertiesRow.innerHTML.indexOf(" = "));console.log(name);//往控制台输出这个property// set the text to the received valueconst formattedValue = typeof value === "number" ? value.toFixed(4) : value;propertiesRow.innerHTML += " = " + formattedValue.toString();if (propertiesRow.highlightTimeout) {clearTimeout(propertiesRow.highlightTimeout);}propertiesRow.highlightTimeout = setTimeout(() => {// after a timeout of one second disable the highlightpropertiesRow.className = "property inactive";}, 1000);});}// create the tables for the events and properties//调用createTables(),创建eventtable和propertytablecreateTables();// Setup all view events defined in the array//为数组中的那些事件来分配响应函数for (let i = 0; i < events_arr.length; i++) {setupEventListener(view, events_arr[i]);}// Setup all watch properties defined in the array//为数组中的那些属性创建响应函数for (let i = 0; i < properties_arr.length; i++) {setupPropertiesListener(view, properties_arr[i]);}});</script><style>html,body {padding: 0;margin: 0;height: 100%;width: 100%;}#viewDiv {position: absolute;left: 0;right: 250px;top: 0;bottom: 0;height: 100%;}#panel {background-color: #f5f5f5;position: absolute;right: 0;height: 100%;width: 250px;font-size: 12px;}.title {font-weight: bold;color: #0079c1;}.container {background-color: white;color: #323232;margin: 10px;padding: 5px;border-bottom: 1px solid rgba(50, 50, 50, 0.25);}.event,.property {transition: background-color 0.5s ease-out;padding-bottom: 2px;opacity: 0.2;}.active {opacity: 1;background-color: #f30909;}.inactive {opacity: 1;background-color: white;}</style></head><body><div id="main"><div id="viewDiv"></div><div id="panel" class="esri-widget"><div id="events" class="container"><aclass="title"href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-View.html#events-summary"target="_blank">Class View Events:</a></div><div id="properties" class="container"><aclass="title"href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-View.html#properties-summary"target="_blank">Class View Properties:</a></div></div></div></body>
</html>

 

这篇关于Samples_Event explorer_watch properties注释解读研究的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/742845

相关文章

解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题

《解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题》在Spring开发中,@Autowired注解常用于实现依赖注入,它可以应用于类的属性、构造器或setter方法上,然... 目录1. 为什么 @Autowired 在属性上被警告?1.1 隐式依赖注入1.2 IDE 的警告:

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

解读Pandas和Polars的区别及说明

《解读Pandas和Polars的区别及说明》Pandas和Polars是Python中用于数据处理的两个库,Pandas适用于中小规模数据的快速原型开发和复杂数据操作,而Polars则专注于高效数据... 目录Pandas vs Polars 对比表使用场景对比Pandas 的使用场景Polars 的使用

Rust中的Drop特性之解读自动化资源清理的魔法

《Rust中的Drop特性之解读自动化资源清理的魔法》Rust通过Drop特性实现了自动清理机制,确保资源在对象超出作用域时自动释放,避免了手动管理资源时可能出现的内存泄漏或双重释放问题,智能指针如B... 目录自动清理机制:Rust 的析构函数提前释放资源:std::mem::drop android的妙

golang字符串匹配算法解读

《golang字符串匹配算法解读》文章介绍了字符串匹配算法的原理,特别是Knuth-Morris-Pratt(KMP)算法,该算法通过构建模式串的前缀表来减少匹配时的不必要的字符比较,从而提高效率,在... 目录简介KMP实现代码总结简介字符串匹配算法主要用于在一个较长的文本串中查找一个较短的字符串(称为

使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

MySQL中的MVCC底层原理解读

《MySQL中的MVCC底层原理解读》本文详细介绍了MySQL中的多版本并发控制(MVCC)机制,包括版本链、ReadView以及在不同事务隔离级别下MVCC的工作原理,通过一个具体的示例演示了在可重... 目录简介ReadView版本链演示过程总结简介MVCC(Multi-Version Concurr

关于Gateway路由匹配规则解读

《关于Gateway路由匹配规则解读》本文详细介绍了SpringCloudGateway的路由匹配规则,包括基本概念、常用属性、实际应用以及注意事项,路由匹配规则决定了请求如何被转发到目标服务,是Ga... 目录Gateway路由匹配规则一、基本概念二、常用属性三、实际应用四、注意事项总结Gateway路由

解读Redis秒杀优化方案(阻塞队列+基于Stream流的消息队列)

《解读Redis秒杀优化方案(阻塞队列+基于Stream流的消息队列)》该文章介绍了使用Redis的阻塞队列和Stream流的消息队列来优化秒杀系统的方案,通过将秒杀流程拆分为两条流水线,使用Redi... 目录Redis秒杀优化方案(阻塞队列+Stream流的消息队列)什么是消息队列?消费者组的工作方式每

解读静态资源访问static-locations和static-path-pattern

《解读静态资源访问static-locations和static-path-pattern》本文主要介绍了SpringBoot中静态资源的配置和访问方式,包括静态资源的默认前缀、默认地址、目录结构、访... 目录静态资源访问static-locations和static-path-pattern静态资源配置