Opened 7 years ago
Last modified 5 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 )
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): https://www.openstreetmap.org/user/tyr_asd/diary/41793
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()) { engine.eval(reader); } 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) { Main.trace(ex); } } } catch (OsmTransferException | ScriptException | NoSuchMethodException | IOException ex) { Main.error(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)
Change History (7)
by , 7 years ago
Attachment: | overpass-turbo-lzw.js added |
---|
comment:1 by , 7 years ago
Type: | defect → enhancement |
---|
comment:3 by , 7 years ago
Description: | modified (diff) |
---|
comment:6 by , 5 years ago
Cc: | added |
---|
Will work on it after #15057 is verified and merged.