Merge remote-tracking branch 'upstream/pull/5099'
This commit is contained in:
commit
20f8fadd7b
3 changed files with 29 additions and 6 deletions
|
@ -11,7 +11,7 @@ OSM.initializeContextMenu = function (map) {
|
|||
|
||||
OSM.router.route("/directions?" + Qs.stringify({
|
||||
from: lat + "," + lng,
|
||||
to: $("#route_to").val()
|
||||
to: getDirectionsEndpointCoordinatesFromInput($("#route_to"))
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ OSM.initializeContextMenu = function (map) {
|
|||
lng = latlng.lng.toFixed(precision);
|
||||
|
||||
OSM.router.route("/directions?" + Qs.stringify({
|
||||
from: $("#route_from").val(),
|
||||
from: getDirectionsEndpointCoordinatesFromInput($("#route_from")),
|
||||
to: lat + "," + lng
|
||||
}));
|
||||
}
|
||||
|
@ -79,6 +79,14 @@ OSM.initializeContextMenu = function (map) {
|
|||
else map.contextmenu.enable();
|
||||
});
|
||||
|
||||
function getDirectionsEndpointCoordinatesFromInput(input) {
|
||||
if (input.attr("data-lat") && input.attr("data-lon")) {
|
||||
return input.attr("data-lat") + "," + input.attr("data-lon");
|
||||
} else {
|
||||
return $(input).val();
|
||||
}
|
||||
}
|
||||
|
||||
var updateMenu = function updateMenu() {
|
||||
map.contextmenu.setDisabled(2, map.getZoom() < 12);
|
||||
map.contextmenu.setDisabled(4, map.getZoom() < 14);
|
||||
|
|
|
@ -31,7 +31,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
};
|
||||
|
||||
function markerDragListener(e) {
|
||||
var latlng = e.target.getLatLng();
|
||||
var latlng = convertLatLngToZoomPrecision(e.target.getLatLng());
|
||||
|
||||
setLatLng(latlng);
|
||||
setInputValueFromLatLng(latlng);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -86,16 +86,30 @@ 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);
|
||||
}
|
||||
|
||||
function convertLatLngToZoomPrecision(latlng) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom());
|
||||
|
||||
input.val(latlng.lat.toFixed(precision) + ", " + latlng.lng.toFixed(precision));
|
||||
return L.latLng(latlng.lat.toFixed(precision), latlng.lng.toFixed(precision));
|
||||
}
|
||||
|
||||
return endpoint;
|
||||
|
|
|
@ -287,7 +287,8 @@ OSM.Directions = function (map) {
|
|||
var ll = map.containerPointToLatLng(pt);
|
||||
var precision = OSM.zoomPrecision(map.getZoom());
|
||||
var value = ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision);
|
||||
endpoints[type === "from" ? 0 : 1].setValue(value, ll);
|
||||
var llWithPrecision = L.latLng(ll.lat.toFixed(precision), ll.lng.toFixed(precision));
|
||||
endpoints[type === "from" ? 0 : 1].setValue(value, llWithPrecision);
|
||||
});
|
||||
|
||||
endpoints[0].enable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue