Skip to content

重置事件模块更新 - #2826

Merged
lzxue merged 78 commits into
masterfrom
beta
Mar 10, 2026
Merged

重置事件模块更新#2826
lzxue merged 78 commits into
masterfrom
beta

Conversation

@lzxue

@lzxue lzxue commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

[English Template / 英文模板]

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 工作流程
  • 版本更新
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

📝 更新日志

语言 更新描述
🇺🇸 英文
🇨🇳 中文

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

lzxue and others added 30 commits January 23, 2026 17:18
- Auto create PR when .skills directory changes
- File validation (type, size, content check)
- Only run on official antvis/L7 repository
- Support manual trigger with force option
1. 修复蜂窝热力图 (hexagon):
   - 调整六边形方向为 pointy-top,与 d3-hexbin 一致
   - 翻转 y 坐标方向以匹配屏幕坐标系

2. 修复网格热力图 (grid):
   - 改用屏幕像素坐标划分网格,与 hexagon 一致
   - 修正 xOffset/yOffset 计算:正方形顶点范围是 [-√2/2, √2/2]

3. 修复 count 聚合方法:
   - 在 statMap 中添加 count 方法

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
主要优化:
- TileLayerService: 使用 Map 存储瓦片实例,查找复杂度从 O(n) 降为 O(1)
- TileLayerService: 实现分帧销毁机制,避免大量瓦片销毁阻塞渲染
- TileLayerService: 添加渲染列表缓存和脏标记,减少每帧重建
- BaseLayer: 合并多个 filter 操作,减少中间数组创建
- BaseLayer: 优化视图状态比较,使用数值比较替代字符串比较
- TilesetManager: 缓存 tiles getter,避免每次访问都排序
- TilesetManager: 使用 Set 存储当前瓦片 key,加速查找
- TilesetManager: 合并 updateTileVisible 遍历,减少迭代次数
- SourceTile: 缓存 bounds 和 bboxPolygon,避免重复计算
- TilePickService: 优化遍历,跳过未加载的瓦片

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
主要优化:
- math.ts: 表达式预编译为函数,避免循环中 JSON 序列化/反序列化
  - 对于 256x256 瓦片,从 65536 次序列化操作优化为 1 次编译
  - 预分配 Float32Array 结果数组,避免动态扩容
- operationSchema.ts: 使用快速选择算法计算百分位
  - 复杂度从 O(n log n) 降到 O(n)
  - 预分配 Uint8Array 数组存储 RGB 数据
- getRasterData.ts: 多波段数据并行请求
  - 使用 Promise.all 并行请求,减少网络等待时间

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
主要修复:
1. 修复 UBO std140 布局问题 - vec3 只占 3 floats,之前的布局导致 u_RelativeOrigin 位置错误
2. 修复 extrude/water/ocean 图层在相对坐标模式下 UV 计算错误
3. 修复 Pipeline 缓存 key 生成不完整导致的状态不一致问题

性能优化:
1. 添加颜色解析缓存 (rgb2arr),避免重复解析相同颜色
2. 优化数据映射插件的过滤流程,减少遍历次数
3. 添加质心计算缓存

其他修复:
1. 移除地图适配器中的硬编码 API Keys
2. 修复 Scene.emit 调用错误

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- fix: 修复 citybuliding 目录名拼写错误 (citybuliding -> citybuilding)
- refactor: 用自定义实现替代 lodash 依赖,优化包大小
- refactor: 将 SimpleMapCoord 移到 maps 包本地 utils
- fix: 添加 getDefault 方法返回类型
- fix: 修复 merge 函数的类型参数
- fix: 添加 initCfg 方法 option 参数的条件检查
- chore: 更新 build 脚本,添加 clean-dist 步骤

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 packages/source/src/utils/csv.ts 实现 csvParse 函数
- 支持 CSV 基础解析、引号处理、转义引号、各种换行符
- 移除 d3-dsv 和 @types/d3-dsv 依赖
- 添加完整的单元测试覆盖边界情况

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 在 lodash-adapter.ts 中添加 extent 函数实现
- 移除 d3-array 和 @types/d3-array 依赖
- 更新 FeatureScalePlugin 使用 lodashUtil.extent
- 添加 lodash-adapter 单元测试

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 packages/utils/src/color-parser.ts 实现颜色解析
- 支持 hex、rgb/rgba、hsl/hsla 和 CSS 颜色名称
- 更新 color.ts 使用自定义 parseColor 函数
- 移除 utils 和 layers 包中的 d3-color 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 在 color-parser.ts 中添加 interpolateRgbBasis 函数
- 实现分段线性颜色插值功能
- 更新 FeatureScalePlugin 使用自定义 interpolateRgbBasis
- 移除 layers 包中的 d3-interpolate 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 packages/source/src/utils/hexbin.ts 实现六边形分箱算法
- 使用 odd-q offset 坐标系统与 d3-hexbin 兼容
- 更新 hexagon.ts 使用自定义 hexbin 函数
- 移除 d3-hexbin 和 @types/d3-hexbin 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 将 odd-q 偏移(奇数列偏移)改为 odd-r 偏移(奇数行偏移)
- 完全复制 d3-hexbin 的分箱算法逻辑
- 修复中心坐标计算方式:
  - x = (pi + (pj & 1) / 2) * dx
  - y = pj * dy
