OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, changeCallback) {
- var endpoint = {};
+ const endpoint = {};
endpoint.marker = L.marker([0, 0], {
icon: L.icon({
function inputChangeListener(e) {
// make text the same in both text boxes
- var value = e.target.value;
+ const value = e.target.value;
endpoint.setValue(value);
}
delete endpoint.geocodeRequest;
input.removeClass("is-invalid");
- var coordinatesMatch = value.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/);
- var latlng = coordinatesMatch && L.latLng(coordinatesMatch[1], coordinatesMatch[2]);
+ const coordinatesMatch = value.match(/^\s*([+-]?\d+(?:\.\d*)?)(?:\s+|\s*[/,]\s*)([+-]?\d+(?:\.\d*)?)\s*$/);
+ const latlng = coordinatesMatch && L.latLng(coordinatesMatch[1], coordinatesMatch[2]);
if (latlng && endpoint.cachedReverseGeocode && endpoint.cachedReverseGeocode.latlng.equals(latlng)) {
setLatLng(latlng);
};
endpoint.swapCachedReverseGeocodes = function (otherEndpoint) {
- var g0 = endpoint.cachedReverseGeocode;
- var g1 = otherEndpoint.cachedReverseGeocode;
+ const g0 = endpoint.cachedReverseGeocode;
+ const g1 = otherEndpoint.cachedReverseGeocode;
delete endpoint.cachedReverseGeocode;
delete otherEndpoint.cachedReverseGeocode;
if (g0) otherEndpoint.cachedReverseGeocode = g0;
};
function getGeocode() {
- var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
- var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox;
+ const viewbox = map.getBounds().toBBoxString(), // <sw lon>,<sw lat>,<ne lon>,<ne lat>
+ geocodeUrl = OSM.NOMINATIM_URL + "search?" + new URLSearchParams({ q: endpoint.value, format: "json", viewbox });
endpoint.geocodeRequest = $.getJSON(geocodeUrl, function (json) {
delete endpoint.geocodeRequest;
}
function getReverseGeocode() {
- var latlng = endpoint.latlng.clone();
- var reverseGeocodeUrl = OSM.NOMINATIM_URL + "reverse?lat=" + latlng.lat + "&lon=" + latlng.lng + "&format=json";
+ const latlng = endpoint.latlng.clone(),
+ { lat, lng } = latlng,
+ reverseGeocodeUrl = OSM.NOMINATIM_URL + "reverse?" + new URLSearchParams({ lat, lon: lng, format: "json" });
endpoint.geocodeRequest = $.getJSON(reverseGeocodeUrl, function (json) {
delete endpoint.geocodeRequest;