Skip to content

Map#on, once and off - support for multiple layers #4570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Aug 24, 2024

Conversation

pstaszek
Copy link
Contributor

@pstaszek pstaszek commented Aug 16, 2024

Implements: #4279

This PR adds support for adding listener for multiple layers using Map#on and Map#once. It also adds support for removing listeners with Map#off function.

To remove listener in off function the user has to provide array of layerIds with the same content as when creating the listener. I chose this approach because it seems the simplest, there is no need to consider complex cases (i.e. remove only part of layers from listener).

I intentionally did not check the Mapbox GL JS implementation before I wrote my code. I did it after and to some degree it is similar, because it is the most obvious implementation. Is it ok, or should we try to find some other way to implement this feature?

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2024

Codecov Report

Attention: Patch coverage is 93.65079% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.72%. Comparing base (8a005bd) to head (a0b009b).
Report is 260 commits behind head on main.

Files with missing lines Patch % Lines
src/ui/map.ts 93.65% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4570      +/-   ##
==========================================
- Coverage   87.84%   87.72%   -0.12%     
==========================================
  Files         247      247              
  Lines       33574    33601      +27     
  Branches     2366     2391      +25     
==========================================
- Hits        29492    29476      -16     
- Misses       3116     3131      +15     
- Partials      966      994      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator

HarelM commented Aug 17, 2024

Can you check if the coverage is correct?
Otherwise, looks good.

@pstaszek
Copy link
Contributor Author

@HarelM I have bumped up the coverage with few additional tests.

@pstaszek
Copy link
Contributor Author

I have some issue with registering once event, but I'm not sure if it is related to this PR. I will investigate it further tomorrow, or during the weekend.

@pstaszek
Copy link
Contributor Author

pstaszek commented Aug 23, 2024

Ok - this is something unrelated to this PR.
I notice a bug, that it is not possible to deregister a listener added with once method with a layer - this is because removeDelegatedListener function looks for callback reference in this._delegatedListener, but once method is not saving it there.

src/ui/map.ts Outdated

_removeDelegatedListener(type: string, layerIds: string[], listener: Listener) {
if (!this._delegatedListeners || !this._delegatedListeners[type]) {
return this;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure returning "this" is needed.
I would simply return void.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, done.

@HarelM
Copy link
Collaborator

HarelM commented Aug 24, 2024

Can you fix the build test please? Just update the size.

@pstaszek
Copy link
Contributor Author

@HarelM
Copy link
Collaborator

HarelM commented Aug 24, 2024

Yes please.

@HarelM HarelM merged commit 2b847a3 into maplibre:main Aug 24, 2024
15 checks passed
@HarelM
Copy link
Collaborator

HarelM commented Aug 24, 2024

Thanks!!!

@pstaszek pstaszek deleted the issue-4279-map-on-multiple-layers branch August 24, 2024 18:44
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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy