]> git.openstreetmap.org Git - rails.git/commitdiff
Make reverse geocoding request with zoom using 'Where is this?'
authorAnton Khorev <tony29@yandex.ru>
Wed, 9 Apr 2025 09:15:49 +0000 (12:15 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 9 Apr 2025 09:16:39 +0000 (12:16 +0300)
app/assets/javascripts/index/search.js
test/system/search_test.rb

index 05a4c449a26ca0f084b9b196297018c9ddbbc9e4..84f0d3ab47af361dfb91daff947ba0e79ed90299 100644 (file)
@@ -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")
index 992d0b8004f13c3b4ba0fc282d60c0b7e9ddece3..bf05f92122a2e098093148370edd50545b5ae60a 100644 (file)
@@ -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)
+        <?xml version="1.0" encoding="UTF-8"?>
+        <error>
+          <code>400</code>
+          <message>Parameter 'zoom' must be a number.</message>
+        </error>
+      BODY
+
+    stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$})
+      .to_return(:status => 200, :body => <<-BODY)
+        <?xml version="1.0" encoding="UTF-8"?>
+        <reversegeocode timestamp="Sun, 01 Mar 15 22:49:45 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="accept-language=&amp;lat=51.76320&amp;lon=-0.00760&amp;zoom=15">
+          <result place_id="150696" osm_type="node" osm_id="28825933" ref="Broxbourne" lat="51.7465723" lon="-0.0190782">Broxbourne, Hertfordshire, East of England, England, United Kingdom</result>
+          <addressparts>
+            <suburb>Broxbourne</suburb>
+            <city>Broxbourne</city>
+            <county>Hertfordshire</county>
+            <state_district>East of England</state_district>
+            <state>England</state>
+            <country>United Kingdom</country>
+            <country_code>gb</country_code>
+          </addressparts>
+        </reversegeocode>
+      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