Load note from edit link with remote control

This commit is contained in:
Anton Khorev 2022-10-06 00:42:04 +03:00
parent d8c1b28fde
commit a419f8890a
2 changed files with 28 additions and 19 deletions

View file

@ -246,8 +246,8 @@ $(document).ready(function () {
});
function remoteEditHandler(bbox, object) {
var loaded = false,
url,
var remoteEditHost = "http://127.0.0.1:8111",
osmHost = location.protocol + "//" + location.host,
query = {
left: bbox.getWest() - 0.0001,
top: bbox.getNorth() + 0.0001,
@ -255,25 +255,31 @@ $(document).ready(function () {
bottom: bbox.getSouth() - 0.0001
};
url = "http://127.0.0.1:8111/load_and_zoom?";
if (object && object.type !== "note") query.select = object.type + object.id; // can't select notes
sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + Qs.stringify(query), function () {
if (object && object.type === "note") {
var noteQuery = { url: osmHost + OSM.apiUrl(object) };
sendRemoteEditCommand(remoteEditHost + "/import?" + Qs.stringify(noteQuery));
}
});
if (object) query.select = object.type + object.id;
var iframe = $("<iframe>")
.hide()
.appendTo("body")
.attr("src", url + Qs.stringify(query))
.on("load", function () {
$(this).remove();
loaded = true;
});
setTimeout(function () {
if (!loaded) {
function sendRemoteEditCommand(url, callback) {
var iframe = $("<iframe>");
var timeoutId = setTimeout(function () {
alert(I18n.t("site.index.remote_failed"));
iframe.remove();
}
}, 1000);
}, 5000);
iframe
.hide()
.appendTo("body")
.attr("src", url)
.on("load", function () {
clearTimeout(timeoutId);
iframe.remove();
if (callback) callback();
});
}
return false;
}

View file

@ -37,7 +37,8 @@ OSM = {
SEARCHING: <%= image_path("searching.gif").to_json %>,
apiUrl: function (object) {
var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
var apiType = object.type === "note" ? "notes" : object.type;
var url = "/api/" + OSM.API_VERSION + "/" + apiType + "/" + object.id;
if (object.type === "way" || object.type === "relation") {
url += "/full";
@ -85,6 +86,8 @@ OSM = {
mapParams.object = {type: 'way', id: parseInt(params.way)};
} else if (params.relation) {
mapParams.object = {type: 'relation', id: parseInt(params.relation)};
} else if (params.note) {
mapParams.object = {type: 'note', id: parseInt(params.note)};
}
var hash = OSM.parseHash(location.hash);