Changeset 16549 in osm for applications
- Timestamp:
- 2009-07-17T01:35:53+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersAddLayerAction.java
r16522 r16549 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent; 5 6 import java.io.BufferedReader; 6 import java.io.BufferedWriter;7 import java.io.File;8 import java.io.FileOutputStream;9 import java.io.IOException;10 7 import java.io.InputStreamReader; 11 import java.io.OutputStreamWriter;12 8 import java.net.URL; 13 9 import java.util.regex.Matcher; … … 19 15 import org.openstreetmap.josm.actions.JosmAction; 20 16 import org.openstreetmap.josm.data.Bounds; 21 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 22 import org.openstreetmap.josm.tools.OsmUrlToBounds; 17 import org.openstreetmap.josm.data.coor.LatLon; 23 18 19 @SuppressWarnings("serial") 24 20 public class WalkingPapersAddLayerAction extends JosmAction { 25 21 … … 31 27 public void actionPerformed(ActionEvent e) { 32 28 String wpid = JOptionPane.showInputDialog(Main.parent, 33 tr("Image id from walking-papers.org "),34 Main.pref.get("walkingpapers.last-used-id"));29 tr("Image id from walking-papers.org (the bit after the ?id= in the URL)"), 30 Main.pref.get("walkingpapers.last-used-id")); 35 31 36 32 if (wpid == null || wpid.equals("")) return; … … 39 35 String wpUrl = "http://walking-papers.org/scan.php?id=" + wpid; 40 36 41 Pattern locationPattern = 42 Pattern.compile("<a id=\"print-location\" href=\"(http://www.openstreetmap.org/[^\"]+)\""); 43 Pattern hiddenFieldPattern = 44 Pattern.compile("<input name=\"(\\S+)\" type=\"hidden\" value=\"(.*)\" />"); 37 Pattern spanPattern = Pattern.compile("<span class=\"(\\S+)\">(\\S+)</span>"); 45 38 Matcher m; 46 39 47 Bounds b = null; 48 int minx = -1; 49 int maxx = -1; 50 int miny = -1; 51 int maxy = -1; 40 double north = 0; 41 double south = 0; 42 double east = 0; 43 double west = 0; 52 44 int minz = -1; 53 45 int maxz = -1; 46 String tile = null; 54 47 55 48 try { 56 49 BufferedReader r = new BufferedReader(new InputStreamReader(new URL(wpUrl).openStream(), "utf-8")); 57 50 for (String line = r.readLine(); line != null; line = r.readLine()) { 58 m = locationPattern.matcher(line);51 m = spanPattern.matcher(line); 59 52 if (m.find()) { 60 String escapedUrl = m.group(1); 61 b = OsmUrlToBounds.parse(escapedUrl.replace("&","&")); 62 } else { 63 m = hiddenFieldPattern.matcher(line); 64 if (m.find()) { 65 if ("maxrow".equals(m.group(1))) maxy = (int) Double.parseDouble(m.group(2)); 66 else if ("maxcolumn".equals(m.group(1))) maxx = (int) Double.parseDouble(m.group(2)); 67 else if ("minrow".equals(m.group(1))) miny = (int) Double.parseDouble(m.group(2)); 68 else if ("mincolumn".equals(m.group(1))) minx = (int) Double.parseDouble(m.group(2)); 69 else if ("minzoom".equals(m.group(1))) minz = Integer.parseInt(m.group(2)); 70 else if ("maxzoom".equals(m.group(1))) maxz = Integer.parseInt(m.group(2)); 71 } 53 if ("tile".equals(m.group(1))) tile = m.group(2); 54 else if ("north".equals(m.group(1))) north = Double.parseDouble(m.group(2)); 55 else if ("south".equals(m.group(1))) south = Double.parseDouble(m.group(2)); 56 else if ("east".equals(m.group(1))) east = Double.parseDouble(m.group(2)); 57 else if ("west".equals(m.group(1))) west = Double.parseDouble(m.group(2)); 58 else if ("minzoom".equals(m.group(1))) minz = Integer.parseInt(m.group(2)); 59 else if ("maxzoom".equals(m.group(1))) maxz = Integer.parseInt(m.group(2)); 72 60 } 73 61 } 74 62 r.close(); 75 if (( b == null) || (minx <0)) throw new Exception();63 if ((tile == null) || (north == 0 && south == 0) || (east == 0 && west == 0)) throw new Exception(); 76 64 } catch (Exception ex) { 77 78 65 JOptionPane.showMessageDialog(Main.parent,tr("Could not read information from walking-papers.org for this id.")); 66 return; 79 67 } 68 69 Main.pref.put("walkingpapers.last-used-id", wpid); 70 71 Bounds b = new Bounds(new LatLon(south, west), new LatLon(north, east)); 80 72 81 // FIXME min/max values are not any good, they just indicate the centre tile x/y for the 82 // minimum and the maximum zoom lvl but not how many tiles there are... 83 WalkingPapersLayer wpl = new WalkingPapersLayer(wpid, b, /* minx, maxx, miny, maxy, */ minz, maxz); 73 WalkingPapersLayer wpl = new WalkingPapersLayer(wpid, tile, b, minz, maxz); 84 74 Main.main.addLayer(wpl); 85 75 -
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersLayer.java
r16522 r16549 9 9 import java.awt.Point; 10 10 import java.awt.image.ImageObserver; 11 import java.net.URL; 11 12 import java.util.Comparator; 12 13 import java.util.HashMap; … … 49 50 private Image bufferImage; 50 51 private boolean needRedraw; 51 // FIXME need to find out bounds of Walking Papers scan: private int minx, maxx, miny, maxy, 52 52 53 private int minzoom, maxzoom; 54 private Bounds printBounds; 55 private String tileUrlTemplate; 53 56 private String walkingPapersId; 54 57 55 58 @SuppressWarnings("serial") 56 public WalkingPapersLayer(String id, Bounds b, /*int minx, int maxx, int miny, int maxy,*/int minz, int maxz) {59 public WalkingPapersLayer(String id, String tile, Bounds b, int minz, int maxz) { 57 60 super(tr("Walking Papers: " +id)); 58 61 background = true; 59 62 walkingPapersId = id; 60 63 61 /* 62 this.minx = minx; this.maxx = maxx; 63 this.miny = miny; this.maxy = maxy; 64 */ 64 tileUrlTemplate = tile; 65 this.printBounds = b; 65 66 this.minzoom = minz; this.maxzoom = maxz; 66 67 currentZoomLevel = minz; 67 68 68 69 clearTileStorage(); 69 final Bounds copyOfB = b;70 70 71 71 Layer.listeners.add(new LayerChangeListener() { 72 72 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 73 // if user changes to a walking papers layer, zoom there just as if 74 // it was newly added 73 75 layerAdded(newLayer); 74 76 } 75 77 76 78 public void layerAdded(Layer newLayer) { 77 /*Main.worker.execute(new Runnable() { 78 public void run() { 79 */ 80 BoundingXYVisitor bbox = new BoundingXYVisitor(); 81 bbox.visit(copyOfB); 82 Main.map.mapView.recalculateCenterScale(bbox); 83 /* } 84 });*/ 85 79 // only do something if we are affected 80 if (newLayer != WalkingPapersLayer.this) return; 81 BoundingXYVisitor bbox = new BoundingXYVisitor(); 82 bbox.visit(printBounds); 83 Main.map.mapView.recalculateCenterScale(bbox); 84 needRedraw = true; 86 85 } 87 86 … … 224 223 } 225 224 226 boolean protectServerFromOverload = false;227 if ((viewportMaxX-viewportMinX) * (viewportMaxY-viewportMinY) > 100) {228 System.out.println("more than 100 visible tiles - will not download new ones");229 protectServerFromOverload = true;230 }231 225 if (viewportMaxX-viewportMinX > 18) return; 232 226 if (viewportMaxY-viewportMinY > 18) return; 233 234 227 235 228 for (int x = viewportMinX - 1; x <= viewportMaxX + 1; x++) { … … 255 248 if (!key.valid) continue; 256 249 if (tile == null) { 257 if (protectServerFromOverload) continue; 250 // check if tile is in range 251 Bounds tileBounds = new Bounds(new LatLon(tileYToLat(y+1), tileXToLon(x)), 252 new LatLon(tileYToLat(y), tileXToLon(x+1))); 253 if (!tileBounds.asRect().intersects(printBounds.asRect())) continue; 258 254 tile = new WalkingPapersTile(x, y, currentZoomLevel, this); 259 255 tileStorage.put(key, tile); … … 272 268 } 273 269 } 270 } 271 272 if (count == 0) 273 { 274 //System.out.println("no images on " + walkingPapersId + ", return"); 275 return; 274 276 } 275 277 … … 406 408 } 407 409 408 410 public URL formatImageUrl(int x, int y, int z) { 411 String urlstr = tileUrlTemplate. 412 replace("{x}", String.valueOf(x)). 413 replace("{y}", String.valueOf(y)). 414 replace("{z}", String.valueOf(z)); 415 try { 416 return new URL(urlstr); 417 } catch (Exception ex) { 418 return null; 419 } 420 } 409 421 410 422 } -
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersPlugin.java
r16522 r16549 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.gui.MainMenu; 13 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;14 13 import org.openstreetmap.josm.plugins.Plugin; 15 14 … … 33 32 walkingPapersMenu.add(new JMenuItem(new WalkingPapersAddLayerAction())); 34 33 35 JOptionPane.showMessageDialog(Main.parent,tr("You are running the highly experimental Walking Papers plugin. Please report all problems."));34 JOptionPane.showMessageDialog(Main.parent,tr("You are running the highly experimental Walking Papers plugin. Expect a rougher than usual ride...")); 36 35 } 37 36 -
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersTile.java
r16522 r16549 1 1 package org.openstreetmap.josm.plugins.walkingpapers; 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 2 5 3 import java.awt.Image; 6 4 import java.awt.Toolkit; 7 import java.io.BufferedReader;8 import java.io.InputStreamReader;9 import java.net.MalformedURLException;10 5 import java.net.URL; 11 import java.net.URLConnection;12 6 13 7 /** … … 39 33 40 34 public URL getImageUrl() { 41 try { 42 return new URL("http://paperwalking-uploads.s3.amazonaws.com/scans/" + parentLayer.getWalkingPapersId() + "/" + z + "/" + x + "/" + y + ".jpg"); 43 } catch (MalformedURLException mfu) { 44 mfu.printStackTrace(); 45 } 46 return null; 35 return parentLayer.formatImageUrl(x, y, z); 47 36 } 48 37
Note:
See TracChangeset
for help on using the changeset viewer.