- 修复访问器类型签名以支持 3 个参数

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 packages/layers/src/utils/scale.ts 实现 10 种比例尺
- scaleLinear, scalePow, scaleLog: 连续比例尺
- scaleSequential, scaleDiverging: 连续颜色比例尺
- scaleQuantile, scaleQuantize, scaleThreshold: 离散比例尺
- scaleOrdinal: 枚举比例尺
- scaleTime: 时间比例尺
- 更新 FeatureScalePlugin 使用自定义比例尺
- 移除 d3-scale 和 @types/d3-scale 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 sanitizeDomain 函数处理 domain 中的 undefined、null、NaN 值
- 修复当 extent 返回 [undefined, undefined] 时导致 NaN 计算的问题
- 处理 domain 只有一个值或为空的情况
- 处理 domain[0] === domain[1] 时除以零的问题
- 所有连续比例尺现在都对无效输入有容错处理

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 移除 lodash 依赖(已有自定义 lodash-adapter 实现)
- 移除 layers 包中未使用的 extrude-polyline、polyline-miter-util、gl-vec2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 使用现代浏览器原生支持的 ResizeObserver API
- 移除 element-resize-detector 和 @types/element-resize-detector 依赖
- 减少第三方依赖,提升稳定性

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lzxue and others added 22 commits February 25, 2026 12:05
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
symbol-es6@0.1.2 是较旧的 polyfill,会覆盖原生 Symbol.iterator 实现,
导致 earcut 返回的 Uint32Array 无法被 spread 操作符展开。

现代浏览器已原生支持 Symbol 和迭代器协议,不需要此 polyfill。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- SceneService 增加监听 Hover/Click/DblClick 事件并发射到 scene
- IInteractionTarget 添加 pixel 属性兼容 l7-draw 事件格式
- 修复 mousedown 事件发送时机,确保 layer 能正确接收拖拽开始事件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 初始化 BaseLayer.animateStartTime 为 0,避免动画时间返回 NaN
- 添加 std140 uniform block padding 字段,修正内存对齐(108 -> 112 字节)
- 修复 removeDuplicateUniforms 函数处理 L7 默认值语法(:)
- 确保在 WebGL1/regl 渲染器下着色器正确编译
- 更新高德地图主题 URL 使用标准格式
- 修复 Three.js demo 中 GLTFLoader 的引入方式,改为使用 window.GLTFLoader

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolved conflicts in:
- packages/core/package.json
- packages/maps/src/amap-next/map.ts
- .changeset/pre.json (added)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Mar 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 61456b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

本次拉取请求主要旨在解决 L7 库中事件系统因移除 Hammer.js 而引发的兼容性问题,通过回滚到 Hammer.js 实现来恢复事件的正常功能。此外,还对核心服务中的事件监听机制进行了增强,优化了 AMap 地图的集成配置和样式,并对图层着色器和基础配置进行了细微调整,以提升系统的稳定性和开发体验。

Highlights

  • 事件系统回滚与兼容性修复: 由于此前移除 Hammer.js 导致事件系统出现兼容性问题,本次更新回滚了事件系统到 Hammer.js 实现,并修复了相关问题。具体包括修复 triggerHover 方法签名不符导致 layer.pick() 失效,以及 SceneService 补充 Press 事件监听以保持长按事件的向后兼容性。
  • 核心服务事件监听增强: SceneService 新增了对 HoverClickDblClick 事件的监听,扩展了场景交互能力。
  • AMap 地图配置与样式优化: 更新了 AMap 的默认 Key,并修复了 amap-next 模块中地图容器的定位上下文和高度初始化问题。同时,AMap 的地图样式配置也进行了简化,使用了更通用的样式名称。
  • 着色器与图层配置调整: 城市建筑图层的着色器中增加了 u_padding 统一变量,BaseLayeranimateStartTime 属性被初始化为 0,并对 enableRelativeCoordinates 属性访问增加了可选链操作符。
  • 开发与构建配置更新: Vite 服务器配置中增加了 allowedHosts,UMD 构建配置中禁用了 CSS 提取,并更新了多个 CHANGELOG.md 文件和 package.json 中的版本号。
