From: Tom Hughes Date: Sun, 13 Apr 2025 09:38:39 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/5921' X-Git-Tag: live~74 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/0551a4e7f627dfa962cc32bfc3740f5cfdf42770?hp=570206dadaf90709d53b2ed848af413b60dd7b0a Merge remote-tracking branch 'upstream/pull/5921' --- diff --git a/app/assets/javascripts/leaflet.key.js b/app/assets/javascripts/leaflet.key.js index a5d7acb43..b432bcf8f 100644 --- a/app/assets/javascripts/leaflet.key.js +++ b/app/assets/javascripts/leaflet.key.js @@ -27,7 +27,7 @@ L.OSM.key = function (options) { } function updateButton() { - const disabled = OSM.LAYERS_WITH_MAP_KEY.indexOf(map.getMapBaseLayerId()) === -1; + const disabled = !map.getMapBaseLayer().options.hasLegend; button .toggleClass("disabled", disabled) .attr("data-bs-original-title", diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index d73d1c163..31f92da84 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -27,8 +27,7 @@ OSM = { DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>, - LAYER_DEFINITIONS: <%= MapLayers::full_definitions("config/layers.yml").to_json %>, - LAYERS_WITH_MAP_KEY: <%= YAML.load_file(Rails.root.join("config/key.yml")).keys.to_json %>, + LAYER_DEFINITIONS: <%= MapLayers::full_definitions("config/layers.yml", :legends => "config/key.yml").to_json %>, MARKER_BLUE: <%= image_path("marker-blue.png").to_json %>, MARKER_GREEN: <%= image_path("marker-green.png").to_json %>, diff --git a/lib/map_layers.rb b/lib/map_layers.rb index 8a1bdea79..f0727ed92 100644 --- a/lib/map_layers.rb +++ b/lib/map_layers.rb @@ -1,5 +1,6 @@ module MapLayers - def self.full_definitions(layers_filename) + def self.full_definitions(layers_filename, legends: nil) + legended_layers = YAML.load_file(Rails.root.join(legends)).keys if legends YAML.load_file(Rails.root.join(layers_filename)) .reject { |layer| layer["apiKeyId"] && !Settings[layer["apiKeyId"]] } .map do |layer| @@ -7,6 +8,7 @@ module MapLayers layer["apikey"] = Settings[layer["apiKeyId"]] layer.delete "apiKeyId" end + layer["hasLegend"] = true if legended_layers&.include?(layer["layerId"]) layer end end diff --git a/test/system/search_test.rb b/test/system/search_test.rb index bf05f9212..0292e67f0 100644 --- a/test/system/search_test.rb +++ b/test/system/search_test.rb @@ -1,7 +1,13 @@ require "application_system_test_case" class SearchTest < ApplicationSystemTestCase - test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do + def setup + stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?}) + .to_return(:status => 404) + + stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?}) + .to_return(:status => 404) + stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$}) .to_return(:status => 400, :body => <<-BODY) @@ -27,7 +33,9 @@ class SearchTest < ApplicationSystemTestCase BODY + end + test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do visit "/#map=15/51.76320/-0.00760" assert_field "Search", :with => "" @@ -37,28 +45,28 @@ class SearchTest < ApplicationSystemTestCase assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom" end - test "query search link sets search input value" do - stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?}) - .to_return(:status => 404) + test "'Show address' from context menu makes reverse geocoding request with zoom" do + visit "/#map=15/51.76320/-0.00760" + + find_by_id("map").right_click + click_on "Show address" + assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom" + end + + test "query search link sets search input value" do visit search_path(:query => "2.341, 7.896") assert_field "Search", :with => "2.341, 7.896" end test "latlon search link sets search input value" do - stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?}) - .to_return(:status => 404) - visit search_path(:lat => "4.321", :lon => "9.876") assert_field "Search", :with => "4.321, 9.876" end test "search adds viewbox param to Nominatim link" do - stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?}) - .to_return(:status => 404) - visit "/" fill_in "query", :with => "paris" @@ -68,9 +76,6 @@ class SearchTest < ApplicationSystemTestCase end test "search adds zoom param to reverse Nominatim link" do - stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?}) - .to_return(:status => 404) - visit "/#map=7/1.234/6.789" fill_in "query", :with => "60 30"