Ignore:
Timestamp:
2011-03-26T19:34:21+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: new LinePattern style element similar to mapnik's LinePatternSymbolizer; split off the text part of LineElemStyle, so it also works for LinePattern

File:
1 edited

Legend:

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

    r4002 r4006  
    116116     */
    117117    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor,
    118             TextElement text, boolean showOrientation, boolean showHeadArrowOnly,
     118            boolean showOrientation, boolean showHeadArrowOnly,
    119119            boolean showOneway, boolean onewayReversed) {
    120120
     
    204204        }
    205205        displaySegments(path, orientationArrows, onewayArrows, onewayArrowsCasing, color, line, dashes, dashedColor);
    206         drawTextOnPath(way, text);
    207206    }
    208207
     
    247246    }
    248247
    249     private void drawTextOnPath(Way way, TextElement text) {
     248    public void drawTextOnPath(Way way, TextElement text) {
    250249        if (text == null)
    251250            return;
     
    348347        }
    349348        return null;
     349    }
     350
     351    public void drawLinePattern(Way way, ImageIcon pattern) {
     352        final int width = pattern.getIconWidth();
     353        final int height = pattern.getIconHeight();
     354
     355        Point lastP = null;
     356        double wayLength = 0;
     357
     358        Iterator<Node> it = way.getNodes().iterator();
     359        while (it.hasNext()) {
     360            Node n = it.next();
     361            Point thisP = nc.getPoint(n);
     362
     363            if (lastP != null) {
     364                final double segmentLength = thisP.distance(lastP);
     365
     366                final double dx = thisP.x - lastP.x;
     367                final double dy = thisP.y - lastP.y;
     368
     369                double dist = wayLength == 0 ? 0 : width - (wayLength % width);
     370
     371                AffineTransform saveTransform = g.getTransform();
     372                g.translate(lastP.x, lastP.y);
     373                g.rotate(Math.atan2(dy, dx));
     374
     375                if (dist > 0) {
     376                    g.drawImage(pattern.getImage(), 0, 0, (int) dist, height,
     377                            width - (int) dist, 0, width, height, null);
     378                }
     379                while (dist < segmentLength) {
     380                    if (dist + width > segmentLength) {
     381                        g.drawImage(pattern.getImage(), (int) dist, 0, (int) segmentLength, height,
     382                                0, 0, (int) segmentLength - (int) dist, height, null);
     383                    } else {
     384                        pattern.paintIcon(nc, g, (int) dist, 0);
     385                    }
     386                    dist += width;
     387                }
     388                g.setTransform(saveTransform);
     389
     390                wayLength += segmentLength;
     391            }
     392            lastP = thisP;
     393        }
    350394    }
    351395
Note: See TracChangeset for help on using the changeset viewer.