$(".search_form").on("submit", function (e) {
e.preventDefault();
$("header").addClass("closed");
- const query = $(this).find("input[name=query]").val();
- let search = "/";
- if (query) search = "/search?" + new URLSearchParams({ query });
+ const params = new URLSearchParams({
+ query: this.elements.query.value,
+ zoom: map.getZoom(),
+ minlon: map.getBounds().getWest(),
+ minlat: map.getBounds().getSouth(),
+ maxlon: map.getBounds().getEast(),
+ maxlat: map.getBounds().getNorth()
+ });
+ const search = params.get("query") ? `/search?${params}` : "/";
OSM.router.route(search + OSM.formatHash(map));
});
const entry = $(this);
fetch(entry.data("href"), {
method: "POST",
- body: new URLSearchParams({
- zoom: map.getZoom(),
- minlon: map.getBounds().getWest(),
- minlat: map.getBounds().getSouth(),
- maxlon: map.getBounds().getEast(),
- maxlat: map.getBounds().getNorth(),
- ...OSM.csrf
- })
+ body: new URLSearchParams(OSM.csrf)
})
.then(response => response.text())
.then(function (html) {
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"
+ click_on "Go"
+
+ assert_link "OpenStreetMap Nominatim", :href => /&viewbox=/
+ 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"
+ click_on "Go"
+
+ assert_link "OpenStreetMap Nominatim", :href => /&zoom=7/
+ end
end