Disable show home location button if close enough to map center
This commit is contained in:
parent
2dbe4e6f88
commit
2a32a0427b
2 changed files with 13 additions and 1 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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">
|
||||
<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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue