当前位置: 首页 > 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…...

Awesome-Awesome终极指南:如何快速找到任何技术领域的最佳资源

Awesome-Awesome终极指南&#xff1a;如何快速找到任何技术领域的最佳资源 【免费下载链接】awesome-awesome A curated list of awesome curated lists of many topics. 项目地址: https://gitcode.com/gh_mirrors/aw/awesome-awesome 在技术学习和开发过程中&#xff…...

从理论到实践:拆解FOC滑模观测器中的三个关键增益(Gsmopos, Fsmopos, Hsmopos)

从理论到实践&#xff1a;拆解FOC滑模观测器中的三个关键增益&#xff08;Gsmopos, Fsmopos, Hsmopos&#xff09; 在永磁同步电机&#xff08;PMSM&#xff09;的磁场定向控制&#xff08;FOC&#xff09;系统中&#xff0c;滑模观测器&#xff08;SMO&#xff09;因其强鲁棒性…...

DFRDisplayKm 实用指南:Apple Touch Bar Windows支持常见问题全解析

DFRDisplayKm 实用指南&#xff1a;Apple Touch Bar Windows支持常见问题全解析 【免费下载链接】DFRDisplayKm Windows infrastructure support for Apple DFR (Touch Bar) 项目地址: https://gitcode.com/gh_mirrors/df/DFRDisplayKm DFRDisplayKm 是一款专为 Windows…...

LockSupport深度解析:线程阻塞与唤醒的底层实现原理

在技术领域&#xff0c;我们常常被那些闪耀的、可见的成果所吸引。今天&#xff0c;这个焦点无疑是大语言模型技术。它们的流畅对话、惊人的创造力&#xff0c;让我们得以一窥未来的轮廓。然而&#xff0c;作为在企业一线构建、部署和维护复杂系统的实践者&#xff0c;我们深知…...

从ATE到RPE:用evo全面解读你的SLAM算法在KITTI上的表现

从ATE到RPE&#xff1a;用evo全面解读你的SLAM算法在KITTI上的表现 在SLAM算法开发中&#xff0c;量化评估是验证算法性能的关键环节。KITTI数据集作为自动驾驶领域最具影响力的基准测试平台之一&#xff0c;为研究者提供了丰富的真实场景数据。但如何从海量轨迹数据中提取有价…...

开源项目常见安装故障的系统性排查与解决

开源项目常见安装故障的系统性排查与解决 【免费下载链接】ComfyUI-Manager ComfyUI-Manager is an extension designed to enhance the usability of ComfyUI. It offers management functions to install, remove, disable, and enable various custom nodes of ComfyUI. Fur…...

3个秘诀让城通网盘下载提速10倍:ctfileGet工具全解析

3个秘诀让城通网盘下载提速10倍&#xff1a;ctfileGet工具全解析 【免费下载链接】ctfileGet 获取城通网盘一次性直连地址 项目地址: https://gitcode.com/gh_mirrors/ct/ctfileGet ctfileGet是一款专注于获取城通网盘直连地址的开源工具&#xff0c;通过本地解析技术帮…...

二手交易平台信任度调查:闲鱼交易安全性深度解析

二手交易平台信任度调查&#xff1a;闲鱼交易安全性深度解析随着循环经济的兴起&#xff0c;中国二手交易市场规模在2023年突破万亿元大关。作为阿里巴巴旗下的C2C二手交易平台&#xff0c;闲鱼凭借5亿注册用户和日均10亿元的交易规模&#xff0c;已成为国内最大的闲置物品流转…...

KityMinder云存储与分享功能完整指南:打造高效团队协作体验

KityMinder云存储与分享功能完整指南&#xff1a;打造高效团队协作体验 【免费下载链接】kityminder 百度脑图 项目地址: https://gitcode.com/gh_mirrors/ki/kityminder KityMinder作为百度FEX团队开发的在线思维导图工具&#xff0c;其强大的云存储与分享功能让团队协…...

车载Android Auto兼容性开发全链路(车规级Java SDK集成手册)

第一章&#xff1a;车载Android Auto兼容性开发全链路概览Android Auto 是 Google 提供的车载信息娱乐系统集成框架&#xff0c;其兼容性开发并非仅限于应用层适配&#xff0c;而是一条横跨设备端、车机系统、认证流程与用户交互的完整技术链路。开发者需同步关注 Android 应用…...