Merge remote-tracking branch 'upstream/pull/5581'
This commit is contained in:
commit
8f387236ce
9 changed files with 59 additions and 103 deletions
|
@ -4,13 +4,10 @@ OSM.initializeContextMenu = function (map) {
|
|||
map.contextmenu.addItem({
|
||||
text: I18n.t("javascripts.context.directions_from"),
|
||||
callback: function directionsFromHere(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const latlng = OSM.cropLocation(e.latlng, map.getZoom());
|
||||
|
||||
OSM.router.route("/directions?" + Qs.stringify({
|
||||
from: lat + "," + lng,
|
||||
from: latlng.join(","),
|
||||
to: getDirectionsEndpointCoordinatesFromInput($("#route_to"))
|
||||
}));
|
||||
}
|
||||
|
@ -19,14 +16,11 @@ OSM.initializeContextMenu = function (map) {
|
|||
map.contextmenu.addItem({
|
||||
text: I18n.t("javascripts.context.directions_to"),
|
||||
callback: function directionsToHere(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const latlng = OSM.cropLocation(e.latlng, map.getZoom());
|
||||
|
||||
OSM.router.route("/directions?" + Qs.stringify({
|
||||
from: getDirectionsEndpointCoordinatesFromInput($("#route_from")),
|
||||
to: lat + "," + lng
|
||||
to: latlng.join(",")
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -34,36 +28,27 @@ OSM.initializeContextMenu = function (map) {
|
|||
map.contextmenu.addItem({
|
||||
text: I18n.t("javascripts.context.add_note"),
|
||||
callback: function addNoteHere(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
|
||||
|
||||
OSM.router.route("/note/new?lat=" + lat + "&lon=" + lng);
|
||||
OSM.router.route("/note/new?" + Qs.stringify({ lat, lon }));
|
||||
}
|
||||
});
|
||||
|
||||
map.contextmenu.addItem({
|
||||
text: I18n.t("javascripts.context.show_address"),
|
||||
callback: function describeLocation(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom()).map(encodeURIComponent);
|
||||
|
||||
OSM.router.route("/search?lat=" + encodeURIComponent(lat) + "&lon=" + encodeURIComponent(lng));
|
||||
OSM.router.route("/search?" + Qs.stringify({ lat, lon }));
|
||||
}
|
||||
});
|
||||
|
||||
map.contextmenu.addItem({
|
||||
text: I18n.t("javascripts.context.query_features"),
|
||||
callback: function queryFeatures(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
|
||||
|
||||
OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
|
||||
OSM.router.route("/query?" + Qs.stringify({ lat, lon }));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
};
|
||||
|
||||
function markerDragListener(e) {
|
||||
var latlng = convertLatLngToZoomPrecision(e.target.getLatLng());
|
||||
const latlng = L.latLng(OSM.cropLocation(e.target.getLatLng(), map.getZoom()));
|
||||
|
||||
setLatLng(latlng);
|
||||
setInputValueFromLatLng(latlng);
|
||||
|
@ -109,11 +109,5 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -116,18 +116,14 @@ OSM.Directions = function (map) {
|
|||
// Cancel any route that is already in progress
|
||||
if (routeRequest) routeRequest.abort();
|
||||
|
||||
var o = endpoints[0].latlng,
|
||||
d = endpoints[1].latlng;
|
||||
const points = endpoints.map(p => p.latlng);
|
||||
|
||||
if (!o || !d) return;
|
||||
if (!points[0] || !points[1]) return;
|
||||
$("header").addClass("closed");
|
||||
|
||||
var precision = OSM.zoomPrecision(map.getZoom());
|
||||
|
||||
OSM.router.replace("/directions?" + Qs.stringify({
|
||||
engine: chosenEngine.id,
|
||||
route: o.lat.toFixed(precision) + "," + o.lng.toFixed(precision) + ";" +
|
||||
d.lat.toFixed(precision) + "," + d.lng.toFixed(precision)
|
||||
route: points.map(p => OSM.cropLocation(p, map.getZoom()).join()).join(";")
|
||||
}));
|
||||
|
||||
// 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());
|
||||
map.setSidebarOverlaid(false);
|
||||
|
||||
routeRequest = chosenEngine.getRoute([o, d], function (err, route) {
|
||||
routeRequest = chosenEngine.getRoute(points, function (err, route) {
|
||||
routeRequest = null;
|
||||
|
||||
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
|
||||
pt.y += 20;
|
||||
var ll = map.containerPointToLatLng(pt);
|
||||
var precision = OSM.zoomPrecision(map.getZoom());
|
||||
var value = ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision);
|
||||
var llWithPrecision = L.latLng(ll.lat.toFixed(precision), ll.lng.toFixed(precision));
|
||||
endpoints[type === "from" ? 0 : 1].setValue(value, llWithPrecision);
|
||||
const llWithPrecision = OSM.cropLocation(ll, map.getZoom());
|
||||
endpoints[type === "from" ? 0 : 1].setValue(llWithPrecision.join(", "), llWithPrecision);
|
||||
});
|
||||
|
||||
endpoints[0].enable();
|
||||
|
|
|
@ -36,16 +36,16 @@ OSM.Export = function (map) {
|
|||
}
|
||||
|
||||
function setBounds(bounds) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom());
|
||||
$("#minlon").val(bounds.getWest().toFixed(precision));
|
||||
$("#minlat").val(bounds.getSouth().toFixed(precision));
|
||||
$("#maxlon").val(bounds.getEast().toFixed(precision));
|
||||
$("#maxlat").val(bounds.getNorth().toFixed(precision));
|
||||
const truncated = [bounds.getSouthWest(), bounds.getNorthEast()]
|
||||
.map(c => OSM.cropLocation(c, map.getZoom()));
|
||||
$("#minlon").val(truncated[0][1]);
|
||||
$("#minlat").val(truncated[0][0]);
|
||||
$("#maxlon").val(truncated[1][1]);
|
||||
$("#maxlat").val(truncated[1][0]);
|
||||
|
||||
$("#export_overpass").attr("href",
|
||||
"https://overpass-api.de/api/map?bbox=" +
|
||||
$("#minlon").val() + "," + $("#minlat").val() + "," +
|
||||
$("#maxlon").val() + "," + $("#maxlat").val());
|
||||
truncated.map(p => p.reverse()).join());
|
||||
}
|
||||
|
||||
function validateControls() {
|
||||
|
|
|
@ -272,18 +272,18 @@ OSM.Query = function (map) {
|
|||
function queryOverpass(lat, lng) {
|
||||
var latlng = L.latLng(lat, lng).wrap(),
|
||||
bounds = map.getBounds().wrap(),
|
||||
precision = OSM.zoomPrecision(map.getZoom()),
|
||||
bbox = bounds.getSouth().toFixed(precision) + "," +
|
||||
bounds.getWest().toFixed(precision) + "," +
|
||||
bounds.getNorth().toFixed(precision) + "," +
|
||||
bounds.getEast().toFixed(precision),
|
||||
radius = 10 * Math.pow(1.5, 19 - map.getZoom()),
|
||||
around = "around:" + radius + "," + lat + "," + lng,
|
||||
nodes = "node(" + around + ")",
|
||||
ways = "way(" + around + ")",
|
||||
relations = "relation(" + around + ")",
|
||||
nearby = "(" + nodes + ";" + ways + ";);out tags geom(" + bbox + ");" + relations + ";out geom(" + bbox + ");",
|
||||
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids geom(" + bbox + ");relation(pivot.a);out tags bb;";
|
||||
zoom = map.getZoom(),
|
||||
bbox = [bounds.getSouthWest(), bounds.getNorthEast()]
|
||||
.map(c => OSM.cropLocation(c, zoom))
|
||||
.join(),
|
||||
geombbox = "geom(" + bbox + ");",
|
||||
radius = 10 * Math.pow(1.5, 19 - zoom),
|
||||
around = "(around:" + radius + "," + lat + "," + lng + ")",
|
||||
nodes = "node" + around,
|
||||
ways = "way" + around,
|
||||
relations = "relation" + around,
|
||||
nearby = "(" + nodes + ";" + ways + ";);out tags " + geombbox + relations + ";out " + geombbox,
|
||||
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")
|
||||
.hide();
|
||||
|
@ -299,12 +299,9 @@ OSM.Query = function (map) {
|
|||
}
|
||||
|
||||
function clickHandler(e) {
|
||||
var precision = OSM.zoomPrecision(map.getZoom()),
|
||||
latlng = e.latlng.wrap(),
|
||||
lat = latlng.lat.toFixed(precision),
|
||||
lng = latlng.lng.toFixed(precision);
|
||||
const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
|
||||
|
||||
OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
|
||||
OSM.router.route("/query?" + Qs.stringify({ lat, lon }));
|
||||
}
|
||||
|
||||
function enableQueryMode() {
|
||||
|
|
|
@ -33,12 +33,9 @@ OSM.Search = function (map) {
|
|||
$(".describe_location").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
$("header").addClass("closed");
|
||||
var center = map.getCenter().wrap(),
|
||||
precision = OSM.zoomPrecision(map.getZoom()),
|
||||
lat = center.lat.toFixed(precision),
|
||||
lng = center.lng.toFixed(precision);
|
||||
const [lat, lon] = OSM.cropLocation(map.getCenter(), map.getZoom()).map(encodeURIComponent);
|
||||
|
||||
OSM.router.route("/search?lat=" + encodeURIComponent(lat) + "&lon=" + encodeURIComponent(lng));
|
||||
OSM.router.route("/search?" + Qs.stringify({ lat, lon }));
|
||||
});
|
||||
|
||||
$("#sidebar_content")
|
||||
|
|
|
@ -152,13 +152,10 @@ L.OSM.Map = L.Map.extend({
|
|||
},
|
||||
|
||||
getUrl: function (marker) {
|
||||
var precision = OSM.zoomPrecision(this.getZoom()),
|
||||
params = {};
|
||||
const params = {};
|
||||
|
||||
if (marker && this.hasLayer(marker)) {
|
||||
var latLng = marker.getLatLng().wrap();
|
||||
params.mlat = latLng.lat.toFixed(precision);
|
||||
params.mlon = latLng.lng.toFixed(precision);
|
||||
[params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom());
|
||||
}
|
||||
|
||||
var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
|
||||
|
@ -236,21 +233,14 @@ L.OSM.Map = L.Map.extend({
|
|||
},
|
||||
|
||||
getGeoUri: function (marker) {
|
||||
var precision = OSM.zoomPrecision(this.getZoom()),
|
||||
latLng,
|
||||
params = {};
|
||||
let latLng = this.getCenter();
|
||||
const zoom = this.getZoom();
|
||||
|
||||
if (marker && this.hasLayer(marker)) {
|
||||
latLng = marker.getLatLng().wrap();
|
||||
} else {
|
||||
latLng = this.getCenter();
|
||||
latLng = marker.getLatLng();
|
||||
}
|
||||
|
||||
params.lat = latLng.lat.toFixed(precision);
|
||||
params.lon = latLng.lng.toFixed(precision);
|
||||
params.zoom = this.getZoom();
|
||||
|
||||
return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom;
|
||||
return `geo:${OSM.cropLocation(latLng, zoom).join(",")}?z=${zoom}`;
|
||||
},
|
||||
|
||||
addObject: function (object, callback) {
|
||||
|
|
|
@ -190,13 +190,9 @@ OSM = {
|
|||
layers = args.layers || "";
|
||||
}
|
||||
|
||||
center = center.wrap();
|
||||
layers = layers.replace("M", "");
|
||||
|
||||
var precision = OSM.zoomPrecision(zoom),
|
||||
hash = "#map=" + zoom +
|
||||
"/" + center.lat.toFixed(precision) +
|
||||
"/" + center.lng.toFixed(precision);
|
||||
let hash = "#map=" + [zoom, ...OSM.cropLocation(center, zoom)].join("/");
|
||||
|
||||
if (layers) {
|
||||
hash += "&layers=" + layers;
|
||||
|
@ -211,11 +207,16 @@ OSM = {
|
|||
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) {
|
||||
var center = map.getCenter().wrap(),
|
||||
zoom = map.getZoom(),
|
||||
precision = OSM.zoomPrecision(zoom);
|
||||
return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join("|");
|
||||
const zoom = map.getZoom(),
|
||||
center = OSM.cropLocation(map.getCenter(), zoom).reverse();
|
||||
return [...center, zoom, map.getLayersCode()].join("|");
|
||||
},
|
||||
|
||||
distance: function (latlng1, latlng2) {
|
||||
|
|
|
@ -64,12 +64,10 @@ $(document).ready(function () {
|
|||
map.on("click", function (e) {
|
||||
if (!$("#updatehome").is(":checked")) return;
|
||||
|
||||
var zoom = map.getZoom(),
|
||||
precision = OSM.zoomPrecision(zoom),
|
||||
location = e.latlng.wrap();
|
||||
const [lat, lon] = OSM.cropLocation(e.latlng);
|
||||
|
||||
$("#home_lat").val(location.lat.toFixed(precision));
|
||||
$("#home_lon").val(location.lng.toFixed(precision));
|
||||
$("#home_lat").val(lat);
|
||||
$("#home_lon").val(lon);
|
||||
|
||||
deleted_lat = null;
|
||||
deleted_lon = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue