当前位置: 首页 > news >正文

源码分析之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属性控件的源码实现&#xff0c;该控件也是 Openlayers 中三个默认控件之一。默认情况下&#xff0c;控件会显示在地图的右下角&#xff0c;可以通过控件的类名设置CSS属性控制。实际应用中该控件主要显示与图层源source相关的所有…...

Shell自定义(二)

1.Shell自定义 1.初始化 定义全局变量environ&#xff0c;把g_env的内容用memset初始化为0&#xff0c;这里用malloc开辟的空间为对应环境变量的长度1&#xff0c;多1位置是最后结束符0&#xff0c;strcpy把此时的对应的环境变量拷贝到g_env里面&#xff0c;下面是新增一个环…...

自然语言处理:我的学习心得与笔记

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 更高效&#xff1f; EXISTS 提前终止&#xff1a; EXISTS 一旦在子查询中找到第一个匹配项&#xff0c;就会立即返回 TRUE&#xff0c;不再继续扫描子查询中的其他记录。IN 必须扫描整个子查询的结果集&#xff0c;将所有结果与主查询的每一行进行对比。大数据集…...

Spring基础分析08-集成JPA/Hibernate进行ORM操作

大家好&#xff0c;今天和大家一起分享一下Spring集成JPAHibernate进行ORM操作的流程~ JPA&#xff08;Java Persistence API&#xff09;作为Java EE标准的一部分&#xff0c;提供了统一的API来管理实体类和持久化上下文&#xff1b;Hibernate则是最流行的JPA实现之一&#x…...

MySQL知识汇总(一)

一些命令行操作注意加 分号 “ ; ” show databases 查看所有数据库 use 数据库名 切换数据库 show tables 查看数据库中所有表 describe 表名 显示表中所有信息 create database [if not exists] 新库名 创…...

PDFMathTranslate 一个基于AI优秀的PDF论文翻译工具

PDFMathTranslate 是一个设想中的工具&#xff0c;旨在翻译PDF文档中的数学内容。以下是这个工具的主要特点和使用方法&#xff1a; 链接&#xff1a;https://www.modelscope.cn/studios/AI-ModelScope/PDFMathTranslate 功能特点 数学公式识别&#xff1a;利用先进的OCR&…...

React+Vite从零搭建项目及配置详解

相信很多React初学者第一次搭建自己的项目&#xff0c;搭建时会无从下手&#xff0c;本篇适合快速实现功能&#xff0c;熟悉React项目搭建流程。 目录 一、创建项目react-item 二、调整项目目录结构 三、使用scss预处理器 四、组件库Ant Design 五、配置基础路由 六、配置…...

@pytest.fixture() 跟 @pytest.fixture有区别吗?

在iOS UI 自动化工程里面最早我用的是pytest.fixture()&#xff0c;因为在pycharm中联想出来的fixture是带&#xff08;&#xff09;的&#xff0c;后来偶然一次我没有带&#xff08;&#xff09;发现也没有问题&#xff0c;于是详细查了一下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. 虽然工作有段时间了&#xff0c;但是深感maven了解的不深入&#xff0c;所以这次开始深入的学习。 课程地址: https://www.bilibili.com/video/BV1JN411G7gX?spm_id_from333.788.player.switch&vd_source240d9002f7c7e3da63cd9a975639409a&p2 1.…...

多模态抽取图片信息的 Prompt

多模态抽取图片信息的 Prompt 1. 中文版2. 日文版3. 英文原版 下面使用多模态从图片中抽取文章&#xff0c;表格&#xff0c;Flowcharts的Prompt。 1. 中文版 你是一位擅长提取图片、图表、文本并对其进行解释的专家&#xff0c;能够保持原始语言不变。## 指南- 针对输入内容…...

WPF 使用LibVLCSharp.WPF实现视频播放、停止、暂停功能

