From 00d085ed5db770b3ba18080290850d3283e9ffaf Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Tue, 19 Sep 2023 22:16:42 -0700 Subject: [PATCH] Add Tracestrack Topo as featured layer --- app/assets/javascripts/leaflet.map.js | 16 ++++++++++++++++ app/assets/javascripts/osm.js.erb | 4 ++++ config/initializers/secure_headers.rb | 2 +- config/locales/en.yml | 3 +++ config/settings.yml | 2 ++ vendor/assets/leaflet/leaflet.osm.js | 8 ++++++++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index 6e61100f2..b992b5c8a 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -51,6 +51,13 @@ L.OSM.Map = L.Map.extend({ }).prop("outerHTML"); var thunderforest = I18n.t("javascripts.map.thunderforest_credit", { thunderforest_link: thunderforest_link }); + var tracestrack_link = $("", { + href: "https://www.tracestrack.com/", + target: "_blank", + text: I18n.t("javascripts.map.tracestrack") + }).prop("outerHTML"); + var tracestrack = I18n.t("javascripts.map.tracestrack_credit", { tracestrack_link: tracestrack_link }); + var memomaps_link = $("", { href: "https://memomaps.de/", target: "_blank", @@ -99,6 +106,15 @@ L.OSM.Map = L.Map.extend({ })); } + if (OSM.TRACESTRACK_KEY) { + this.baseLayers.push(new L.OSM.TracestrackTopo({ + attribution: copyright + ". " + tracestrack + ". " + terms, + apikey: OSM.TRACESTRACK_KEY, + code: "P", + keyid: "tracestracktopo", + name: I18n.t("javascripts.map.base.tracestracktop_topo") + })); + } this.baseLayers.push(new L.OSM.OPNVKarte({ attribution: copyright + ". " + memomaps + ". " + terms, code: "O", diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 0ffd35e2c..0a0f5c67a 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -25,6 +25,10 @@ OSM = { THUNDERFOREST_KEY: <%= Settings.thunderforest_key.to_json %>, <% end %> +<% if Settings.key?(:tracestrack_key) %> + TRACESTRACK_KEY: <%= Settings.tracestrack_key.to_json %>, +<% end %> + MARKER_GREEN: <%= image_path("marker-green.png").to_json %>, MARKER_RED: <%= image_path("marker-red.png").to_json %>, diff --git a/config/initializers/secure_headers.rb b/config/initializers/secure_headers.rb index e710019da..778b5b827 100644 --- a/config/initializers/secure_headers.rb +++ b/config/initializers/secure_headers.rb @@ -7,7 +7,7 @@ csp_policy = { :form_action => %w['self'], :frame_ancestors => %w['self'], :frame_src => %w['self'], - :img_src => %w['self' data: www.gravatar.com *.wp.com tile.openstreetmap.org *.tile.openstreetmap.org *.tile.thunderforest.com tileserver.memomaps.de *.openstreetmap.fr], + :img_src => %w['self' data: www.gravatar.com *.wp.com tile.openstreetmap.org *.tile.openstreetmap.org *.tile.thunderforest.com tileserver.memomaps.de tile.tracestrack.com *.openstreetmap.fr], :manifest_src => %w['self'], :media_src => %w['none'], :object_src => %w['self'], diff --git a/config/locales/en.yml b/config/locales/en.yml index ec845dc7c..530dad207 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2966,6 +2966,7 @@ en: cyclosm: CyclOSM cycle_map: Cycle Map transport_map: Transport Map + tracestracktop_topo: Tracestrack Topo hot: Humanitarian opnvkarte: ÖPNVKarte layers: @@ -2986,6 +2987,8 @@ en: andy_allan: Andy Allan opnvkarte_credit: "Tiles courtesy of %{memomaps_link}" memomaps: MeMoMaps + tracestrack_credit: "Tiles courtesy of %{tracestrack_link}" + tracestrack: Tracestrack hotosm_credit: "Tiles style by %{hotosm_link} hosted by %{osm_france_link}" hotosm_name: Humanitarian OpenStreetMap Team site: diff --git a/config/settings.yml b/config/settings.yml index 3ea298efc..e228247e0 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -117,6 +117,8 @@ fossgis_valhalla_url: "https://valhalla1.openstreetmap.de/route" #wikipedia_auth_secret: "" # Thunderforest authentication details #thunderforest_key: "" +# Tracestrack authentication details +#tracestrack_key: "" # Key for generating TOTP tokens #totp_key: "" # Enforce Content-Security-Policy diff --git a/vendor/assets/leaflet/leaflet.osm.js b/vendor/assets/leaflet/leaflet.osm.js index 6e8e20ba6..0e51f3408 100644 --- a/vendor/assets/leaflet/leaflet.osm.js +++ b/vendor/assets/leaflet/leaflet.osm.js @@ -61,6 +61,14 @@ L.OSM.HOT = L.OSM.TileLayer.extend({ } }); +L.OSM.TracestrackTopo = L.OSM.TileLayer.extend({ + options: { + url: 'https://tile.tracestrack.com/topo__/{z}/{x}/{y}.png?key={apikey}', + maxZoom: 19, + attribution: '© OpenStreetMap contributors. Tiles courtesy of Tracestrack Maps' + } +}); + L.OSM.GPS = L.OSM.TileLayer.extend({ options: { url: 'https://gps.tile.openstreetmap.org/lines/{z}/{x}/{y}.png', -- 2.39.5