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 class based map tiles dark mode #5505

Closed
wants to merge 3 commits into from

Conversation

hlfan
Copy link
Contributor

@hlfan hlfan commented Jan 16, 2025

A cleaner, class-based variant of #5426, enabling moving more logic out of layeradd into initialize.

} else if (property === "leafletOsmDarkId" && OSM.isDarkMap() && L.OSM[value]) {
layerConstructor = L.OSM[value];
layerOptions.className += " dark";
} else if (property === "filterClass" && OSM.isDarkMap()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think something like darkFilterClass would be better as the property name, so that it's clear what the filtering is for.

this.on("layeradd", function ({ layer }) {
if (this.baseLayers.indexOf(layer) < 0) return;
this.setMaxZoom(layer.options.maxZoom);
const key = document.querySelector(".key-ui");
Copy link
Member

Choose a reason for hiding this comment

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

We normally use jQuery rather than native methods like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that multiple ways, but jQuery-based variants always errored out, so I just left it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've looked further into it, this is on me for having minified leaflet overwrite the $ function.
This works:

jQuery(".key-ui").attr("class", "key-ui " + layer.options.className);

this.setMaxZoom(layer.options.maxZoom);
const key = document.querySelector(".key-ui");
if (!key) return;
key.className = "key-ui " + layer.options.className;
Copy link
Member

Choose a reason for hiding this comment

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

...and if jQuery is used then this can use addClass and not have to worry about preserving pre-existing classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also have to remove the classes from the previously selected layer. And I'd rather do that in a single line without needing a separate function on layerremove.

@@ -31,6 +31,7 @@
apiKeyId: "THUNDERFOREST_KEY"
canEmbed: true
canDownloadImage: true
filterClass: "no-filter"
Copy link
Member

Choose a reason for hiding this comment

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

I assumed that the filter class was going to be for turning on filtering, not for turning it off? My understanding from #5426 is that enabling filtering for a layer will only happen on the basis of agreement with the designer of that layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I appeal that as long as there isn't documentation on which layers should get which treatment in dark mode, explicitly specifying at least in one file that this layer already has had a review of how it should be displayed in dark mode is critical for maintainability and avoiding unnecessary re-reviews.

.leaflet-tile-container .leaflet-tile {
filter: none;
.no-filter, .dark {
--dark-mode-map-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.

This all seems very confused - you've removed the default value for the filter variable, and set a default of none when using it, so why do we need to explicitly set it to none here?

@@ -516,13 +515,13 @@ body.small-nav {
}

@mixin dark-map-color-scheme {
.leaflet-tile-container,
.leaflet-layer,
Copy link
Member

Choose a reason for hiding this comment

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

Why the change in class here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the need to stop .leaflet-tile from inheriting the filter from .leaflet-tile-container since .leaflet-tile-container doesn't inherit the filter from .leaflet-layer.

@tomhughes
Copy link
Member

Superseded by #5507.

@tomhughes tomhughes closed this Jan 18, 2025
@hlfan hlfan deleted the classy-dark-mode branch January 18, 2025 16:32
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