Opened 7 years ago

Last modified 4 years 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, Stereo

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 7 years ago.

Download all attachments as: .zip

Change History (7)

by Don-vip, 7 years ago

Attachment: overpass-turbo-lzw.js added

comment:1 by Don-vip, 7 years ago

Type: defectenhancement

comment:2 by bafonins, 7 years ago

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

Last edited 4 years ago by skyper (previous) (diff)

comment:3 by Don-vip, 7 years ago

Description: modified (diff)

comment:4 by Don-vip, 5 years ago

Ticket #18045 has been marked as a duplicate of this ticket.

comment:5 by Don-vip, 4 years ago

Ticket #18499 has been marked as a duplicate of this ticket.

comment:6 by Stereo, 4 years ago

Cc: Stereo added

Modify Ticket

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

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.