Changeset 9704 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-02-01T16:16:17+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OverpassTurboQueryWizard.java
r9385 r9704 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import org.openstreetmap.josm.Main; 3 5 4 6 import java.io.IOException; … … 6 8 import java.io.Reader; 7 9 import java.nio.charset.StandardCharsets; 8 import java.util. regex.Pattern;10 import java.util.HashMap; 9 11 10 12 import javax.script.Invocable; … … 14 16 15 17 /** 16 * Uses <a href="https://github.com/tyrasd/overpass- turbo/">Overpass Turbo</a> query wizard code18 * Uses <a href="https://github.com/tyrasd/overpass-wizard/">Overpass Turbo query wizard</a> code (MIT Licensed) 17 19 * to build an Overpass QL from a {@link org.openstreetmap.josm.actions.search.SearchAction} like query. 18 20 * … … 38 40 39 41 private OverpassTurboQueryWizard() { 40 // overpass-turbo is MIT Licensed41 42 42 try (final Reader reader = new InputStreamReader( 43 getClass().getResourceAsStream("/data/overpass-turbo-ffs.js"), StandardCharsets.UTF_8)) { 44 engine.eval("var console = {log: function(){}};"); 43 getClass().getResourceAsStream("/data/overpass-wizard.js"), StandardCharsets.UTF_8)) { 44 engine.eval("var console = {error: " + Main.class.getCanonicalName() + ".warn};"); 45 engine.eval("var global = {};"); 45 46 engine.eval(reader); 46 engine.eval("var construct_query = turbo.ffs().construct_query;");47 47 } catch (ScriptException | IOException ex) { 48 48 throw new RuntimeException("Failed to initialize OverpassTurboQueryWizard", ex); … … 58 58 public String constructQuery(String search) throws UncheckedParseException { 59 59 try { 60 final Object result = ((Invocable) engine).invokeFunction("construct_query", search); 60 final Object result = ((Invocable) engine).invokeMethod(engine.get("global"), 61 "overpassWizard", search, new HashMap<String, Object>() {{ 62 put("comment", false); 63 put("outputFormat", "xml"); 64 put("outputMode", "recursive_meta"); 65 }}); 61 66 if (result == Boolean.FALSE) { 62 67 throw new UncheckedParseException(); 63 68 } 64 69 String query = (String) result; 65 query = Pattern.compile("^.*\\[out:json\\]", Pattern.DOTALL).matcher(query).replaceFirst(""); 66 query = Pattern.compile("^out.*", Pattern.MULTILINE).matcher(query).replaceAll("out meta;"); 67 query = query.replace("({{bbox}})", ""); 70 query = query.replace("[bbox:{{bbox}}]", ""); 68 71 return query; 69 72 } catch (NoSuchMethodException e) {
Note:
See TracChangeset
for help on using the changeset viewer.