From: Anton Khorev Date: Wed, 9 Apr 2025 09:15:49 +0000 (+0300) Subject: Make reverse geocoding request with zoom using 'Where is this?' X-Git-Tag: live~53^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/40a942f5e549a815d9ab276c86ef1291023b162a?hp=-c Make reverse geocoding request with zoom using 'Where is this?' --- 40a942f5e549a815d9ab276c86ef1291023b162a diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index 05a4c449a..84f0d3ab4 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -33,9 +33,10 @@ OSM.Search = function (map) { $(".describe_location").on("click", function (e) { e.preventDefault(); $("header").addClass("closed"); - const [lat, lon] = OSM.cropLocation(map.getCenter(), map.getZoom()); + const zoom = map.getZoom(); + const [lat, lon] = OSM.cropLocation(map.getCenter(), zoom); - OSM.router.route("/search?" + new URLSearchParams({ lat, lon })); + OSM.router.route("/search?" + new URLSearchParams({ lat, lon, zoom })); }); $("#sidebar_content") diff --git a/test/system/search_test.rb b/test/system/search_test.rb index 992d0b800..bf05f9212 100644 --- a/test/system/search_test.rb +++ b/test/system/search_test.rb @@ -1,15 +1,40 @@ require "application_system_test_case" class SearchTest < ApplicationSystemTestCase - test "click on 'where is this' sets search input value" do - stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?}) - .to_return(:status => 404) - - visit "/#map=7/1.234/6.789" + test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do + stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$}) + .to_return(:status => 400, :body => <<-BODY) + + + 400 + Parameter 'zoom' must be a number. + + BODY + + stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$}) + .to_return(:status => 200, :body => <<-BODY) + + + Broxbourne, Hertfordshire, East of England, England, United Kingdom + + Broxbourne + Broxbourne + Hertfordshire + East of England + England + United Kingdom + gb + + + BODY + + visit "/#map=15/51.76320/-0.00760" assert_field "Search", :with => "" click_on "Where is this?" - assert_field "Search", :with => "1.234, 6.789" + + assert_field "Search", :with => "51.76320, -0.00760" + assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom" end test "query search link sets search input value" do