Merge remote-tracking branch 'upstream/pull/5581'

This commit is contained in:
Tom Hughes 2025-02-02 10:11:23 +00:00
commit 8f387236ce
9 changed files with 59 additions and 103 deletions

View file

@ -4,13 +4,10 @@ OSM.initializeContextMenu = function (map) {
map.contextmenu.addItem({ map.contextmenu.addItem({
text: I18n.t("javascripts.context.directions_from"), text: I18n.t("javascripts.context.directions_from"),
callback: function directionsFromHere(e) { callback: function directionsFromHere(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const latlng = OSM.cropLocation(e.latlng, map.getZoom());
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/directions?" + Qs.stringify({ OSM.router.route("/directions?" + Qs.stringify({
from: lat + "," + lng, from: latlng.join(","),
to: getDirectionsEndpointCoordinatesFromInput($("#route_to")) to: getDirectionsEndpointCoordinatesFromInput($("#route_to"))
})); }));
} }
@ -19,14 +16,11 @@ OSM.initializeContextMenu = function (map) {
map.contextmenu.addItem({ map.contextmenu.addItem({
text: I18n.t("javascripts.context.directions_to"), text: I18n.t("javascripts.context.directions_to"),
callback: function directionsToHere(e) { callback: function directionsToHere(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const latlng = OSM.cropLocation(e.latlng, map.getZoom());
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/directions?" + Qs.stringify({ OSM.router.route("/directions?" + Qs.stringify({
from: getDirectionsEndpointCoordinatesFromInput($("#route_from")), from: getDirectionsEndpointCoordinatesFromInput($("#route_from")),
to: lat + "," + lng to: latlng.join(",")
})); }));
} }
}); });
@ -34,36 +28,27 @@ OSM.initializeContextMenu = function (map) {
map.contextmenu.addItem({ map.contextmenu.addItem({
text: I18n.t("javascripts.context.add_note"), text: I18n.t("javascripts.context.add_note"),
callback: function addNoteHere(e) { callback: function addNoteHere(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/note/new?lat=" + lat + "&lon=" + lng); OSM.router.route("/note/new?" + Qs.stringify({ lat, lon }));
} }
}); });
map.contextmenu.addItem({ map.contextmenu.addItem({
text: I18n.t("javascripts.context.show_address"), text: I18n.t("javascripts.context.show_address"),
callback: function describeLocation(e) { callback: function describeLocation(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom()).map(encodeURIComponent);
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/search?lat=" + encodeURIComponent(lat) + "&lon=" + encodeURIComponent(lng)); OSM.router.route("/search?" + Qs.stringify({ lat, lon }));
} }
}); });
map.contextmenu.addItem({ map.contextmenu.addItem({
text: I18n.t("javascripts.context.query_features"), text: I18n.t("javascripts.context.query_features"),
callback: function queryFeatures(e) { callback: function queryFeatures(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/query?lat=" + lat + "&lon=" + lng); OSM.router.route("/query?" + Qs.stringify({ lat, lon }));
} }
}); });

View file

@ -34,7 +34,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
}; };
function markerDragListener(e) { function markerDragListener(e) {
var latlng = convertLatLngToZoomPrecision(e.target.getLatLng()); const latlng = L.latLng(OSM.cropLocation(e.target.getLatLng(), map.getZoom()));
setLatLng(latlng); setLatLng(latlng);
setInputValueFromLatLng(latlng); setInputValueFromLatLng(latlng);
@ -109,11 +109,5 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
input.val(latlng.lat + ", " + latlng.lng); input.val(latlng.lat + ", " + latlng.lng);
} }
function convertLatLngToZoomPrecision(latlng) {
var precision = OSM.zoomPrecision(map.getZoom());
return L.latLng(latlng.lat.toFixed(precision), latlng.lng.toFixed(precision));
}
return endpoint; return endpoint;
}; };

View file

