- Timestamp:
- 2017-10-06T12:18:10+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r12846 r12927 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.geom.Area; 13 import java.awt.geom.Path2D; 11 14 import java.util.ArrayList; 12 15 import java.util.Arrays; … … 42 45 import org.openstreetmap.josm.data.osm.BBox; 43 46 import org.openstreetmap.josm.data.preferences.StringProperty; 47 import org.openstreetmap.josm.gui.MainApplication; 44 48 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; 49 import org.openstreetmap.josm.gui.layer.MainLayerManager; 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 45 51 import org.openstreetmap.josm.gui.layer.TMSLayer; 46 52 import org.openstreetmap.josm.spi.preferences.Config; … … 50 56 * This panel displays a map and lets the user chose a {@link BBox}. 51 57 */ 52 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {58 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener { 53 59 54 60 /** … … 190 196 } 191 197 198 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 199 192 200 new SlippyMapControler(this, this); 193 201 } … … 215 223 */ 216 224 @Override 217 public void paint(Graphics g) { 218 super.paint(g); 225 public void paintComponent(Graphics g) { 226 super.paintComponent(g); 227 Graphics2D g2d = (Graphics2D)g; 228 229 // draw shaded area for non-downloaded region of current "edit layer", but only if there *is* a current "edit layer", 230 // and it has defined bounds. Routine is analogous to that in OsmDataLayer's paint routine (but just different 231 // enough to make sharing code impractical) 232 final OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer(); 233 if (editLayer != null && Config.getPref().getBoolean("draw.data.downloaded_area", true) && !editLayer.data.getDataSources().isEmpty()) { 234 // initialize area with current viewport 235 Rectangle b = this.getBounds(); 236 // ensure we comfortably cover full area 237 b.grow(100, 100); 238 Path2D p = new Path2D.Float(); 239 240 // combine successively downloaded areas after converting to screen-space 241 for (Bounds bounds : editLayer.data.getDataSourceBounds()) { 242 if (bounds.isCollapsed()) { 243 continue; 244 } 245 Rectangle r = new Rectangle(this.getMapPosition(bounds.getMinLat(), bounds.getMinLon(), false)); 246 r.add(this.getMapPosition(bounds.getMaxLat(), bounds.getMaxLon(), false)); 247 p.append(r, false); 248 } 249 // subtract combined areas 250 Area a = new Area(b); 251 a.subtract(new Area(p)); 252 253 // paint remainder 254 g2d.setPaint(new Color(0, 0, 0, 32)); 255 g2d.fill(a); 256 } 219 257 220 258 // draw selection rectangle … … 229 267 g.drawRect(box.x, box.y, box.width, box.height); 230 268 } 269 } 270 271 @Override 272 public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) { 273 this.repaint(); 231 274 } 232 275
Note:
See TracChangeset
for help on using the changeset viewer.