[Bug] onMoveEnd event is fired on second map on remount with reuseMaps

未关闭
#2,512 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
react, typescript
领域
frontend

调研方向

首先运行链接的 CodeSandbox 复现,并在两张地图都启用 reuseMaps 的情况下多次切换 Unmount/Mount。跟踪 reuseMaps 的重新挂载处理和主地图的 moveend 事件,然后验证重新挂载不会改变迷你地图的缩放级别,也不会报告错误地图的视图状态。

由索引模型根据 Issue 内容生成。

描述

bug
Description

I have a main map and a mini map.
I would like the view state of the main map to drive the mini map, however the mini map should always be 2 zoom levels lower than the main map.
The main map is uncontrolled, the mini map is controlled.
The main map view state is stored in React state which updates when the main map moveend event fires.

The maps appear in a modal, so are unmounted and remounted as the modal is opened and closed. So I also have reuseMaps added to reduce mapbox map loads from the frequent mounting.

Each time the maps are remounted, the mini map zoom level decreases by 2 without moving the main map.
This only occurs when reuseMaps is set for both maps. But of course, I'd like to reuse both to save on map loads :)

The bug appears to be, at least, that the moveend callback for the main map is fired with the zoom level of the mini map, NOT the main map
You can see in the logs of the moveend callback that the zoom of the event view state doesn't match the main map zoom even when not changing the main map zoom. and the ID of the container for the event is indeed the main map.

But additionally may be that the moveend callback fires when the maps remount, when in reuse mode? does remount when reuse is on count as a move event?

Expected Behavior

moveend doesn't fire with reuse + remount? Or at least, the zoom of the event should match to the map the handler is attached to.
The zoom level of the mini map shouldn't change.

Steps to Reproduce

https://codesandbox.io/p/sandbox/epic-liskov-mymg27

Click Unmount/Mount several times to observe the mini map zoom level decreases each time

Environment
Logs

No response

主要语言
TypeScript
星标
8.5k
派生
1.3k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

visgl/react-map-gl 的其他 Issue

查看 visgl/react-map-gl 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。