Ticket #15369: 0003-SlippyMapBBoxChooser-paint-extents-of-downloaded-are.patch
| File 0003-SlippyMapBBoxChooser-paint-extents-of-downloaded-are.patch, 5.1 KB (added by , 9 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
From b01d3088f6ee27433a6e70a97e27de78dcb1b808 Mon Sep 17 00:00:00 2001 From: Robert Scott <code@humanleg.org.uk> Date: Thu, 28 Sep 2017 23:37:02 +0100 Subject: [PATCH 3/3] SlippyMapBBoxChooser: paint extents of downloaded area in similar style to OsmDataLayer using a technique which is almost directly lifted therefrom. --- .../josm/gui/bbox/SlippyMapBBoxChooser.java | 56 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java b/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java index 6451dd8..1f653b4 100644
a b import static org.openstreetmap.josm.tools.I18n.tr; 6 6 import java.awt.Color; 7 7 import java.awt.Dimension; 8 8 import java.awt.Graphics; 9 import java.awt.Graphics2D; 9 10 import java.awt.Point; 10 11 import java.awt.Rectangle; 12 import java.awt.TexturePaint; 13 import java.awt.geom.Area; 14 import java.awt.geom.Path2D; 15 import java.awt.image.BufferedImage; 11 16 import java.util.ArrayList; 12 17 import java.util.Arrays; 13 18 import java.util.Collections; … … import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 41 46 import org.openstreetmap.josm.data.imagery.TileLoaderFactory; 42 47 import org.openstreetmap.josm.data.osm.BBox; 43 48 import org.openstreetmap.josm.data.preferences.StringProperty; 49 import org.openstreetmap.josm.gui.MainApplication; 44 50 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; 51 import org.openstreetmap.josm.gui.layer.MainLayerManager; 52 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 45 53 import org.openstreetmap.josm.gui.layer.TMSLayer; 46 54 import org.openstreetmap.josm.spi.preferences.Config; 47 55 import org.openstreetmap.josm.tools.Logging; … … import org.openstreetmap.josm.tools.Logging; 49 57 /** 50 58 * This panel displays a map and lets the user chose a {@link BBox}. 51 59 */ 52 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {60 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener { 53 61 54 62 /** 55 63 * A list of tile sources that can be used for displaying the map. … … public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser { 189 197 iSourceButton.setCurrentMap(tileSources.get(0)); 190 198 } 191 199 200 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 201 192 202 new SlippyMapControler(this, this); 193 203 } 194 204 … … public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser { 216 226 @Override 217 227 public void paintComponent(Graphics g) { 218 228 super.paintComponent(g); 229 Graphics2D g2d = (Graphics2D)g; 230 231 // draw hatched area for non-downloaded region of current "edit layer", but only if there *is* a current "edit layer", 232 // and it has defined bounds. routime is analogous to that in OsmDataLayer's paint routine (but just different 233 // enough to make sharing code impractical) 234 final OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer(); 235 if (editLayer != null && Config.getPref().getBoolean("draw.data.downloaded_area", true) && !editLayer.data.getDataSources().isEmpty()) { 236 // initialize area with current viewport 237 Rectangle b = this.getBounds(); 238 // ensure we comfortably cover full area 239 b.grow(100, 100); 240 Path2D p = new Path2D.Float(); 241 242 // combine successively downloaded areas after converting to screen-space 243 for (Bounds bounds : editLayer.data.getDataSourceBounds()) { 244 if (bounds.isCollapsed()) { 245 continue; 246 } 247 Rectangle r = new Rectangle(this.getMapPosition(bounds.getMinLat(), bounds.getMinLon(), false)); 248 r.add(this.getMapPosition(bounds.getMaxLat(), bounds.getMaxLon(), false)); 249 p.append(r, false); 250 } 251 // subtract combined areas 252 Area a = new Area(b); 253 a.subtract(new Area(p)); 254 255 // paint remainder 256 BufferedImage hatchedTexture = editLayer.getHatchedTexture(); 257 int hatchedSize = hatchedTexture.getWidth(); 258 Rectangle anchorRect = new Rectangle( 259 hatchedSize-(this.center.x % hatchedSize), 260 hatchedSize-(this.center.y % hatchedSize), 261 hatchedSize, 262 hatchedSize 263 ); 264 g2d.setPaint(new TexturePaint(hatchedTexture, anchorRect)); 265 266 g2d.fill(a); 267 } 219 268 220 269 // draw selection rectangle 221 270 if (iSelectionRectStart != null && iSelectionRectEnd != null) { … … public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser { 230 279 } 231 280 } 232 281 282 @Override 283 public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) { 284 this.repaint(); 285 } 286 233 287 /** 234 288 * Enables the disk tile cache. 235 289 * @param enabled true to enable, false to disable
