源码分析之Openlayers中的Attribution属性控件
概述
本文主要介绍 Openlayers 中Attribution属性控件的源码实现,该控件也是 Openlayers 中三个默认控件之一。默认情况下,控件会显示在地图的右下角,可以通过控件的类名设置CSS属性控制。实际应用中该控件主要显示与图层源source相关的所有属性,一般用来显示版权说明等等。
源码分析
Attribution控件继承自Control类,关于Control类,可以参考这篇文章源码分析之Openlayers中的控件篇Control基类介绍
Attribution类控件源码实现如下
class Attribution extends Control {constructor(options) {options = options ? options : {};super({element: document.createElement("div"),render: options.render,target: options.target,});this.ulElement_ = document.createElement("ul");this.collapsed_ =options.collapsed !== undefined ? options.collapsed : true;this.userCollapsed_ = this.collapsed_;this.overrideCollapsible_ = options.collapsible !== undefined;this.collapsible_ =options.collapsible !== undefined ? options.collapsible : true;if (!this.collapsible_) {this.collapsed_ = false;}this.attributions_ = options.attributions;const className =options.className !== undefined ? options.className : "ol-attribution";const tipLabel =options.tipLabel !== undefined ? options.tipLabel : "Attributions";const expandClassName =options.expandClassName !== undefined? options.expandClassName: className + "-expand";const collapseLabel =options.collapseLabel !== undefined ? options.collapseLabel : "\u203A";const collapseClassName =options.collapseClassName !== undefined? options.collapseClassName: className + "-collapse";if (typeof collapseLabel === "string") {this.collapseLabel_ = document.createElement("span");this.collapseLabel_.textContent = collapseLabel;this.collapseLabel_.className = collapseClassName;} else {this.collapseLabel_ = collapseLabel;}const label = options.label !== undefined ? options.label : "i";if (typeof label === "string") {this.label_ = document.createElement("span");this.label_.textContent = label;this.label_.className = expandClassName;} else {this.label_ = label;}const activeLabel =this.collapsible_ && !this.collapsed_ ? this.collapseLabel_ : this.label_;this.toggleButton_ = document.createElement("button");this.toggleButton_.setAttribute("type", "button");this.toggleButton_.setAttribute("aria-expanded", String(!this.collapsed_));this.toggleButton_.title = tipLabel;this.toggleButton_.appendChild(activeLabel);this.toggleButton_.addEventListener(EventType.CLICK,this.handleClick_.bind(this),false);const cssClasses =className +" " +CLASS_UNSELECTABLE +" " +CLASS_CONTROL +(this.collapsed_ && this.collapsible_ ? " " + CLASS_COLLAPSED : "") +(this.collapsible_ ? "" : " ol-uncollapsible");const element = this.element;element.className = cssClasses;element.appendChild(this.toggleButton_);element.appendChild(this.ulElement_);this.renderedAttributions_ = [];this.renderedVisible_ = true;}collectSourceAttributions_(frameState) {const layers = this.getMap().getAllLayers();const visibleAttributions = new Set(layers.flatMap((layer) => layer.getAttributions(frameState)));if (this.attributions_ !== undefined) {Array.isArray(this.attributions_)? this.attributions_.forEach((item) => visibleAttributions.add(item)): visibleAttributions.add(this.attributions_);}if (!this.overrideCollapsible_) {const collapsible = !layers.some((layer) => layer.getSource()?.getAttributionsCollapsible() === false);this.setCollapsible(collapsible);}return Array.from(visibleAttributions);}async updateElement_(frameState) {if (!frameState) {if (this.renderedVisible_) {this.element.style.display = "none";this.renderedVisible_ = false;}return;}const attributions = await Promise.all(this.collectSourceAttributions_(frameState).map((attribution) =>toPromise(() => attribution)));const visible = attributions.length > 0;if (this.renderedVisible_ != visible) {this.element.style.display = visible ? "" : "none";this.renderedVisible_ = visible;}if (equals(attributions, this.renderedAttributions_)) {return;}removeChildren(this.ulElement_);// append the attributionsfor (let i = 0, ii = attributions.length; i < ii; ++i) {const element = document.createElement("li");element.innerHTML = attributions[i];this.ulElement_.appendChild(element);}this.renderedAttributions_ = attributions;}handleClick_(event) {event.preventDefault();this.handleToggle_();this.userCollapsed_ = this.collapsed_;}handleToggle_() {this.element.classList.toggle(CLASS_COLLAPSED);if (this.collapsed_) {replaceNode(this.collapseLabel_, this.label_);} else {replaceNode(this.label_, this.collapseLabel_);}this.collapsed_ = !this.collapsed_;this.toggleButton_.setAttribute("aria-expanded", String(!this.collapsed_));}getCollapsible() {return this.collapsible_;}setCollapsible(collapsible) {if (this.collapsible_ === collapsible) {return;}this.collapsible_ = collapsible;this.element.classList.toggle("ol-uncollapsible");if (this.userCollapsed_) {this.handleToggle_();}}setCollapsed(collapsed) {this.userCollapsed_ = collapsed;if (!this.collapsible_ || this.collapsed_ === collapsed) {return;}this.handleToggle_();}getCollapsed() {return this.collapsed_;}render(mapEvent) {this.updateElement_(mapEvent.frameState);}
}
Attribution控件的主要方法
关于Attribution控件主要介绍它的两个方法,如下
collectSourceAttributions_方法
collectSourceAttributions_方法顾名思义就是获取图层源的属性作为一个集合;该方法内部先调用getMap().getAllLayers()方法获取所有图层,然后遍历图层获取图层源的属性信息;判断,若this.attributions_存在,则根据它的类型将其添加到visibleAttributions中;判断,若this.overrideCollapsible_为false,则获取图层源属性折叠信息,调用setCollapsible方法
updateElement_方法
updateElement_方法在控件的render方法中调用,本质上就是获取属性信息,更新信息。
总结
本文主要介绍了 Openlayers 中的Attribution属性控件,这个控件的非核心部分就是点击元素折叠显示,详见上面源码即可;另,核心部分就是collectSourceAttributions_方法,获取图层源的信息,这是基于Layer类和Source类实现的,关于这两个 Openlayers 的核心类,可以参考后面的文章。
相关文章:
源码分析之Openlayers中的Attribution属性控件
概述 本文主要介绍 Openlayers 中Attribution属性控件的源码实现,该控件也是 Openlayers 中三个默认控件之一。默认情况下,控件会显示在地图的右下角,可以通过控件的类名设置CSS属性控制。实际应用中该控件主要显示与图层源source相关的所有…...
Shell自定义(二)
1.Shell自定义 1.初始化 定义全局变量environ,把g_env的内容用memset初始化为0,这里用malloc开辟的空间为对应环境变量的长度1,多1位置是最后结束符0,strcpy把此时的对应的环境变量拷贝到g_env里面,下面是新增一个环…...
自然语言处理:我的学习心得与笔记
Pytorch 1.Pytorch基本语法 1.1 认识Pytorch 1.2 Pytorch中的autograd 2.Pytorch初步应用 2.1 使用Pytorch构建一个神经网络 2.2 使用Pytorch构建一个分类器 小节总结 学习了什么是Pytorch. 。Pytorch是一个基于Numpy的科学计算包,作为Numpy的替代者,向用户提供使用GPU强大…...
Oracle 中什么情况下 可以使用 EXISTS 替代 IN 提高查询效率
为什么 EXISTS 更高效? EXISTS 提前终止: EXISTS 一旦在子查询中找到第一个匹配项,就会立即返回 TRUE,不再继续扫描子查询中的其他记录。IN 必须扫描整个子查询的结果集,将所有结果与主查询的每一行进行对比。大数据集…...
Spring基础分析08-集成JPA/Hibernate进行ORM操作
大家好,今天和大家一起分享一下Spring集成JPAHibernate进行ORM操作的流程~ JPA(Java Persistence API)作为Java EE标准的一部分,提供了统一的API来管理实体类和持久化上下文;Hibernate则是最流行的JPA实现之一&#x…...
MySQL知识汇总(一)
一些命令行操作注意加 分号 “ ; ” show databases 查看所有数据库 use 数据库名 切换数据库 show tables 查看数据库中所有表 describe 表名 显示表中所有信息 create database [if not exists] 新库名 创…...
PDFMathTranslate 一个基于AI优秀的PDF论文翻译工具
PDFMathTranslate 是一个设想中的工具,旨在翻译PDF文档中的数学内容。以下是这个工具的主要特点和使用方法: 链接:https://www.modelscope.cn/studios/AI-ModelScope/PDFMathTranslate 功能特点 数学公式识别:利用先进的OCR&…...
React+Vite从零搭建项目及配置详解
相信很多React初学者第一次搭建自己的项目,搭建时会无从下手,本篇适合快速实现功能,熟悉React项目搭建流程。 目录 一、创建项目react-item 二、调整项目目录结构 三、使用scss预处理器 四、组件库Ant Design 五、配置基础路由 六、配置…...
@pytest.fixture() 跟 @pytest.fixture有区别吗?
在iOS UI 自动化工程里面最早我用的是pytest.fixture(),因为在pycharm中联想出来的fixture是带()的,后来偶然一次我没有带()发现也没有问题,于是详细查了一下pytest.fixture() 和 pytest.fixtur…...
Google Cloud Architect 认证考试错题集5
Google Cloud Architect 认证考试错题集5 D. Store static content such as HTML and images in a Cloud Storage bucket. Use Cloud Functions to host the APIs and save the user data in Firestore. - Storing static content in a Cloud Storage bucket is a cost-effecti…...
【Maven】基础(一)
【Maven】基础一 1. 虽然工作有段时间了,但是深感maven了解的不深入,所以这次开始深入的学习。 课程地址: https://www.bilibili.com/video/BV1JN411G7gX?spm_id_from333.788.player.switch&vd_source240d9002f7c7e3da63cd9a975639409a&p2 1.…...
多模态抽取图片信息的 Prompt
多模态抽取图片信息的 Prompt 1. 中文版2. 日文版3. 英文原版 下面使用多模态从图片中抽取文章,表格,Flowcharts的Prompt。 1. 中文版 你是一位擅长提取图片、图表、文本并对其进行解释的专家,能够保持原始语言不变。## 指南- 针对输入内容…...
WPF 使用LibVLCSharp.WPF实现视频播放、停止、暂停功能
使用LibVLCSharp.WPF实现视频播放、停止、暂停功能 1, NuGet 添加 VideoLAN.LibVLC.Windows 2. NuGet 添加 LibVLCSharp.WPF 3. wpf 代码如下: <Grid ><Grid.RowDefinitions><RowDefinition Height"*" /><RowDefinition Height&q…...
Java全栈项目 - 校园招聘信息平台
项目介绍 校园招聘信息平台是一个面向高校学生和企业的双向服务平台。该系统帮助企业发布招聘信息,方便学生查询职位并投递简历,同时为学校就业部门提供就业数据分析功能。 技术栈 后端 Spring Boot 2.xSpring SecurityMyBatis PlusMySQL 8.0RedisRabbitMQ 前端 Vue.js 2…...
java导出
请求头获取responseimport com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet;PostMapping("excel/export") ApiOperation(value "党员档案导出", httpMethod "POST")…...
【嵌入式系统】期末试题库,ARM处理器,CortexM3内核,USART,EXTI,GPIO
关注作者了解更多 我的其他CSDN专栏 过程控制系统 工程测试技术 虚拟仪器技术 可编程控制器 工业现场总线 数字图像处理 智能控制 传感器技术 嵌入式系统 复变函数与积分变换 单片机原理 线性代数 大学物理 热工与工程流体力学 数字信号处理 光电融合集成电路…...
arcgisPro相接多个面要素转出为完整独立线要素
1、使用【面转线】工具,并取消勾选“识别和存储面邻域信息”,如下: 2、得到的线要素,如下:...
QTday1
#include "mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent) {//设置窗口标题this->setWindowTitle("向日葵远程控制");//设置窗口图标this->setWindowIcon(QIcon("C:\\Users\\Hasee\\Desktop\\pictrue\\mypicture\\logo.png&…...
SAP ALV选择列排序时弹出定义排序顺序窗口问题
需求场景 使用REUSE_ALV_GRID_DISPLAY_LVC生成ALV,发现一个问题:使用it_events的时候选择列排序时会弹出定义排序顺序窗口,如下图所示。(正常选择某一列再使用排序功能时会直接排序,不用再选择列) CLASS l…...
CSS Backgrounds(背景)
CSS Backgrounds(背景) Introduction(介绍) CSS backgrounds play a crucial role in web design, allowing developers to apply colors, images, and other decorative elements to the background of HTML elements. This enhances the visual appeal of web pages and he…...
ssc377d修改flash分区大小
1、flash的分区默认分配16M、 / # df -h Filesystem Size Used Available Use% Mounted on /dev/root 1.9M 1.9M 0 100% / /dev/mtdblock4 3.0M...
pam_env.so模块配置解析
在PAM(Pluggable Authentication Modules)配置中, /etc/pam.d/su 文件相关配置含义如下: 配置解析 auth required pam_env.so1. 字段分解 字段值说明模块类型auth认证类模块,负责验证用户身份&am…...
视频字幕质量评估的大规模细粒度基准
大家读完觉得有帮助记得关注和点赞!!! 摘要 视频字幕在文本到视频生成任务中起着至关重要的作用,因为它们的质量直接影响所生成视频的语义连贯性和视觉保真度。尽管大型视觉-语言模型(VLMs)在字幕生成方面…...
反射获取方法和属性
Java反射获取方法 在Java中,反射(Reflection)是一种强大的机制,允许程序在运行时访问和操作类的内部属性和方法。通过反射,可以动态地创建对象、调用方法、改变属性值,这在很多Java框架中如Spring和Hiberna…...
如何更改默认 Crontab 编辑器 ?
在 Linux 领域中,crontab 是您可能经常遇到的一个术语。这个实用程序在类 unix 操作系统上可用,用于调度在预定义时间和间隔自动执行的任务。这对管理员和高级用户非常有益,允许他们自动执行各种系统任务。 编辑 Crontab 文件通常使用文本编…...
省略号和可变参数模板
本文主要介绍如何展开可变参数的参数包 1.C语言的va_list展开可变参数 #include <iostream> #include <cstdarg>void printNumbers(int count, ...) {// 声明va_list类型的变量va_list args;// 使用va_start将可变参数写入变量argsva_start(args, count);for (in…...
c# 局部函数 定义、功能与示例
C# 局部函数:定义、功能与示例 1. 定义与功能 局部函数(Local Function)是嵌套在另一个方法内部的私有方法,仅在包含它的方法内可见。 • 作用:封装仅用于当前方法的逻辑,避免污染类作用域,提升…...
解析两阶段提交与三阶段提交的核心差异及MySQL实现方案
引言 在分布式系统的事务处理中,如何保障跨节点数据操作的一致性始终是核心挑战。经典的两阶段提交协议(2PC)通过准备阶段与提交阶段的协调机制,以同步决策模式确保事务原子性。其改进版本三阶段提交协议(3PC…...
Qt Quick Controls模块功能及架构
Qt Quick Controls是Qt Quick的一个附加模块,提供了一套用于构建完整用户界面的UI控件。在Qt 6.0中,这个模块经历了重大重构和改进。 一、主要功能和特点 1. 架构重构 完全重写了底层架构,与Qt Quick更紧密集成 移除了对Qt Widgets的依赖&…...
标注工具核心架构分析——主窗口的图像显示
🏗️ 标注工具核心架构分析 📋 系统概述 主要有两个核心类,采用经典的 Scene-View 架构模式: 🎯 核心类结构 1. AnnotationScene (QGraphicsScene子类) 主要负责标注场景的管理和交互 🔧 关键函数&…...
