Skip to content

fix(tmap): add resize event listener to handle browser window resize (fixes #2751) - #2833

Merged
lzxue merged 3 commits into
antvis:masterfrom
lzxue:fix/tmap-resize
Mar 18, 2026
Merged

fix(tmap): add resize event listener to handle browser window resize (fixes #2751)#2833
lzxue merged 3 commits into
antvis:masterfrom
lzxue:fix/tmap-resize

Conversation

@lzxue

@lzxue lzxue commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Problem

When the browser window is resized, TencentMap (TMap) fails to automatically trigger the resize event, causing L7 layers to be misplaced (错位). This issue affects all components using TencentMap with L7.

Root Cause

The TMapService.init() method subscribes to various map events (drag, pan, rotate, pitch, zoom) but was missing the resize event listener. When the browser window is resized, the map container size changes but no event is triggered to update the L7 viewport.

Solution

Add the resize event listener in the init() method to ensure handleCameraChanged() is called when the map container is resized.

Changes

  • Added this.map.on('resize', this.handleCameraChanged) in TMapService.init()

Testing

  1. Initialize a map with TencentMap as the base map
  2. Add L7 layers to the scene
  3. Resize the browser window
  4. Verify that layers remain correctly positioned relative to the base map

Fixes #2751

@changeset-bot

changeset-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 15059f5

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.

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!

This pull request resolves an issue where L7 layers would become misaligned or misplaced when the browser window was resized while using TencentMap. The problem stemmed from the TMapService not subscribing to the map's resize event. By introducing this event listener, the map's camera adjustments are now correctly triggered upon window resizing, ensuring visual consistency for L7 layers.

Highlights

  • TencentMap Resize Event Handling: Added a resize event listener to the TMapService.init() method. This ensures that the handleCameraChanged() function is called when the browser window is resized, preventing L7 layers from being misplaced.
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.

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.

@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 correctly addresses the issue where L7 layers were misplaced on browser window resize when using TencentMap. Adding the resize event listener is the right solution. I have one minor suggestion to improve code consistency and maintainability.

Comment thread packages/maps/src/tmap/map.ts Outdated
this.map.on('rotate', this.handleCameraChanged);
this.map.on('pitch', this.handleCameraChanged);
this.map.on('zoom', this.handleCameraChanged);
this.map.on('resize', this.handleCameraChanged);// FIX #2751: handle window resize

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

This inline comment is redundant, as the code is self-explanatory and the rationale for the change is well-documented in the commit message and pull request. Removing it will improve code consistency with the other event listener registrations in this block.

Suggested change
this.map.on('resize', this.handleCameraChanged);// FIX #2751: handle window resize
this.map.on('resize', this.handleCameraChanged);
References
  1. Code should be self-documenting. Avoid comments that just repeat what the code does. The 'why' behind a change, especially for a bug fix, is best captured in commit messages and pull request descriptions, not as inline comments.

@lzxue
lzxue merged commit 2cd9937 into antvis:master Mar 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TencentMap 今天开始突然无法自动响应 resize 事件

1 participant