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 from leaflet-osm plugin #5426

Closed
wants to merge 4 commits into from

Conversation

hlfan
Copy link
Contributor

@hlfan hlfan commented Dec 20, 2024

A version between #5396 and #5397 using the updated version of leaflet-osm without requiring it.
Also removing some ifs that always evaluate true and removed the dependency on the .key-ui.

@hlfan
Copy link
Contributor Author

hlfan commented Dec 20, 2024

Huh, no linting support for the optional chaining operator?

I may have gotten a bit overexcited by #5421.

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.

Can you fix the lint warning? Then we can get this merged!

@hlfan hlfan requested a review from tomhughes December 22, 2024 17:51
@hlfan
Copy link
Contributor Author

hlfan commented Dec 22, 2024

Since the line with the not (yet) supported optional chaining is only to make the updates work without the UI panes (like in the tests) anyway, the complexity of that predicate can be reduced.

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.

As it stands this only works correctly for the transport layer that has a dark variant - for all other layers it disables the filtering when in dark mode.

@@ -31,6 +31,9 @@ L.OSM.layers = function (options) {
var miniMap = L.map(mapContainer[0], { attributionControl: false, zoomControl: false, keyboard: false })
.addLayer(new layer.constructor(layer.options));

if (layer.options.schemeClass) miniMap.getPane("tilePane").classList.add(layer.options.schemeClass);
miniMap.getPane("tilePane").style.setProperty("--dark-mode-map-filter", layer.options.filter || "none");
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 layer that has a filter option now so this just always removes the filter, plus we don't want to be editing the style anyway as we're trying to get away from using inline styles.

What this should do is change the style rules at

@mixin dark-map-color-scheme {
to avoid filtering when the map has the dark class applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the dark flag/class should have special treatment, should thunderforest-cycle get a special nofilter class as the first layer where the default from the current proposal #5328 (comment) is explicitly asked for (#5395 (comment))? And should further layers also get a class each?

Do you think it is favorable to spread the map layer filter definitions that much into CSS as well? I think having the way the layers from leaflet-osm are used in a single location including filters adds to the maintainability.

Copy link
Member

Choose a reason for hiding this comment

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

I only mentioned the dark class because you're already applying it, though as far as I know it does nothing currently? I don't care too much about exactly what you call the class but I do want to make the filtering decision dependent on a class rather than on dynamically editing the style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the opinions in #5328 varied wildly, I wanted to have an easy flag for other devs that an alternate tileset has been loaded, since some might like a different styling like I already mentioned in #5396 (comment).
You are correct in that it doesn't do anything on the unmodified site.

if (layer.options.schemeClass) container.classList.add(layer.options.schemeClass);
for (let filterReceiver of [container, document.querySelector(".key-ui")]) {
if (!filterReceiver) continue;
filterReceiver.style.setProperty("--dark-mode-map-filter", layer.options.filter || "none");
Copy link
Member

Choose a reason for hiding this comment

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

The same thing applies here - we should be making the style look at the class instead of modifying the style inline in a way that doesn't even work.

@gravitystorm
Copy link
Collaborator

As it stands this only works correctly for the transport layer that has a dark variant - for all other layers it disables the filtering when in dark mode.

I think it's important here to note that we decided in #5328 that only filters approved by the cartographers should be applied. Since currently no cartographers have chosen any filters, then it's expected that any existing filtering (e.g. darken) would be removed by default, until we hear back from some other cartographers.

@hlfan could you also work on the point that @tomhughes raised with regards to setting classes instead of using inline styles?

@hlfan
Copy link
Contributor Author

hlfan commented Jan 15, 2025

Yes, however, I can already hear the question "why are you adding a no-dark-filter class to the cyclemap that only sets filter:none instead of inheriting filter:none?" coming up in the new PR, as this doesn't need half of the changes here.

@hlfan hlfan marked this pull request as draft January 16, 2025 02:12
@hlfan hlfan closed this Jan 18, 2025
@hlfan hlfan deleted the dark-mode-ular-losm branch January 18, 2025 06:47
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