Ignore:
Timestamp:
2017-10-06T12:18:10+02:00 (7 years ago)
Author:
bastiK
Message:

applied #15369 - download area display in SlippyMapBBoxChooser (patch by ris)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r12846 r12927  
    77import java.awt.Dimension;
    88import java.awt.Graphics;
     9import java.awt.Graphics2D;
    910import java.awt.Point;
    1011import java.awt.Rectangle;
     12import java.awt.geom.Area;
     13import java.awt.geom.Path2D;
    1114import java.util.ArrayList;
    1215import java.util.Arrays;
     
    4245import org.openstreetmap.josm.data.osm.BBox;
    4346import org.openstreetmap.josm.data.preferences.StringProperty;
     47import org.openstreetmap.josm.gui.MainApplication;
    4448import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
     49import org.openstreetmap.josm.gui.layer.MainLayerManager;
     50import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4551import org.openstreetmap.josm.gui.layer.TMSLayer;
    4652import org.openstreetmap.josm.spi.preferences.Config;
     
    5056 * This panel displays a map and lets the user chose a {@link BBox}.
    5157 */
    52 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {
     58public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener {
    5359
    5460    /**
     
    190196        }
    191197
     198        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     199
    192200        new SlippyMapControler(this, this);
    193201    }
     
    215223     */
    216224    @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        }
    219257
    220258        // draw selection rectangle
     
    229267            g.drawRect(box.x, box.y, box.width, box.height);
    230268        }
     269    }
     270
     271    @Override
     272    public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) {
     273        this.repaint();
    231274    }
    232275
Note: See TracChangeset for help on using the changeset viewer.