Opened 3 months ago

Last modified 3 months ago

#15085 new enhancement

Fetch overpass turbo queries from OSM preferences API

Reported by: Don-vip Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: mirrored_download overpass turbo Cc: bastiK, michael2402

Description (last modified by Don-vip)

From #15057:

Overpass turbo now has an option to save a query directly in the OSM account data. We could fetch that data (and in principle add new entries as well): ​

This code allows to fetch overpass turbo queries (with r12502 + overpass-turbo-lzw.js):

            try {
                Map<String, String> map = new OsmServerUserPreferencesReader().fetchUserPreferences(NullProgressMonitor.INSTANCE);
                String scount = map.get("overpass-ide_query-count");
                if (scount != null) {
                    try {
                        ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
                        try (CachedFile cf = new CachedFile("resource://data/overpass-turbo-lzw.js");
                                Reader reader = cf.getContentReader()) {
                        Object base64 = engine.get("Base64");

                        for (int i = 0; i < Integer.parseInt(scount); i++) {
                            String v = map.get("overpass-ide_query_" + i + "_0");
                            int idx = v.indexOf("p=") + 2;
                            int p = Integer.parseInt(v.substring(idx, v.indexOf('&', idx)));
                            idx = v.indexOf("n=") + 2;
                            String name = v.substring(idx, v.indexOf('&', idx));
                            StringBuffer sb = new StringBuffer(v.substring(v.indexOf("q=") + 2));
                            for (int j = 1; j < p ; j++) {
                                sb.append(map.get("overpass-ide_query_" + i + "_" + j));
                            String query = (String) ((Invocable) engine).invokeFunction("lzw_decode",
                                    ((Invocable) engine).invokeMethod(base64, "decode", sb.toString()));
                    } catch (NumberFormatException ex) {
            } catch (OsmTransferException | ScriptException | NoSuchMethodException | IOException ex) {

We can add an extra button to fetch/sync them, but this would be a separate feature. The problem I see is that we should be consistent on where we store preferences: We currently only store all preferences locally. Best would be to allow the user to store all JOSM preferences to the server and be consistent there.
PS: Wouldn't this be much cleaner using Regexp (p=(\\d+), untested)?

Attachments (1)

overpass-turbo-lzw.js (7.3 KB) - added by Don-vip 3 months ago.

Download all attachments as: .zip

Change History (4)

Changed 3 months ago by Don-vip

Attachment: overpass-turbo-lzw.js added

comment:1 Changed 3 months ago by Don-vip

Type: defectenhancement

comment:2 Changed 3 months ago by bafonins

Will work on it after #15057 is verified and merged.

comment:3 Changed 3 months ago by Don-vip

Description: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain team.
as The resolution will be set.
to The owner will be changed from team to the specified user.
The owner will change to Don-vip
as duplicate The resolution will be set to duplicate.The specified ticket will be cross-referenced with this ticket
The owner will be changed from team to anonymous.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.