Skip to content
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

Use map tiles dark mode with leaflet-osm plugin #5396

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

hlfan
Copy link
Contributor

@hlfan hlfan commented Dec 12, 2024

This lean and updated variant of #4777 follows the rules laid out in #5328 that were implemented in #5362.
Since the editing of the user preference happens on a different view/site, there is no need to listen to color scheme changes on the fly and the whole logic can happen in the initialization of L.OSM.TileLayer.

Before After
image image

Additionally, a "dark" CSS class is introduced to allow better style targeting if the user wants to.
for example like this:
image

@tomhughes
Copy link
Member

Changes to anything under vendor need to be done in the appropriate upstream repository, not here.

@tomhughes
Copy link
Member

tomhughes commented Dec 12, 2024

Also inline styles are not allowed by our security policy in production so any dynamic changes need to be done by adding or removing classes to trigger static style rules in the main stylesheet.

@hlfan
Copy link
Contributor Author

hlfan commented Dec 12, 2024

I wrote it's a leaner variant of #4777, not that I fixed its flaws.

Changes to anything under vendor need to be done in the appropriate upstream repository, not here.

That's why I left openstreetmap/leaflet-osm#42 open.

inline styles are not allowed by our security policy in production

The style-src 'self' 'unsafe-inline' in the CSP header tells me a different story.

Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

I don't think leaflet-osm should be getting involved in automatic transforms - it should have the ability to select a dark tile version where there is one and any automatic transformations should only be in the osm.org code.

options = L.Util.setOptions(this, options);
L.TileLayer.prototype.initialize.call(this, options.url);
url = isDarkMap ? options.darkUrl : options.lightUrl;
Copy link
Member

Choose a reason for hiding this comment

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

There is no lightUrl anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, if the provided layers can be expected always to be a light-mode-first choice, the logic can be simplified to this more unreadable version:

    options.filter = isDarkMap && options.darkFilter || 'none';
    options = L.Util.setOptions(this, options);
    url = isDarkMap && options.darkUrl;
    this.schemeClass = url && 'dark';

But I thought an implementation agnostic to that would be easier to think through with more options for cartographers' choices.

@tomhughes
Copy link
Member

inline styles are not allowed by our security policy in production

The style-src 'self' 'unsafe-inline' in the CSP header tells me a different story.

OK so it is allowed for views with a map. I'm note sure why that is offhand but our goal is to not have it so we don't add new inline styles ourselves but we sometimes have to allow it for third party components.

@hlfan
Copy link
Contributor Author

hlfan commented Dec 12, 2024

leaflet-osm should be getting involved in automatic transforms - it should have the ability to select a dark tile version where there is one

Do you mean only the extension of L.OSM.TransportMap should be added to leaflet-osm?

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.

2 participants