使用LibVLCSharp.WPF实现视频播放、停止、暂停功能 1, NuGet 添加 VideoLAN.LibVLC.Windows 2. NuGet 添加 LibVLCSharp.WPF 3. wpf 代码如下&#xff1a; <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、使用【面转线】工具&#xff0c;并取消勾选“识别和存储面邻域信息”&#xff0c;如下&#xff1a; 2、得到的线要素&#xff0c;如下&#xff1a;...

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&#xff0c;发现一个问题&#xff1a;使用it_events的时候选择列排序时会弹出定义排序顺序窗口&#xff0c;如下图所示。&#xff08;正常选择某一列再使用排序功能时会直接排序&#xff0c;不用再选择列&#xff09; 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…...

相机Camera日志实例分析之二:相机Camx【专业模式开启直方图拍照】单帧流程日志详解

【关注我&#xff0c;后续持续新增专题博文&#xff0c;谢谢&#xff01;&#xff01;&#xff01;】 上一篇我们讲了&#xff1a; 这一篇我们开始讲&#xff1a; 目录 一、场景操作步骤 二、日志基础关键字分级如下 三、场景日志如下&#xff1a; 一、场景操作步骤 操作步…...

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

是否存在路径(FIFOBB算法)

题目描述 一个具有 n 个顶点e条边的无向图&#xff0c;该图顶点的编号依次为0到n-1且不存在顶点与自身相连的边。请使用FIFOBB算法编写程序&#xff0c;确定是否存在从顶点 source到顶点 destination的路径。 输入 第一行两个整数&#xff0c;分别表示n 和 e 的值&#xff08;1…...

Rapidio门铃消息FIFO溢出机制

关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系&#xff0c;以下是深入解析&#xff1a; 门铃FIFO溢出的本质 在RapidIO系统中&#xff0c;门铃消息FIFO是硬件控制器内部的缓冲区&#xff0c;用于临时存储接收到的门铃消息&#xff08;Doorbell Message&#xff09;。…...

打手机检测算法AI智能分析网关V4守护公共/工业/医疗等多场景安全应用

一、方案背景​ 在现代生产与生活场景中&#xff0c;如工厂高危作业区、医院手术室、公共场景等&#xff0c;人员违规打手机的行为潜藏着巨大风险。传统依靠人工巡查的监管方式&#xff0c;存在效率低、覆盖面不足、判断主观性强等问题&#xff0c;难以满足对人员打手机行为精…...

【学习笔记】erase 删除顺序迭代器后迭代器失效的解决方案

目录 使用 erase 返回值继续迭代使用索引进行遍历 我们知道类似 vector 的顺序迭代器被删除后&#xff0c;迭代器会失效&#xff0c;因为顺序迭代器在内存中是连续存储的&#xff0c;元素删除后&#xff0c;后续元素会前移。 但一些场景中&#xff0c;我们又需要在执行删除操作…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...

机器学习的数学基础:线性模型

线性模型 线性模型的基本形式为&#xff1a; f ( x ) ω T x b f\left(\boldsymbol{x}\right)\boldsymbol{\omega}^\text{T}\boldsymbol{x}b f(x)ωTxb 回归问题 利用最小二乘法&#xff0c;得到 ω \boldsymbol{\omega} ω和 b b b的参数估计$ \boldsymbol{\hat{\omega}}…...

【Ftrace 专栏】Ftrace 参考博文

ftrace、perf、bcc、bpftrace、ply、simple_perf的使用Ftrace 基本用法Linux 利用 ftrace 分析内核调用如何利用ftrace精确跟踪特定进程调度信息使用 ftrace 进行追踪延迟Linux-培训笔记-ftracehttps://www.kernel.org/doc/html/v4.18/trace/events.htmlhttps://blog.csdn.net/…...

比特币:固若金汤的数字堡垒与它的四道防线

第一道防线&#xff1a;机密信函——无法破解的哈希加密 将每一笔比特币交易比作一封在堡垒内部传递的机密信函。 解释“哈希”&#xff08;Hashing&#xff09;就是一种军事级的加密术&#xff08;SHA-256&#xff09;&#xff0c;能将信函内容&#xff08;交易细节&#xf…...