Changeset 1943 in josm for trunk/src


Ignore:
Timestamp:
2009-08-10T06:02:47+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3228: GPX waypoints / rendering above streets

File:
1 edited

Legend:

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

    r1918 r1943  
    2020import java.util.Collection;
    2121import java.util.Collections;
     22import java.util.Comparator;
    2223import java.util.Enumeration;
    2324import java.util.LinkedList;
     
    259260
    260261    /**
    261      * Moves the layer to the given new position. No event is fired.
     262     * Moves the layer to the given new position. No event is fired, but repaints
     263     * according to the new Z-Order of the layers.
     264     *
    262265     * @param layer     The layer to move
    263266     * @param pos       The new position of the layer
     
    276279        }
    277280        AudioPlayer.reset();
     281        repaint();
    278282    }
    279283
     
    284288            throw new IllegalArgumentException(tr("layer not in list."));
    285289        return curLayerPos;
     290    }
     291
     292    /**
     293     * Creates a list of the visible layers in Z-Order, the layer with the lowest Z-Order
     294     * first, layer with the highest Z-Order last.
     295     *
     296     * @return a list of the visible in Z-Order, the layer with the lowest Z-Order
     297     * first, layer with the highest Z-Order last.
     298     */
     299    protected List<Layer> getVisibleLayersInZOrder() {
     300        ArrayList<Layer> ret = new ArrayList<Layer>();
     301        for (Layer l: layers) {
     302            if (l.isVisible()) {
     303                ret.add(l);
     304            }
     305        }
     306        // sort according to position in the list of layers, with one exception:
     307        // an active data layer always becomes a higher Z-Order than all other
     308        // data layers
     309        //
     310        Collections.sort(
     311                ret,
     312                new Comparator<Layer>() {
     313                    public int compare(Layer l1, Layer l2) {
     314                        if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) {
     315                            if (l1 == getActiveLayer()) return -1;
     316                            if (l2 == getActiveLayer()) return 1;
     317                            return new Integer(layers.indexOf(l1)).compareTo(layers.indexOf(l2));
     318                        } else
     319                            return new Integer(layers.indexOf(l1)).compareTo(layers.indexOf(l2));
     320                    }
     321                }
     322        );
     323        Collections.reverse(ret);
     324        return ret;
    286325    }
    287326
     
    305344        tempG.fillRect(0, 0, getWidth(), getHeight());
    306345
    307         Layer activeLayer = getActiveLayer();
    308         for (int i = layers.size()-1; i >= 0; --i) {
    309             Layer l = layers.get(i);
    310             if (l.isVisible() && l != getActiveLayer()) {
    311                 l.paint(tempG, this);
    312             }
    313         }
    314         if (activeLayer != null && activeLayer.isVisible()) {
    315             activeLayer.paint(tempG, this);
    316         }
    317 
     346        for (Layer l: getVisibleLayersInZOrder()) {
     347            l.paint(tempG, this);
     348        }
    318349        for (MapViewPaintable mvp : temporaryLayers) {
    319350            mvp.paint(tempG, this);
Note: See TracChangeset for help on using the changeset viewer.