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

View file

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