});
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,
bottom: bbox.getSouth() - 0.0001
};
- url = "http://127.0.0.1:8111/load_and_zoom?";
-
- 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;
- });
+ 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));
+ }
+ });
- 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;
}
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";
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);