@ -116,18 +116,14 @@ OSM.Directions = function (map) {
// Cancel any route that is already in progress // Cancel any route that is already in progress
if (routeRequest) routeRequest.abort(); if (routeRequest) routeRequest.abort();
var o = endpoints[0].latlng, const points = endpoints.map(p => p.latlng);
d = endpoints[1].latlng;
if (!o || !d) return; if (!points[0] || !points[1]) return;
$("header").addClass("closed"); $("header").addClass("closed");
var precision = OSM.zoomPrecision(map.getZoom());
OSM.router.replace("/directions?" + Qs.stringify({ OSM.router.replace("/directions?" + Qs.stringify({
engine: chosenEngine.id, engine: chosenEngine.id,
route: o.lat.toFixed(precision) + "," + o.lng.toFixed(precision) + ";" + route: points.map(p => OSM.cropLocation(p, map.getZoom()).join()).join(";")
d.lat.toFixed(precision) + "," + d.lng.toFixed(precision)
})); }));
// copy loading item to sidebar and display it. we copy it, rather than // copy loading item to sidebar and display it. we copy it, rather than
@ -136,7 +132,7 @@ OSM.Directions = function (map) {
$("#sidebar_content").html($(".directions_form .loader_copy").html()); $("#sidebar_content").html($(".directions_form .loader_copy").html());
map.setSidebarOverlaid(false); map.setSidebarOverlaid(false);
routeRequest = chosenEngine.getRoute([o, d], function (err, route) { routeRequest = chosenEngine.getRoute(points, function (err, route) {
routeRequest = null; routeRequest = null;
if (err) { if (err) {
@ -285,10 +281,8 @@ OSM.Directions = function (map) {
var pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present var pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present
pt.y += 20; pt.y += 20;
var ll = map.containerPointToLatLng(pt); var ll = map.containerPointToLatLng(pt);
var precision = OSM.zoomPrecision(map.getZoom()); const llWithPrecision = OSM.cropLocation(ll, map.getZoom());
var value = ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision); endpoints[type === "from" ? 0 : 1].setValue(llWithPrecision.join(", "), llWithPrecision);
var llWithPrecision = L.latLng(ll.lat.toFixed(precision), ll.lng.toFixed(precision));
endpoints[type === "from" ? 0 : 1].setValue(value, llWithPrecision);
}); });
endpoints[0].enable(); endpoints[0].enable();

View file

@ -36,16 +36,16 @@ OSM.Export = function (map) {
} }
function setBounds(bounds) { function setBounds(bounds) {
var precision = OSM.zoomPrecision(map.getZoom()); const truncated = [bounds.getSouthWest(), bounds.getNorthEast()]
$("#minlon").val(bounds.getWest().toFixed(precision)); .map(c => OSM.cropLocation(c, map.getZoom()));
$("#minlat").val(bounds.getSouth().toFixed(precision)); $("#minlon").val(truncated[0][1]);
$("#maxlon").val(bounds.getEast().toFixed(precision)); $("#minlat").val(truncated[0][0]);
$("#maxlat").val(bounds.getNorth().toFixed(precision)); $("#maxlon").val(truncated[1][1]);
$("#maxlat").val(truncated[1][0]);
$("#export_overpass").attr("href", $("#export_overpass").attr("href",
"https://overpass-api.de/api/map?bbox=" + "https://overpass-api.de/api/map?bbox=" +
$("#minlon").val() + "," + $("#minlat").val() + "," + truncated.map(p => p.reverse()).join());
$("#maxlon").val() + "," + $("#maxlat").val());
} }
function validateControls() { function validateControls() {

View file

@ -272,18 +272,18 @@ OSM.Query = function (map) {
function queryOverpass(lat, lng) { function queryOverpass(lat, lng) {
var latlng = L.latLng(lat, lng).wrap(), var latlng = L.latLng(lat, lng).wrap(),
bounds = map.getBounds().wrap(), bounds = map.getBounds().wrap(),
precision = OSM.zoomPrecision(map.getZoom()), zoom = map.getZoom(),
bbox = bounds.getSouth().toFixed(precision) + "," + bbox = [bounds.getSouthWest(), bounds.getNorthEast()]
bounds.getWest().toFixed(precision) + "," + .map(c => OSM.cropLocation(c, zoom))
bounds.getNorth().toFixed(precision) + "," + .join(),
bounds.getEast().toFixed(precision), geombbox = "geom(" + bbox + ");",
radius = 10 * Math.pow(1.5, 19 - map.getZoom()), radius = 10 * Math.pow(1.5, 19 - zoom),
around = "around:" + radius + "," + lat + "," + lng, around = "(around:" + radius + "," + lat + "," + lng + ")",
nodes = "node(" + around + ")", nodes = "node" + around,
ways = "way(" + around + ")", ways = "way" + around,
relations = "relation(" + around + ")", relations = "relation" + around,
nearby = "(" + nodes + ";" + ways + ";);out tags geom(" + bbox + ");" + relations + ";out geom(" + bbox + ");", nearby = "(" + nodes + ";" + ways + ";);out tags " + geombbox + relations + ";out " + geombbox,
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids geom(" + bbox + ");relation(pivot.a);out tags bb;"; isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids " + geombbox + "relation(pivot.a);out tags bb;";
$("#sidebar_content .query-intro") $("#sidebar_content .query-intro")
.hide(); .hide();
@ -299,12 +299,9 @@ OSM.Query = function (map) {
} }
function clickHandler(e) { function clickHandler(e) {
var precision = OSM.zoomPrecision(map.getZoom()), const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/query?lat=" + lat + "&lon=" + lng); OSM.router.route("/query?" + Qs.stringify({ lat, lon }));
} }
function enableQueryMode() { function enableQueryMode() {

View file

@ -33,12 +33,9 @@ OSM.Search = function (map) {
$(".describe_location").on("click", function (e) { $(".describe_location").on("click", function (e) {
e.preventDefault(); e.preventDefault();
$("header").addClass("closed"); $("header").addClass("closed");
var center = map.getCenter().wrap(), const [lat, lon] = OSM.cropLocation(map.getCenter(), map.getZoom()).map(encodeURIComponent);
precision = OSM.zoomPrecision(map.getZoom()),
lat = center.lat.toFixed(precision),
lng = center.lng.toFixed(precision);
OSM.router.route("/search?lat=" + encodeURIComponent(lat) + "&lon=" + encodeURIComponent(lng)); OSM.router.route("/search?" + Qs.stringify({ lat, lon }));
}); });
$("#sidebar_content") $("#sidebar_content")

View file

@ -152,13 +152,10 @@ L.OSM.Map = L.Map.extend({
}, },
getUrl: function (marker) { getUrl: function (marker) {
var precision = OSM.zoomPrecision(this.getZoom()), const params = {};
params = {};
if (marker && this.hasLayer(marker)) { if (marker && this.hasLayer(marker)) {
var latLng = marker.getLatLng().wrap(); [params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom());
params.mlat = latLng.lat.toFixed(precision);
params.mlon = latLng.lng.toFixed(precision);
} }
var url = window.location.protocol + "//" + OSM.SERVER_URL + "/", var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
@ -236,21 +233,14 @@ L.OSM.Map = L.Map.extend({
}, },
getGeoUri: function (marker) { getGeoUri: function (marker) {
var precision = OSM.zoomPrecision(this.getZoom()), let latLng = this.getCenter();
latLng, const zoom = this.getZoom();
params = {};
if (marker && this.hasLayer(marker)) { if (marker && this.hasLayer(marker)) {
latLng = marker.getLatLng().wrap(); latLng = marker.getLatLng();
} else {
latLng = this.getCenter();
} }
params.lat = latLng.lat.toFixed(precision); return `geo:${OSM.cropLocation(latLng, zoom).join(",")}?z=${zoom}`;
params.lon = latLng.lng.toFixed(precision);
params.zoom = this.getZoom();
return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom;
}, },
addObject: function (object, callback) { addObject: function (object, callback) {

View file

@ -190,13 +190,9 @@ OSM = {
layers = args.layers || ""; layers = args.layers || "";
} }
center = center.wrap();
layers = layers.replace("M", ""); layers = layers.replace("M", "");
var precision = OSM.zoomPrecision(zoom), let hash = "#map=" + [zoom, ...OSM.cropLocation(center, zoom)].join("/");
hash = "#map=" + zoom +
"/" + center.lat.toFixed(precision) +
"/" + center.lng.toFixed(precision);
if (layers) { if (layers) {
hash += "&layers=" + layers; hash += "&layers=" + layers;
@ -211,11 +207,16 @@ OSM = {
return Math.ceil(Math.log10(pixels / degrees)); return Math.ceil(Math.log10(pixels / degrees));
}, },
cropLocation: function (latLng, zoom) {
const precision = OSM.zoomPrecision(zoom),
wrapped = latLng.wrap();
return [wrapped.lat, wrapped.lng].map(c => c.toFixed(precision));
},
locationCookie: function (map) { locationCookie: function (map) {
var center = map.getCenter().wrap(), const zoom = map.getZoom(),
zoom = map.getZoom(), center = OSM.cropLocation(map.getCenter(), zoom).reverse();
precision = OSM.zoomPrecision(zoom); return [...center, zoom, map.getLayersCode()].join("|");
return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join("|");
}, },
distance: function (latlng1, latlng2) { distance: function (latlng1, latlng2) {

View file

@ -64,12 +64,10 @@ $(document).ready(function () {
map.on("click", function (e) { map.on("click", function (e) {
if (!$("#updatehome").is(":checked")) return; if (!$("#updatehome").is(":checked")) return;
var zoom = map.getZoom(), const [lat, lon] = OSM.cropLocation(e.latlng);
precision = OSM.zoomPrecision(zoom),
location = e.latlng.wrap();
$("#home_lat").val(location.lat.toFixed(precision)); $("#home_lat").val(lat);
$("#home_lon").val(location.lng.toFixed(precision)); $("#home_lon").val(lon);
deleted_lat = null; deleted_lat = null;
deleted_lon = null; deleted_lon = null;