fix(tmap): add resize event listener to handle browser window resize (fixes #2751) - #2833
Conversation
|
Summary of ChangesHello, 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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| this.map.on('resize', this.handleCameraChanged);// FIX #2751: handle window resize | |
| this.map.on('resize', this.handleCameraChanged); |
References
- 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.
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 theresizeevent 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
resizeevent listener in theinit()method to ensurehandleCameraChanged()is called when the map container is resized.Changes
this.map.on('resize', this.handleCameraChanged)inTMapService.init()Testing
Fixes #2751