From 9aecb2a8295ff62229f727cdc31d03e035d36ba9 Mon Sep 17 00:00:00 2001 From: Ian Dees Date: Mon, 15 Jul 2013 23:27:32 -0500 Subject: [PATCH] Finish transition to Fieldpapers and new scrape logic for WP.org --- .classpath | 2 +- README | 7 +- build.xml | 169 +++++++++++++++++- images/{walkingpapers.png => fieldpapers.png} | Bin .../{walkingpapers.png => fieldpapers.png} | Bin .../FieldPapersAddLayerAction.java | 67 +++---- .../plugins/fieldpapers/FieldPapersKey.java | 4 +- .../plugins/fieldpapers/FieldPapersLayer.java | 32 ++-- .../fieldpapers/FieldPapersPlugin.java | 5 +- .../plugins/fieldpapers/FieldPapersTile.java | 1 + 10 files changed, 223 insertions(+), 64 deletions(-) rename images/{walkingpapers.png => fieldpapers.png} (100%) rename images/preferences/{walkingpapers.png => fieldpapers.png} (100%) diff --git a/.classpath b/.classpath index 663bc1b..32eb8e6 100644 --- a/.classpath +++ b/.classpath @@ -2,6 +2,6 @@ - + diff --git a/README b/README index 52fa214..026818d 100644 --- a/README +++ b/README @@ -1,6 +1,7 @@ -A plugin for displaying tiled, scanned maps from walking-papers.org. +A plugin for displaying tiled, scanned maps from fieldpapers.org. -Written by Frederik Ramm , based on SlippyMap -plugin work by Lubomir Varga or . +Adapted by Ian Dees from a plugin written by +Frederik Ramm , based on SlippyMap plugin work +by Lubomir Varga or . Public Domain. diff --git a/build.xml b/build.xml index 34ac7d5..e6f5f52 100644 --- a/build.xml +++ b/build.xml @@ -11,20 +11,173 @@ ** Call "ant help" to get possible build targets. ** --> - + - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Building against core revision ${coreversion.info.entry.revision}. + Plugin-Mainversion is set to ${plugin.main.version}. + + + + + Commiting the plugin source with message '${commit.message}' ... + + + + + + + + + + Updating plugin source ... + + + + + + Updating ${plugin.jar} ... + + + + + + + + + + ***** Properties of published ${plugin.jar} ***** + Commit message : '${commit.message}' + Plugin-Mainversion: ${plugin.main.version} + JOSM build version: ${coreversion.info.entry.revision} + Plugin-Version : ${version.entry.commit.revision} + ***** / Properties of published ${plugin.jar} ***** + + Now commiting ${plugin.jar} ... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/images/walkingpapers.png b/images/fieldpapers.png similarity index 100% rename from images/walkingpapers.png rename to images/fieldpapers.png diff --git a/images/preferences/walkingpapers.png b/images/preferences/fieldpapers.png similarity index 100% rename from images/preferences/walkingpapers.png rename to images/preferences/fieldpapers.png diff --git a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersAddLayerAction.java b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersAddLayerAction.java index ac3eb9b..98e9547 100644 --- a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersAddLayerAction.java +++ b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersAddLayerAction.java @@ -20,79 +20,82 @@ public class FieldPapersAddLayerAction extends JosmAction { public FieldPapersAddLayerAction() { - super(tr("Scanned Map..."), "walkingpapers", - tr("Display a map that was previously scanned and uploaded to walking-papers.org"), null, false); + super(tr("Scanned Map..."), "fieldpapers", + tr("Display a map that was previously scanned and uploaded to fieldpapers.org"), null, false); } public void actionPerformed(ActionEvent e) { String wpid = JOptionPane.showInputDialog(Main.parent, - tr("Enter a walking-papers.org URL or ID (the bit after the ?id= in the URL)"), - Main.pref.get("walkingpapers.last-used-id")); + tr("Enter a fieldpapers.org snapshot URL"), + Main.pref.get("fieldpapers.last-used-id")); if (wpid == null || wpid.equals("")) return; // Grab id= from the URL if we need to, otherwise get an ID - String mungedWpId = this.getWalkingPapersId(wpid); + String mungedWpId = this.getFieldPapersId(wpid); if (mungedWpId == null || mungedWpId.equals("")) return; - // screen-scrape details about this id from walking-papers.org - String wpUrl = Main.pref.get("walkingpapers.base-url", "http://walking-papers.org/") + "scan.php?id=" + mungedWpId; + // screen-scrape details about this id from fieldpapers.org + // e.g. http://fieldpapers.org/snapshot.php?id=nq78w6wl + String wpUrl = Main.pref.get("fieldpapers.base-url", "http://fieldpapers.org/") + "snapshot.php?id=" + mungedWpId; - Pattern spanPattern = Pattern.compile("(\\S+)"); + Pattern spanPattern = Pattern.compile("var (\\S*) = (\\S*);"); Matcher m; + String boundsStr = ""; + String urlBase = null; double north = 0; double south = 0; double east = 0; double west = 0; - int minz = -1; - int maxz = -1; - String tile = null; try { BufferedReader r = new BufferedReader(new InputStreamReader(new URL(wpUrl).openStream(), "utf-8")); for (String line = r.readLine(); line != null; line = r.readLine()) { m = spanPattern.matcher(line); if (m.find()) { - if ("tile".equals(m.group(1))) tile = m.group(2); - else if ("north".equals(m.group(1))) north = Double.parseDouble(m.group(2)); - else if ("south".equals(m.group(1))) south = Double.parseDouble(m.group(2)); - else if ("east".equals(m.group(1))) east = Double.parseDouble(m.group(2)); - else if ("west".equals(m.group(1))) west = Double.parseDouble(m.group(2)); - else if ("minzoom".equals(m.group(1))) minz = Integer.parseInt(m.group(2)); - else if ("maxzoom".equals(m.group(1))) maxz = Integer.parseInt(m.group(2)); + if ("geojpeg_bounds".equals(m.group(1))) boundsStr = m.group(2); + else if ("base_provider".equals(m.group(1))) urlBase = m.group(2); } } r.close(); - if ((tile == null) || (north == 0 && south == 0) || (east == 0 && west == 0)) throw new Exception(); + if (!boundsStr.isEmpty()) { + String[] boundSplits = boundsStr.replaceAll("\"", "").split(","); + south = Double.parseDouble(boundSplits[0]); + west = Double.parseDouble(boundSplits[1]); + north = Double.parseDouble(boundSplits[2]); + east = Double.parseDouble(boundSplits[3]); + } + + if (!urlBase.isEmpty()) { + urlBase = urlBase.replaceAll("\\\\", "").replaceAll("\"", ""); + } + + if (urlBase == null || (north == 0 && south == 0) || (east == 0 && west == 0)) throw new Exception(); } catch (Exception ex) { - JOptionPane.showMessageDialog(Main.parent,tr("Could not read information from walking-papers.org the id \"{0}\"", mungedWpId)); + ex.printStackTrace(); + JOptionPane.showMessageDialog(Main.parent,tr("Could not read information for the id \"{0}\" from fieldpapers.org", mungedWpId)); return; } - - //http://walking-papers.org/scan.php?id=rmvdr3lq - // The server is apparently broken and returning the WpId in the URL twice - // which makes it return errors when we fetch it. So, strip out one of - // the dups. This is a hack and needs to get removed when the server - // is fixed. - tile = tile.replaceFirst(mungedWpId+"/"+mungedWpId, mungedWpId); - Main.pref.put("walkingpapers.last-used-id", mungedWpId); + String tileUrl = urlBase + "/{zoom}/{x}/{y}.jpg"; + Main.pref.put("fieldpapers.last-used-id", mungedWpId); Bounds b = new Bounds(new LatLon(south, west), new LatLon(north, east)); - FieldPapersLayer wpl = new FieldPapersLayer(mungedWpId, tile, b, minz, maxz); + FieldPapersLayer wpl = new FieldPapersLayer(mungedWpId, tileUrl, b, 13, 18); Main.main.addLayer(wpl); } - private static String getWalkingPapersId(String wpid) { + private String getFieldPapersId(String wpid) { if (!wpid.contains("id=")) { return wpid; } else { - // To match e.g. http://walking-papers.org/scan.php?id=53h78bbx - final Pattern pattern = Pattern.compile("\\?id=(\\S+)"); + // To match e.g. http://fieldpapers.org/snapshot.php?id=tz3fq6xl + // or http://fieldpapers.org/snapshot.php?id=nq78w6wl#15/41.8966/-87.6847 + final Pattern pattern = Pattern.compile("snapshot.php\\?id=([a-z0-9]*)"); final Matcher matcher = pattern.matcher(wpid); final boolean found = matcher.find(); diff --git a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersKey.java b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersKey.java index 8d5f759..3c932d5 100644 --- a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersKey.java +++ b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersKey.java @@ -34,7 +34,7 @@ public FieldPapersKey(int level, int x, int y) { this.level = level; if (level <= 0 || x < 0 || y < 0) { this.valid = false; - System.err.println("invalid WalkingPapersKey("+level+", "+x+", "+y+")"); + System.err.println("invalid FieldPapersKey("+level+", "+x+", "+y+")"); } else { this.valid = true; } @@ -72,7 +72,7 @@ public int hashCode() { */ @Override public String toString() { - return "WalkingPapersKey(x=" + this.x + ",y=" + this.y + ",level=" + level + ")"; + return "FieldPapersKey(x=" + this.x + ",y=" + this.y + ",level=" + level + ")"; } } diff --git a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersLayer.java b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersLayer.java index 421dec5..563eaae 100644 --- a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersLayer.java +++ b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersLayer.java @@ -27,8 +27,9 @@ import org.openstreetmap.josm.tools.ImageProvider; /** - * Class that displays a slippy map layer. Adapted from SlippyMap plugin for Walking Papers use. + * Class that displays a slippy map layer. Adapted from SlippyMap plugin for Field Papers use. * + * @author Ian Dees * @author Frederik Ramm * @author LuVar * @author Dave Hansen @@ -37,7 +38,7 @@ public class FieldPapersLayer extends Layer implements ImageObserver { /** * Actual zoom lvl. Initial zoom lvl is set to - * {@link WalkingPapersPreferences#getMinZoomLvl()}. + * {@link FieldPapersPreferences#getMinZoomLvl()}. */ private int currentZoomLevel; private HashMap tileStorage = null; @@ -52,24 +53,23 @@ public class FieldPapersLayer extends Layer implements ImageObserver { private int minzoom, maxzoom; private Bounds printBounds; private String tileUrlTemplate; - private String walkingPapersId; + private String fieldPapersId; - @SuppressWarnings("serial") - public FieldPapersLayer(String id, String tile, Bounds b, int minz, int maxz) { - super(tr("Walking Papers: {0}", id)); + public FieldPapersLayer(String id, String tileUrlTemplate, Bounds b, int minz, int maxz) { + super(tr("Field Papers: {0}", id)); setBackgroundLayer(true); - walkingPapersId = id; + this.fieldPapersId = id; - tileUrlTemplate = tile; + this.tileUrlTemplate = tileUrlTemplate; this.printBounds = b; this.minzoom = minz; this.maxzoom = maxz; - currentZoomLevel = minz; + this.currentZoomLevel = minz; clearTileStorage(); MapView.addLayerChangeListener(new LayerChangeListener() { public void activeLayerChange(Layer oldLayer, Layer newLayer) { - // if user changes to a walking papers layer, zoom there just as if + // if user changes to a field papers layer, zoom there just as if // it was newly added layerAdded(newLayer); } @@ -279,7 +279,7 @@ public void paint(Graphics2D g, MapView mv, Bounds bounds) { if (count == 0) { - //System.out.println("no images on " + walkingPapersId + ", return"); + //System.out.println("no images on " + fieldPapersId + ", return"); return; } @@ -337,7 +337,7 @@ FieldPapersTile getTileForPixelpos(int px, int py) { @Override public Icon getIcon() { - return ImageProvider.get("walkingpapers"); + return ImageProvider.get("fieldpapers"); } @Override @@ -359,7 +359,7 @@ public Action[] getMenuEntries() { @Override public String getToolTipText() { - return tr("Walking Papers layer ({0}) in zoom {1}", this.getWalkingPapersId(), currentZoomLevel); + return tr("Field Papers layer ({0}) in zoom {1}", this.getFieldPapersId(), currentZoomLevel); } @Override @@ -408,15 +408,15 @@ public boolean imageUpdate(Image img, int infoflags, int x, int y, return !done; } - public String getWalkingPapersId() { - return walkingPapersId; + public String getFieldPapersId() { + return fieldPapersId; } public URL formatImageUrl(int x, int y, int z) { String urlstr = tileUrlTemplate. replace("{x}", String.valueOf(x)). replace("{y}", String.valueOf(y)). - replace("{z}", String.valueOf(z)); + replace("{zoom}", String.valueOf(z)); try { return new URL(urlstr); } catch (Exception ex) { diff --git a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersPlugin.java b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersPlugin.java index bfbf7b9..2ac3499 100644 --- a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersPlugin.java +++ b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersPlugin.java @@ -14,8 +14,9 @@ import org.openstreetmap.josm.plugins.PluginInformation; /** - * Main class for the walking papers plugin. + * Main class for the field papers plugin. * + * @author Ian Dees * @author Frederik Ramm * */ @@ -27,7 +28,7 @@ public FieldPapersPlugin(PluginInformation info) { super(info); MainMenu menu = Main.main.menu; - walkingPapersMenu = menu.addMenu(marktr("Walking Papers"), KeyEvent.VK_K, menu.defaultMenuPos, ht("/Plugin/WalkingPapers")); + walkingPapersMenu = menu.addMenu(marktr("Field Papers"), KeyEvent.VK_K, menu.defaultMenuPos, ht("/Plugin/FieldPapers")); walkingPapersMenu.add(new JMenuItem(new FieldPapersAddLayerAction())); } } diff --git a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersTile.java b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersTile.java index 9679e03..99349a1 100644 --- a/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersTile.java +++ b/src/org/openstreetmap/josm/plugins/fieldpapers/FieldPapersTile.java @@ -7,6 +7,7 @@ /** * Class that contains information about one single slippy map tile. * + * @author Ian Dees * @author LuVar * @author Dave Hansen