]> git.openstreetmap.org Git - rails.git/commitdiff
Disable show home location button if close enough to map center
authorAnton Khorev <tony29@yandex.ru>
Thu, 10 Aug 2023 00:02:02 +0000 (03:02 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 11 Aug 2023 18:47:13 +0000 (21:47 +0300)
app/assets/javascripts/user.js
app/views/profiles/edit.html.erb

index 8f588cbfdf49fe75666d30f40c5a742b3f9f1bd8..c0afd6b8d88bd01169e55a26f690b8a402e85b12 100644 (file)
@@ -64,6 +64,11 @@ $(document).ready(function () {
         deleted_lat = null;
         deleted_lon = null;
         respondToHomeUpdate();
         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 () {
       });
 
       $("#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();
 
   function updateAuthUID() {
     var provider = $("select#user_auth_provider").val();
 
index ff55a0665ea7c13328f09610901a46bba8134d08..cac657ff1a91cf500c9ee469ef9d8b276082fe55 100644 (file)
@@ -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" %>
       <div class="col-sm-4 pt-2 align-self-end">
       <%= 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" %>
       <div class="col-sm-4 pt-2 align-self-end">
-        <button type="button" id="home_show" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %>><%= t ".show" %></button>
+        <button type="button" id="home_show" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %> disabled><%= t ".show" %></button>
         <button type="button" id="home_delete" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %>><%= t ".delete" %></button>
         <button type="button" id="home_undelete" class="btn btn-outline-primary" hidden><%= t ".undelete" %></button>
       </div>
         <button type="button" id="home_delete" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %>><%= t ".delete" %></button>
         <button type="button" id="home_undelete" class="btn btn-outline-primary" hidden><%= t ".undelete" %></button>
       </div>