Ticket #22695: 0002-Add-parent_way_angle-mapcss-function.patch

File 0002-Add-parent_way_angle-mapcss-function.patch, 3.1 KB (added by Woazboat, 3 years ago)
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    From ba5c9fdba9fcbf8cfe4b5424366f191e7d81d1fd Mon Sep 17 00:00:00 2001
    Date: Wed, 1 Feb 2023 01:24:32 +0100
    Subject: [PATCH 2/2] Add parent_way_angle mapcss function
    
    ---
     .../gui/mappaint/mapcss/ExpressionFactory.java  |  1 +
     .../josm/gui/mappaint/mapcss/Functions.java     | 17 +++++++++++++++++
     2 files changed, 18 insertions(+)
    
    diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
    index 72056434f..73e3066e1 100644
    a b public final class ExpressionFactory {  
    216216        FACTORY_MAP.put("parent_osm_id", Factory.ofEnv(Functions::parent_osm_id));
    217217        FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag));
    218218        FACTORY_MAP.put("parent_tags", Factory.ofEnv(String.class, Functions::parent_tags));
     219        FACTORY_MAP.put("parent_way_angle", Factory.ofEnv(Functions::parent_way_angle));
    219220        FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus));
    220221        FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print));
    221222        FACTORY_MAP.put("println", Factory.of(Object.class, Functions::println));
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
    index d45be5389..173814f6e 100644
    a b import org.openstreetmap.josm.tools.RotationAngle;  
    4141import org.openstreetmap.josm.tools.StreamUtils;
    4242import org.openstreetmap.josm.tools.Territories;
    4343import org.openstreetmap.josm.tools.Utils;
     44import org.openstreetmap.josm.tools.RotationAngle.WayDirectionRotationAngle;
    4445
    4546/**
    4647 * List of functions that can be used in MapCSS expressions.
    public final class Functions {  
    477478        return Collections.singletonList(env.parent.get(key));
    478479    }
    479480
     481    /**
     482     * Get the rotation angle of the preceding parent way segment at the node location.
     483     * If there is no preceding parent way segment, the following way segment is used instead.
     484     * Requires a parent way object matched via <a href="https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#LinkSelector">child selector</a>.
     485     *
     486     * @param env the environment
     487     * @return the rotation angle of the parent way segment at the node in radians, otherwise null if there is no matching parent way or the object is not a node
     488     * @since xxx
     489     */
     490    public static Double parent_way_angle(final Environment env) {
     491        if (env.osm instanceof Node && env.parent instanceof Way) {
     492            return WayDirectionRotationAngle.getRotationAngleForNodeOnWay((Node)env.osm, (Way)env.parent);
     493        }
     494        return null;
     495    }
     496
    480497    /**
    481498     * Gets the value of the key {@code key} from the object's child.
    482499     * @param env the environment