Ignore:
Timestamp:
2017-05-15T14:41:08+02:00 (7 years ago)
Author:
michael2402
Message:

See #13124: Refresh the heat map on every invalidation (visible tacks changed, ...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r12156 r12157  
    1010import java.text.DateFormat;
    1111import java.util.Arrays;
    12 import java.util.Collection;
    1312import java.util.Date;
    14 import java.util.LinkedList;
    15 import java.util.List;
    1613
    1714import javax.swing.Action;
     
    2017import javax.swing.SwingUtilities;
    2118
    22 import org.openstreetmap.josm.Main;
    2319import org.openstreetmap.josm.actions.RenameLayerAction;
    2420import org.openstreetmap.josm.actions.SaveActionBase;
     
    2824import org.openstreetmap.josm.data.gpx.GpxData;
    2925import org.openstreetmap.josm.data.gpx.GpxTrack;
    30 import org.openstreetmap.josm.data.gpx.WayPoint;
    3126import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    3227import org.openstreetmap.josm.data.preferences.ColorProperty;
     
    6661    public boolean[] trackVisibility = new boolean[0];
    6762
    68     private final GpxDrawHelper drawHelper;
    69 
    7063    /**
    7164     * Constructs a new {@code GpxLayer} without name.
     
    9588        data = d;
    9689        data.addWeakChangeListener(e -> this.invalidate());
    97         drawHelper = new GpxDrawHelper(data);
    98         SystemOfMeasurement.addSoMChangeListener(drawHelper);
    99         ensureTrackVisibilityLength();
     90        trackVisibility = new boolean[data.getTracks().size()];
     91        Arrays.fill(trackVisibility, true);
    10092        setName(name);
    10193        isLocalFile = isLocal;
     
    280272            throw new IllegalArgumentException("not a GpxLayer: " + from);
    281273        data.mergeFrom(((GpxLayer) from).data);
    282         drawHelper.dataChanged();
    283     }
    284 
    285     @Override
    286     public void paint(Graphics2D g, MapView mv, Bounds box) {
    287         List<WayPoint> visibleSegments = listVisibleSegments(box);
    288         if (!visibleSegments.isEmpty()) {
    289             drawHelper.readPreferences(getName());
    290             drawHelper.drawAll(g, mv, visibleSegments);
    291             if (Main.getLayerManager().getActiveLayer() == this) {
    292                 drawHelper.drawColorBar(g, mv);
    293             }
    294         }
    295     }
    296 
    297     private List<WayPoint> listVisibleSegments(Bounds box) {
    298         WayPoint last = null;
    299         LinkedList<WayPoint> visibleSegments = new LinkedList<>();
    300 
    301         ensureTrackVisibilityLength();
    302         for (Collection<WayPoint> segment : data.getLinesIterable(trackVisibility)) {
    303 
    304             for (WayPoint pt : segment) {
    305                 Bounds b = new Bounds(pt.getCoor());
    306                 if (pt.drawLine && last != null) {
    307                     b.extend(last.getCoor());
    308                 }
    309                 if (b.intersects(box)) {
    310                     if (last != null && (visibleSegments.isEmpty()
    311                             || visibleSegments.getLast() != last)) {
    312                         if (last.drawLine) {
    313                             WayPoint l = new WayPoint(last);
    314                             l.drawLine = false;
    315                             visibleSegments.add(l);
    316                         } else {
    317                             visibleSegments.add(last);
    318                         }
    319                     }
    320                     visibleSegments.add(pt);
    321                 }
    322                 last = pt;
    323             }
    324         }
    325         return visibleSegments;
     274        invalidate();
    326275    }
    327276
     
    339288    public void setAssociatedFile(File file) {
    340289        data.storageFile = file;
    341     }
    342 
    343     /** ensures the trackVisibility array has the correct length without losing data.
    344      * additional entries are initialized to true;
    345      */
    346     private void ensureTrackVisibilityLength() {
    347         final int l = data.getTracks().size();
    348         if (l == trackVisibility.length)
    349             return;
    350         final int m = Math.min(l, trackVisibility.length);
    351         trackVisibility = Arrays.copyOf(trackVisibility, l);
    352         for (int i = m; i < l; i++) {
    353             trackVisibility[i] = true;
    354         }
    355         invalidate();
    356290    }
    357291
     
    383317
    384318    @Override
    385     public synchronized void destroy() {
    386         super.destroy();
    387         SystemOfMeasurement.removeSoMChangeListener(drawHelper);
     319    public void paint(Graphics2D g, MapView mv, Bounds bbox) {
     320        // unused - we use a painter so this is not called.
     321    }
     322
     323    @Override
     324    protected LayerPainter createMapViewPainter(MapViewEvent event) {
     325        return new GpxDrawHelper(this);
    388326    }
    389327}
Note: See TracChangeset for help on using the changeset viewer.