Skip to content

Commit

Permalink
Add josm scheme link to edit menu
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Feb 6, 2025
1 parent e206dd5 commit 9ce8038
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
30 changes: 20 additions & 10 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,10 @@ $(document).ready(function () {
});

function remoteEditHandler(bbox, object) {
var remoteEditHost = "http://127.0.0.1:8111",
osmHost = location.protocol + "//" + location.host,
query = new URLSearchParams({
left: bbox.getWest() - 0.0001,
top: bbox.getNorth() + 0.0001,
right: bbox.getEast() + 0.0001,
bottom: bbox.getSouth() - 0.0001
});
const remoteEditHost = "http://127.0.0.1:8111",
osmHost = location.protocol + "//" + location.host;

if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes
sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query, function () {
sendRemoteEditCommand(remoteEditHost + getLoadAndZoomPath(bbox, object), () => {
if (object && object.type === "note") {
const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) });
sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery);
Expand All @@ -263,12 +256,29 @@ $(document).ready(function () {
return false;
}

function getLoadAndZoomPath(bbox, object) {
const query = new URLSearchParams({
left: bbox.getWest() - 0.0001,
top: bbox.getNorth() + 0.0001,
right: bbox.getEast() + 0.0001,
bottom: bbox.getSouth() - 0.0001
});

if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes
return "/load_and_zoom?" + query;
}

$("a[data-editor=remote]").click(function (e) {
var params = OSM.mapParams(this.search);
remoteEditHandler(map.getBounds(), params.object);
e.preventDefault();
});

$("a[data-editor=josm_scheme]").click(function () {
var params = OSM.mapParams(this.search);
$(this).attr("href", "josm:" + getLoadAndZoomPath(map.getBounds(), params.object));
});

if (OSM.params().edit_help) {
$("#editanchor")
.removeAttr("title")
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ en:
remote:
name: "Remote Control"
description: "Remote Control (JOSM, Potlatch, Merkaartor)"
josm_scheme:
name: "josm: URI scheme"
description: "josm: URI scheme (Vespucci)"
auth:
providers:
none: None
Expand Down
2 changes: 1 addition & 1 deletion lib/editors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Editors
ALL_EDITORS = %w[potlatch potlatch2 id remote].freeze
AVAILABLE_EDITORS = %w[id remote].freeze
RECOMMENDED_EDITORS = %w[id remote].freeze
RECOMMENDED_EDITORS = %w[id remote josm_scheme].freeze
end

0 comments on commit 9ce8038

Please sign in to comment.