Skip to content

Commit

Permalink
Save lat/lon to input data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Aug 20, 2024
1 parent bc2937f commit 2a2970d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/assets/javascripts/index/directions-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch

endpoint.setValue = function (value, latlng) {
endpoint.value = value;
delete endpoint.latlng;
removeLatLng();
input.removeClass("is-invalid");
input.val(value);

Expand Down Expand Up @@ -85,12 +85,22 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
}

function setLatLng(ll) {
input
.attr("data-lat", ll.lat)
.attr("data-lon", ll.lng);
endpoint.latlng = ll;
endpoint.marker
.setLatLng(ll)
.addTo(map);
}

function removeLatLng() {
input
.removeAttr("data-lat")
.removeAttr("data-lon");
delete endpoint.latlng;
}

function setInputValueFromLatLng(latlng) {
input.val(latlng.lat + ", " + latlng.lng);
}
Expand Down

0 comments on commit 2a2970d

Please sign in to comment.