Skip to content

Add attribution handling to the layer #61

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 3 commits into from
Mar 27, 2025

Conversation

fityannugroho
Copy link
Contributor

Summary

This PR introduces enhancements to improve attribution handling. The key changes include dynamic retrieval of attributions from MapLibre styles, support for custom attribution controls, and additional events to synchronize attribution updates.

Key Changes

Custom Attribution Handling

  • Feature: The getAttribution method now dynamically retrieves attributions from MapLibre style sources if attributionControl is enabled and no custom attribution is specified.
  • Fallback: If no valid attributions are found, it defaults to an empty string.

Automatic Attribution Update on Map Load

  • Added an event listener to the load event of the MapLibre instance to update the Leaflet map's attribution control dynamically after the MapLibre map has fully loaded.

Why This Change?

  • Dynamic Attribution Support: Automatically gathering attributions from MapLibre sources ensures compliance with licensing terms without requiring manual input.
  • Customization Flexibility: Developers can specify their own attributions via options.attributionControl.customAttribution when needed.

@lseelenbinder
Copy link
Member

Hey @fityannugroho, thanks for your patience with the long delay for review on this!

Would you be able to look at this again to fix the conflicts and remove the version bump? We'll do that separately. Otherwise it looks good.

@fityannugroho
Copy link
Contributor Author

Done! Please take a look @lseelenbinder

@lseelenbinder lseelenbinder merged commit d9280d8 into maplibre:main Mar 27, 2025
@tomhughes tomhughes mentioned this pull request Jul 24, 2025
@tomhughes
Copy link
Contributor

tomhughes commented Jul 24, 2025

I don't understand how the dynamic attribution stuff here is supposed to work - by default options.attributionControl is false so neither test in getAttribution will pass which is fine.

We can get a custom attribution by setting options.attributionControl to an object with a customAttribution member.

The only way I an see to get a dynamic attribution is to use a weird value like 0 or '' which is falsey without actually being false because any truthy value will make us (try and) return options.attributionControl and I honestly can't believe that was the intention?

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.

3 participants