Changeset 32476 in osm for applications/editors/josm/plugins/walkingpapers/src
- Timestamp:
- 2016-06-30T23:56:10+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersAddLayerAction.java
r30738 r32476 85 85 86 86 WalkingPapersLayer wpl = new WalkingPapersLayer(mungedWpId, tile, b, minz, maxz); 87 Main.main.addLayer(wpl); 88 87 Main.getLayerManager().addLayer(wpl); 89 88 } 90 89 -
applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersLayer.java
r31114 r32476 21 21 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 22 22 import org.openstreetmap.josm.gui.MapView; 23 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;24 23 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 25 24 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 26 25 import org.openstreetmap.josm.gui.layer.Layer; 26 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 27 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 28 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 29 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 30 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 31 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 27 32 import org.openstreetmap.josm.tools.ImageProvider; 28 33 … … 67 72 clearTileStorage(); 68 73 69 MapView.addLayerChangeListener(new LayerChangeListener() { 70 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 71 // if user changes to a walking papers layer, zoom there just as if 72 // it was newly added 73 layerAdded(newLayer); 74 } 75 76 public void layerAdded(Layer newLayer) { 77 // only do something if we are affected 78 if (newLayer != WalkingPapersLayer.this) return; 79 BoundingXYVisitor bbox = new BoundingXYVisitor(); 80 bbox.visit(printBounds); 81 Main.map.mapView.zoomTo(bbox); 82 needRedraw = true; 83 } 84 85 public void layerRemoved(Layer oldLayer) { 86 if (oldLayer == WalkingPapersLayer.this) { 87 MapView.removeLayerChangeListener(this); 74 final ActiveLayerChangeListener activeListener = new ActiveLayerChangeListener() { 75 @Override 76 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 77 // if user changes to a walking papers layer, zoom there just as if it was newly added 78 handleNewLayer(Main.getLayerManager().getActiveLayer()); 79 } 80 }; 81 82 Main.getLayerManager().addActiveLayerChangeListener(activeListener); 83 Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() { 84 85 @Override 86 public void layerAdded(LayerAddEvent e) { 87 handleNewLayer(e.getAddedLayer()); 88 } 89 90 @Override 91 public void layerRemoving(LayerRemoveEvent e) { 92 if (e.getRemovedLayer() == WalkingPapersLayer.this) { 93 Main.getLayerManager().removeLayerChangeListener(this); 94 Main.getLayerManager().removeActiveLayerChangeListener(activeListener); 88 95 } 89 96 } 97 98 @Override 99 public void layerOrderChanged(LayerOrderChangeEvent e) { 100 } 90 101 }); 102 } 103 104 private void handleNewLayer(Layer newLayer) { 105 // only do something if we are affected 106 if (newLayer != WalkingPapersLayer.this) return; 107 BoundingXYVisitor bbox = new BoundingXYVisitor(); 108 bbox.visit(printBounds); 109 Main.map.mapView.zoomTo(bbox); 110 needRedraw = true; 91 111 } 92 112 … … 117 137 118 138 static class TileTimeComp implements Comparator<WalkingPapersTile> { 139 @Override 119 140 public int compare(WalkingPapersTile s1, WalkingPapersTile s2) { 120 141 long t1 = s1.access_time(); … … 170 191 int realHeight = img.getHeight(this); 171 192 if (realWidth == -1 || realHeight == -1) 172 193 return null; 173 194 int drawWidth = p1.x - p0.x; 174 195 int drawHeight = p1.x - p0.x; … … 189 210 190 211 if (botRight.lon() == 0.0 || botRight.lat() == 0) { 191 192 212 // probably still initializing 213 return; 193 214 } 194 215 if (lastTopLeft != null && lastBotRight != null … … 209 230 210 231 if (!LatLon.isValidLat(topLeft.lat()) || 211 !LatLon.isValidLat(botRight.lat()) ||212 !LatLon.isValidLon(topLeft.lon()) ||213 !LatLon.isValidLon(botRight.lon()))232 !LatLon.isValidLat(botRight.lat()) || 233 !LatLon.isValidLon(topLeft.lon()) || 234 !LatLon.isValidLon(botRight.lon())) 214 235 return; 215 236 … … 257 278 // check if tile is in range 258 279 Bounds tileBounds = new Bounds(new LatLon(tileYToLat(y+1), tileXToLon(x)), 259 new LatLon(tileYToLat(y), tileXToLon(x+1)));280 new LatLon(tileYToLat(y), tileXToLon(x+1))); 260 281 if (!tileBounds.asRect().intersects(printBounds.asRect())) continue; 261 282 tile = new WalkingPapersTile(x, y, currentZoomLevel, this); … … 397 418 } 398 419 420 @Override 399 421 public boolean imageUpdate(Image img, int infoflags, int x, int y, 400 422 int width, int height) { … … 414 436 public URL formatImageUrl(int x, int y, int z) { 415 437 String urlstr = tileUrlTemplate. 416 replace("{x}", String.valueOf(x)).417 replace("{y}", String.valueOf(y)).418 replace("{z}", String.valueOf(z));438 replace("{x}", String.valueOf(x)). 439 replace("{y}", String.valueOf(y)). 440 replace("{z}", String.valueOf(z)); 419 441 try { 420 442 return new URL(urlstr);
Note:
See TracChangeset
for help on using the changeset viewer.