Allow map layers to specify an alternate tile set for dark mode
This commit is contained in:
parent
8312ddfe0c
commit
01d8dba8ce
1 changed files with 10 additions and 0 deletions
|
@ -32,6 +32,8 @@ L.OSM.Map = L.Map.extend({
|
||||||
layerOptions.apikey = OSM[value];
|
layerOptions.apikey = OSM[value];
|
||||||
} else if (property === "leafletOsmId") {
|
} else if (property === "leafletOsmId") {
|
||||||
layerConstructor = L.OSM[value];
|
layerConstructor = L.OSM[value];
|
||||||
|
} else if (property === "leafletOsmDarkId" && OSM.isDarkMap() && L.OSM[value]) {
|
||||||
|
layerConstructor = L.OSM[value];
|
||||||
} else {
|
} else {
|
||||||
layerOptions[property] = value;
|
layerOptions[property] = value;
|
||||||
}
|
}
|
||||||
|
@ -386,6 +388,14 @@ L.extend(L.Icon.Default.prototype, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
OSM.isDarkMap = function () {
|
||||||
|
var mapTheme = $("body").attr("data-map-theme");
|
||||||
|
if (mapTheme) return mapTheme === "dark";
|
||||||
|
var siteTheme = $("html").attr("data-bs-theme");
|
||||||
|
if (siteTheme) return siteTheme === "dark";
|
||||||
|
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||||
|
};
|
||||||
|
|
||||||
OSM.getUserIcon = function (url) {
|
OSM.getUserIcon = function (url) {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: url || OSM.MARKER_RED,
|
iconUrl: url || OSM.MARKER_RED,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue