Changeset 8199 in josm


Ignore:
Timestamp:
2015-04-15T23:51:33+02:00 (5 years ago)
Author:
simon04
Message:

see #10217 - Enable rotating icons with MapCSS

The corresponding key is icon-rotation and takes angles in the following forms:
[rad], [rad]rad, [deg]°, [deg]deg, or a cardinal direction
(e.g., northeast, sw).

In addition, the following MapCSS functions are provided:
degree_to_radians, cardinal_to_radians

Location:
trunk
Files:
3 added
3 edited

Legend:

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

    r8140 r8199  
    734734    }
    735735
    736     public void drawNodeIcon(Node n, MapImage img, boolean disabled, boolean selected, boolean member) {
     736    public void drawNodeIcon(Node n, MapImage img, boolean disabled, boolean selected, boolean member, double theta) {
    737737        Point p = nc.getPoint(n);
    738738
     
    747747            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    748748        }
     749        g.rotate(theta, p.x, p.y);
    749750        g.drawImage(img.getImage(disabled), p.x - w/2 + img.offsetX, p.y - h/2 + img.offsetY, nc);
     751        g.rotate(-theta, p.x, p.y);
    750752        g.setPaintMode();
    751753        if (selected || member)
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r8133 r8199  
    1919import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    2020import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
     21import org.openstreetmap.josm.gui.util.RotationAngle;
    2122import org.openstreetmap.josm.tools.Utils;
    2223
     
    2627public class NodeElemStyle extends ElemStyle implements StyleKeys {
    2728    public final MapImage mapImage;
     29    public final RotationAngle mapImageAngle;
    2830    public final Symbol symbol;
    2931
     
    99101    public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
    100102
    101     protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol, float default_major_z_index) {
     103    protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol, float default_major_z_index, RotationAngle rotationAngle) {
    102104        super(c, default_major_z_index);
    103105        this.mapImage = mapImage;
    104106        this.symbol = symbol;
     107        this.mapImageAngle = rotationAngle;
    105108    }
    106109
     
    117120            symbol = createSymbol(env);
    118121        }
     122        final String rotationString = c.get("icon-rotation", null, String.class);
     123        RotationAngle rotationAngle = null;
     124        if ("way".equalsIgnoreCase(rotationString)) {
     125            rotationAngle = RotationAngle.buildWayDirectionRotation();
     126        } else if (rotationString != null) {
     127            try {
     128                rotationAngle = RotationAngle.buildStaticRotation(rotationString);
     129            } catch (RuntimeException ignore) {
     130            }
     131        }
    119132
    120133        // optimization: if we neither have a symbol, nor a mapImage
     
    123136        if (!allowDefault && symbol == null && mapImage == null) return null;
    124137
    125         return new NodeElemStyle(c, mapImage, symbol, default_major_z_index);
     138        return new NodeElemStyle(c, mapImage, symbol, default_major_z_index, rotationAngle);
    126139    }
    127140
     
    257270            Node n = (Node) primitive;
    258271            if (mapImage != null && painter.isShowIcons()) {
    259                 painter.drawNodeIcon(n, mapImage, painter.isInactiveMode() || n.isDisabled(), selected, member);
     272                painter.drawNodeIcon(n, mapImage, painter.isInactiveMode() || n.isDisabled(), selected, member,
     273                        mapImageAngle == null ? 0.0 : mapImageAngle.getRotationAngle(primitive));
    260274            } else if (symbol != null) {
    261275                Color fillColor = symbol.fillColor;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r7937 r8199  
    3030import org.openstreetmap.josm.gui.mappaint.Cascade;
    3131import org.openstreetmap.josm.gui.mappaint.Environment;
     32import org.openstreetmap.josm.gui.util.RotationAngle;
    3233import org.openstreetmap.josm.io.XmlWriter;
    3334import org.openstreetmap.josm.tools.ColorHelper;
     
    547548
    548549        /**
     550         * Converts an angle in degrees to radians.
     551         * @param degree the angle in degrees
     552         * @return the angle in radians
     553         * @see Math#toRadians(double)
     554         */
     555        public static double degree_to_radians(double degree) {
     556            return Math.toRadians(degree);
     557        }
     558
     559        /**
     560         * Converts an angle diven in cardinal directions to radians.
     561         * The following values are supported: {@code n}, {@code north}, {@code ne}, {@code northeast},
     562         * {@code e}, {@code east}, {@code se}, {@code southeast}, {@code s}, {@code south},
     563         * {@code sw}, {@code southwest}, {@code w}, {@code west}, {@code nw}, {@code northwest}.
     564         * @param cardinal the angle in cardinal directions.
     565         * @see RotationAngle#parseCardinalRotation(String)
     566         * @return the angle in radians
     567         */
     568        public static Double cardinal_to_radians(String cardinal) {
     569            try {
     570                return RotationAngle.parseCardinalRotation(cardinal);
     571            } catch (IllegalArgumentException ignore) {
     572                return null;
     573            }
     574        }
     575
     576        /**
    549577         * Determines if the objects {@code a} and {@code b} are equal.
    550578         * @param a First object
Note: See TracChangeset for help on using the changeset viewer.