Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5522'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Feb 2, 2025
2 parents 5f7dd9d + d488df1 commit 6ad4260
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/assets/javascripts/embed.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ window.onload = function () {
map.attributionControl.setPrefix("");
map.removeControl(map.attributionControl);

const isDarkTheme = args.theme === "dark" || (args.theme !== "light" && window.matchMedia("(prefers-color-scheme: dark)").matches);
const layers = <%=
YAML.load_file(Rails.root.join("config/layers.yml"))
.select { |entry| entry["canEmbed"] }
.each_with_object({}) do |entry, obj|
obj[entry["layerId"]] = {
layer: entry["leafletOsmId"],
darkLayer: entry["leafletOsmDarkId"],
apiKeyId: entry["apiKeyId"]
}.compact
end.to_json
%>;
const layerId = (args.layer || "").replaceAll(" ", "");
const layerConfig = layers[layerId] || layers.mapnik;
const { layer, ...options } = {
layer: layerConfig.layer,
layer: layerConfig.darkLayer && isDarkTheme ? layerConfig.darkLayer : layerConfig.layer,
apikey: apiKeys[layerConfig.apiKeyId],
...tileOptions[layerId]
};
Expand Down

0 comments on commit 6ad4260

Please sign in to comment.