Changelog
  • .changeset/fix-interaction-event-compat.md
    • 修复移除 hammerjs 后的事件系统兼容性问题
    • 修复 triggerHover 方法签名与接口不符,补全 lngLat 和 type 参数,解决 layer.pick() 拾取失效问题
    • SceneService 补充 Press 事件监听,保持长按事件向后兼容
    • amap-next: 修复 wrapper 容器定位上下文和高度初始化问题
  • .changeset/fuzzy-readers-sing.md
    • 版本更新
  • .changeset/revert-to-hammerjs.md
    • revert: 回滚事件系统到 hammerjs 实现,修复移除 hammerjs 后的兼容性问题
  • packages/component/CHANGELOG.md
    • 更新了依赖包版本
  • packages/core/CHANGELOG.md
    • 回滚事件系统到 hammerjs 实现,修复移除 hammerjs 后的兼容性问题
    • 修复移除 hammerjs 后的事件系统兼容性问题
    • 修复 triggerHover 方法签名与接口不符,补全 lngLat 和 type 参数,解决 layer.pick() 拾取失效问题
    • SceneService 补充 Press 事件监听,保持长按事件向后兼容
    • amap-next: 修复 wrapper 容器定位上下文和高度初始化问题
    • 版本更新
  • packages/l7/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/layers/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/map/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/maps/CHANGELOG.md
    • 更新了依赖包版本
    • 修复移除 hammerjs 后的事件系统兼容性问题
    • 修复 triggerHover 方法签名与接口不符,补全 lngLat 和 type 参数,解决 layer.pick() 拾取失效问题
    • SceneService 补充 Press 事件监听,保持长按事件向后兼容
    • amap-next: 修复 wrapper 容器定位上下文和高度初始化问题
    • 版本更新
  • packages/renderer/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/scene/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/source/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/test-utils/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/three/CHANGELOG.md
    • 更新了依赖包版本
    • 版本更新
  • packages/utils/CHANGELOG.md
    • 版本更新
Activity
  • 此拉取请求没有提供具体的评论、审查或进度更新活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

- Update all package versions from 2.23.3-beta.3 to 2.24.0
- Clear changeset files for stable release

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This Pull Request primarily revolves around updating and resetting the event module, fixing compatibility issues caused by its previous removal by rolling back to the hammerjs implementation. A security concern was identified regarding a hardcoded AMap API key in the amap-next map service. Additionally, the update includes improvements such as optimizing event listener binding in SceneService for better performance and code style, enhancing robustness by adding default styles to the map container in amap-next/map.ts and using optional chaining in BaseLayer.ts, and fixing uniform extraction logic in shader-module.ts to resolve parsing issues for uniforms with default values.

// 默认的高德地图 Key,仅用于开发和演示,生产环境请使用自己的 Key
// 申请地址: https://lbs.amap.com/api/javascript-web-api/guide/abc/prepare
const DEFAULT_AMAP_KEY = '6c0e16556c6c774e7bb61bc6089483a5';
const DEFAULT_AMAP_KEY = 'f59bcf249433f8b05caaee19f349b3d7';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

A default AMap API key (DEFAULT_AMAP_KEY) is hardcoded in the library source code. This poses a significant security risk as it can lead to unauthorized use, quota exhaustion, and makes key rotation difficult if compromised. Even if intended for development or demo purposes, hardcoding API keys should be avoided. It is recommended to store the key in environment variables or a version-controlled configuration file, and load it dynamically at runtime.

Suggested change
const DEFAULT_AMAP_KEY = 'f59bcf249433f8b05caaee19f349b3d7';
const DEFAULT_AMAP_KEY = process.env.REACT_APP_AMAP_KEY || 'your-fallback-key-if-any';

Comment on lines +164 to +166
this.interactionService.on(InteractionEvent.Hover, this.addSceneEvent.bind(this));
this.interactionService.on(InteractionEvent.Click, this.addSceneEvent.bind(this));
this.interactionService.on(InteractionEvent.DblClick, this.addSceneEvent.bind(this));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提升代码性能和可读性,建议避免在多处重复调用 .bind(this)。一个更好的做法是将 addSceneEvent 方法定义为箭头函数属性,这样它会自动绑定 this 上下文。

// 在 SceneService 类中,将方法定义改为箭头函数属性:
private addSceneEvent = (target: IInteractionTarget) => {
  this.emit(target.type, target);
}

// ... 然后在 init 方法中,可以直接引用,无需 .bind:
this.interactionService.on(InteractionEvent.Drag, this.addSceneEvent);
this.interactionService.on(InteractionEvent.Hover, this.addSceneEvent);
this.interactionService.on(InteractionEvent.Click, this.addSceneEvent);
this.interactionService.on(InteractionEvent.DblClick, this.addSceneEvent);

这样做可以确保只创建一个函数实例,并在所有事件监听器中复用,使代码更简洁高效。

@lzxue
lzxue merged commit a54824d into master Mar 10, 2026
5 checks passed
@lzxue
lzxue deleted the beta branch March 10, 2026 06:51
@lzxue
lzxue restored the beta branch March 13, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant