Changeset 5801 in josm for trunk/src


Ignore:
Timestamp:
2013-03-24T12:58:45+01:00 (11 years ago)
Author:
bastiK
Message:

mapcss: new map element 'repeat-image' similar to 'pattern-image', but more flexible

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r5705 r5801  
    5757import org.openstreetmap.josm.gui.mappaint.NodeElemStyle;
    5858import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol;
     59import org.openstreetmap.josm.gui.mappaint.RepeatImageElemStyle.LineImageAlignment;
    5960import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
    6061import org.openstreetmap.josm.gui.mappaint.TextElement;
     
    595596    }
    596597
     598    @Deprecated
    597599    public void drawLinePattern(Way way, Image pattern) {
    598         final int width = pattern.getWidth(null);
    599         final int height = pattern.getHeight(null);
     600        drawRepeatImage(way, pattern, 0f, 0f, LineImageAlignment.TOP);
     601    }
     602
     603    /**
     604     * Draw an image along a way repeatedly.
     605     *
     606     * @param way the way
     607     * @param pattern the image
     608     * @param offset offset from the way
     609     * @param spacing spacing between two images
     610     * @param align alignment of the image. The top, center or bottom edge
     611     * can be aligned with the way.
     612     */
     613    public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, LineImageAlignment align) {
     614        final int imgWidth = pattern.getWidth(null);
     615        final double repeat = imgWidth + spacing;
     616        final int imgHeight = pattern.getHeight(null);
    600617
    601618        Point lastP = null;
    602         double wayLength = 0;
    603 
    604         Iterator<Node> it = way.getNodes().iterator();
     619        double currentWayLength = 0;
     620
     621        int dy1, dy2;
     622        switch (align) {
     623            case TOP:
     624                dy1 = 0;
     625                dy2 = imgHeight;
     626                break;
     627            case CENTER:
     628                dy1 = - imgHeight / 2;
     629                dy2 = imgHeight + dy1;
     630                break;
     631            case BOTTOM:
     632                dy1 = -imgHeight;
     633                dy2 = 0;
     634                break;
     635            default:
     636                throw new AssertionError();
     637        }
     638
     639        OffsetIterator it = new OffsetIterator(way.getNodes(), offset);
    605640        while (it.hasNext()) {
    606             Node n = it.next();
    607             Point thisP = nc.getPoint(n);
     641            Point thisP = it.next();
    608642
    609643            if (lastP != null) {
     
    613647                final double dy = thisP.y - lastP.y;
    614648
    615                 double dist = wayLength == 0 ? 0 : width - (wayLength % width);
     649                double pos = currentWayLength == 0 ? 0 : repeat - (currentWayLength % repeat);
    616650
    617651                AffineTransform saveTransform = g.getTransform();
     
    619653                g.rotate(Math.atan2(dy, dx));
    620654
    621                 if (dist > 0) {
    622                     g.drawImage(pattern, 0, 0, (int) dist, height,
    623                             width - (int) dist, 0, width, height, null);
    624                 }
    625                 while (dist < segmentLength) {
    626                     if (dist + width > segmentLength) {
    627                         g.drawImage(pattern, (int) dist, 0, (int) segmentLength, height,
    628                                 0, 0, (int) segmentLength - (int) dist, height, null);
     655                // draw the rest of the image from the last segment in case it
     656                // is cut off
     657                if (pos > spacing) {
     658                    g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
     659                            (int) (imgWidth + spacing - pos), 0, imgWidth, imgHeight, null);
     660                }
     661                // draw remaining images for this segment
     662                while (pos < segmentLength) {
     663                    // cut off at the end?
     664                    if (pos + imgWidth > segmentLength) {
     665                        g.drawImage(pattern, (int) pos, dy1, (int) segmentLength, dy2,
     666                                0, 0, (int) segmentLength - (int) pos, imgHeight, null);
    629667                    } else {
    630                         g.drawImage(pattern, (int) dist, 0, nc);
     668                        g.drawImage(pattern, (int) pos, dy1, nc);
    631669                    }
    632                     dist += width;
     670                    pos += repeat;
    633671                }
    634672                g.setTransform(saveTransform);
    635673
    636                 wayLength += segmentLength;
     674                currentWayLength += segmentLength;
    637675            }
    638676            lastP = thisP;
    639677        }
    640678    }
    641    
     679
    642680    @Override
    643681    public void drawNode(Node n, Color color, int size, boolean fill) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r5774 r5801  
    314314                addIfNotNull(sl, AreaElemStyle.create(c));
    315315                addIfNotNull(sl, LinePatternElemStyle.create(env));
     316                addIfNotNull(sl, RepeatImageElemStyle.create(env));
    316317                addIfNotNull(sl, LineElemStyle.createLine(env));
    317318                addIfNotNull(sl, LineElemStyle.createLeftCasing(env));
     
    331332                    addIfNotNull(sl, AreaElemStyle.create(c));
    332333                    addIfNotNull(sl, LinePatternElemStyle.create(env));
     334                    addIfNotNull(sl, RepeatImageElemStyle.create(env));
    333335                    addIfNotNull(sl, LineElemStyle.createLine(env));
    334336                    addIfNotNull(sl, LineElemStyle.createCasing(env));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r5702 r5801  
    1212import org.openstreetmap.josm.data.osm.Way;
    1313import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     14import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    1415import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    15 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    1616import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;
    1717import org.openstreetmap.josm.tools.Utils;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java

    r5571 r5801  
    99
    1010/**
    11  * similar to mapnik's LinePatternSymbolizer
     11 * Similar to mapnik's LinePatternSymbolizer.
     12 *
     13 * @deprecated superseded by #{@link RepeatImageElemStyle}
    1214 */
     15@Deprecated
    1316public class LinePatternElemStyle extends ElemStyle {
    1417
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r5376 r5801  
    44public interface StyleKeys {
    55
    6     public static final String COLOR = "color";
    7     public static final String DASHES = "dashes";
    8     public static final String DASHES_BACKGROUND_COLOR = "dashes-background-color";
    9     public static final String DASHES_BACKGROUND_OPACITY = "dashes-background-opacity";
    10     public static final String DASHES_OFFSET = "dashes-offset";
    11     public static final String FILL_COLOR = "fill-color";
    12     public static final String FILL_IMAGE = "fill-image";
    13     public static final String FILL_OPACITY = "fill-opacity";
    14     public static final String ICON_IMAGE = "icon-image";
    15     public static final String MODIFIER = "modifier";
    16     public static final String OBJECT_Z_INDEX = "object-z-index";
    17     public static final String OFFSET = "offset";
    18     public static final String OPACITY = "opacity";
    19     public static final String REAL_WIDTH = "real-width";
    20     public static final String TEXT_POSITION = "text-position";
    21     public static final String TEXT = "text";
    22     public static final String WIDTH = "width";
    23     public static final String Z_INDEX = "z-index";
     6    String COLOR = "color";
     7    String DASHES = "dashes";
     8    String DASHES_BACKGROUND_COLOR = "dashes-background-color";
     9    String DASHES_BACKGROUND_OPACITY = "dashes-background-opacity";
     10    String DASHES_OFFSET = "dashes-offset";
     11    String FILL_COLOR = "fill-color";
     12    String FILL_IMAGE = "fill-image";
     13    String FILL_OPACITY = "fill-opacity";
     14    String ICON_IMAGE = "icon-image";
     15    String MODIFIER = "modifier";
     16    String OBJECT_Z_INDEX = "object-z-index";
     17    String OFFSET = "offset";
     18    String OPACITY = "opacity";
     19    String REAL_WIDTH = "real-width";
     20    String TEXT_POSITION = "text-position";
     21    String TEXT = "text";
     22    String WIDTH = "width";
     23    String Z_INDEX = "z-index";
     24    String REPEAT_IMAGE = "repeat-image";
     25    String REPEAT_IMAGE_OFFSET = "repeat-image-offset";
     26    String REPEAT_IMAGE_SPACING = "repeat-image-spacing";
     27    String REPEAT_IMAGE_ALIGN = "repeat-image-align";
    2428}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r5705 r5801  
    7373                value = val;
    7474            }
    75             if (key.equals(ICON_IMAGE) || key.equals(FILL_IMAGE) || key.equals("pattern-image")) {
     75            if (key.equals(ICON_IMAGE) || key.equals(FILL_IMAGE) || key.equals("pattern-image") || key.equals(REPEAT_IMAGE)) {
    7676                if (value instanceof String) {
    7777                    value = new IconReference((String) value, env.source);
Note: See TracChangeset for help on using the changeset viewer.