Ticket #15369: v2-0002-SlippyMapBBoxChooser-paint-extents-of-downloaded-are.patch

File v2-0002-SlippyMapBBoxChooser-paint-extents-of-downloaded-are.patch, 4.7 KB (added by ris, 7 years ago)
  • src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    From fa110130405252bbdbe13b8a0827a710c2016899 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 30 Sep 2017 14:30:06 +0100
    Subject: [PATCH 2/2] 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        | 47 +++++++++++++++++++++-
     1 file changed, 46 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..d40041c 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr;  
    66import java.awt.Color;
    77import java.awt.Dimension;
    88import java.awt.Graphics;
     9import java.awt.Graphics2D;
    910import java.awt.Point;
    1011import java.awt.Rectangle;
     12import java.awt.TexturePaint;
     13import java.awt.geom.Area;
     14import java.awt.geom.Path2D;
     15import java.awt.image.BufferedImage;
    1116import java.util.ArrayList;
    1217import java.util.Arrays;
    1318import java.util.Collections;
    import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;  
    4146import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
    4247import org.openstreetmap.josm.data.osm.BBox;
    4348import org.openstreetmap.josm.data.preferences.StringProperty;
     49import org.openstreetmap.josm.gui.MainApplication;
    4450import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
     51import org.openstreetmap.josm.gui.layer.MainLayerManager;
     52import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4553import org.openstreetmap.josm.gui.layer.TMSLayer;
    4654import org.openstreetmap.josm.spi.preferences.Config;
    4755import org.openstreetmap.josm.tools.Logging;
    import org.openstreetmap.josm.tools.Logging;  
    4957/**
    5058 * This panel displays a map and lets the user chose a {@link BBox}.
    5159 */
    52 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {
     60public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener {
    5361
    5462    /**
    5563     * A list of tile sources that can be used for displaying the map.
    public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {  
    189197            iSourceButton.setCurrentMap(tileSources.get(0));
    190198        }
    191199
     200        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     201
    192202        new SlippyMapControler(this, this);
    193203    }
    194204
    public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {  
    216226    @Override
    217227    public void paintComponent(Graphics g) {
    218228        super.paintComponent(g);
     229        Graphics2D g2d = (Graphics2D)g;
     230
     231        // draw shaded 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            g2d.setPaint(new Color(0, 0, 0, 64));
     257            g2d.fill(a);
     258        }
    219259
    220260        // draw selection rectangle
    221261        if (iSelectionRectStart != null && iSelectionRectEnd != null) {
    public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {  
    230270        }
    231271    }
    232272
     273    @Override
     274    public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) {
     275        this.repaint();
     276    }
     277
    233278    /**
    234279     * Enables the disk tile cache.
    235280     * @param enabled true to enable, false to disable