From: Anton Khorev Date: Thu, 10 Aug 2023 00:02:02 +0000 (+0300) Subject: Disable show home location button if close enough to map center X-Git-Tag: live~1556^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/2a32a0427b6d0b496d3a1bd07326b94ec4987de1?ds=sidebyside Disable show home location button if close enough to map center --- diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 8f588cbfd..c0afd6b8d 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -64,6 +64,11 @@ $(document).ready(function () { deleted_lat = null; deleted_lon = null; respondToHomeUpdate(); + }).on("moveend", function () { + var lat = $("#home_lat").val(), + lon = $("#home_lon").val(); + + $("#home_show").prop("disabled", isCloseEnoughToMapCenter(lat, lon)); }); $("#home_lat, #home_lon").on("input", function () { @@ -125,6 +130,13 @@ $(document).ready(function () { } } + function isCloseEnoughToMapCenter(lat, lon) { + var inputPt = map.latLngToContainerPoint([lat, lon]), + centerPt = map.latLngToContainerPoint(map.getCenter()); + + return centerPt.distanceTo(inputPt) < 10; + } + function updateAuthUID() { var provider = $("select#user_auth_provider").val(); diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb index ff55a0665..cac657ff1 100644 --- a/app/views/profiles/edit.html.erb +++ b/app/views/profiles/edit.html.erb @@ -47,7 +47,7 @@ <%= f.text_field :home_lat, :wrapper_class => "col-sm-4", :id => "home_lat" %> <%= f.text_field :home_lon, :wrapper_class => "col-sm-4", :id => "home_lon" %>
- +