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

Custom layer filters #5347

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions app/assets/javascripts/leaflet.layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ L.OSM.layers = function (options) {
.appendTo(baseSection);

var mapContainer = $("<div class='position-absolute top-0 start-0 bottom-0 end-0 z-0 bg-body-secondary'>")
.css("--dark-mode-map-filter", layer.options.darkFilter)
.appendTo(buttonContainer);

var input = $("<input type='radio' class='btn-check' name='layer'>")
Expand Down Expand Up @@ -60,13 +61,7 @@ L.OSM.layers = function (options) {
});

input.on("click", function () {
layers.forEach(function (other) {
if (other === layer) {
map.addLayer(other);
} else {
map.removeLayer(other);
}
});
map.updateLayers(layer.options.code);
map.fire("baselayerchange", { layer: layer });
});

Expand Down
15 changes: 10 additions & 5 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,24 @@ L.OSM.Map = L.Map.extend({
},

updateLayers: function (layerParam) {
var layers = layerParam || "M",
layersAdded = "";
var layerCodes = layerParam || "M",
addedLayer;

for (var i = this.baseLayers.length - 1; i >= 0; i--) {
if (layers.indexOf(this.baseLayers[i].options.code) >= 0) {
if (layerCodes.indexOf(this.baseLayers[i].options.code) >= 0 && !addedLayer) {
this.addLayer(this.baseLayers[i]);
layersAdded = layersAdded + this.baseLayers[i].options.code;
} else if (i === 0 && layersAdded === "") {
addedLayer = this.baseLayers[i];
} else if (i === 0 && !addedLayer) {
this.addLayer(this.baseLayers[i]);
addedLayer = this.baseLayers[i];
} else {
this.removeLayer(this.baseLayers[i]);
}
}

if (addedLayer) {
$("body").css("--dark-mode-map-filter", addedLayer.options.darkFilter);
}
},

getLayersCode: function () {
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

body {
font-size: $typeheight;
--dark-mode-map-filter: brightness(.8);
}

time[title] {
Expand Down Expand Up @@ -507,7 +508,7 @@ body.small-nav {
@include color-mode(dark) {
.leaflet-tile-container .leaflet-tile,
.mapkey-table-entry td:first-child > * {
filter: brightness(.8);
filter: var(--dark-mode-map-filter);
}

.leaflet-container .leaflet-control-attribution a {
Expand Down
6 changes: 6 additions & 0 deletions config/layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
id: "make_a_donation"
href: "https://supporting.openstreetmap.org"
donate: true
darkFilter: "invert(.9) hue-rotate(180deg)"

- leafletOsmId: "CyclOSM"
code: "Y"
Expand All @@ -20,6 +21,7 @@
osm_france_link:
id: "osm_france"
href: "https://openstreetmap.fr/"
darkFilter: "brightness(.8)"

- leafletOsmId: "CycleMap"
code: "C"
Expand All @@ -32,6 +34,7 @@
thunderforest_link:
id: "andy_allan"
href: "https://www.thunderforest.com/"
darkFilter: "brightness(.8)"

- leafletOsmId: "TransportMap"
code: "T"
Expand All @@ -44,6 +47,7 @@
thunderforest_link:
id: "andy_allan"
href: "https://www.thunderforest.com/"
darkFilter: "invert(.9) hue-rotate(180deg)"

- leafletOsmId: "TracestrackTopo"
code: "P"
Expand All @@ -56,6 +60,7 @@
tracestrack_link:
id: "tracestrack"
href: "https://www.tracestrack.com/"
darkFilter: "brightness(.8)"

- leafletOsmId: "HOT"
code: "H"
Expand All @@ -70,3 +75,4 @@
osm_france_link:
id: "osm_france"
href: "https://openstreetmap.fr/"
darkFilter: "invert(.9) hue-rotate(180deg)"
Loading