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 {
|
| 216 | 216 | FACTORY_MAP.put("parent_osm_id", Factory.ofEnv(Functions::parent_osm_id)); |
| 217 | 217 | FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag)); |
| 218 | 218 | 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)); |
| 219 | 220 | FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus)); |
| 220 | 221 | FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print)); |
| 221 | 222 | FACTORY_MAP.put("println", Factory.of(Object.class, Functions::println)); |
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;
|
| 41 | 41 | import org.openstreetmap.josm.tools.StreamUtils; |
| 42 | 42 | import org.openstreetmap.josm.tools.Territories; |
| 43 | 43 | import org.openstreetmap.josm.tools.Utils; |
| | 44 | import org.openstreetmap.josm.tools.RotationAngle.WayDirectionRotationAngle; |
| 44 | 45 | |
| 45 | 46 | /** |
| 46 | 47 | * List of functions that can be used in MapCSS expressions. |
| … |
… |
public final class Functions {
|
| 477 | 478 | return Collections.singletonList(env.parent.get(key)); |
| 478 | 479 | } |
| 479 | 480 | |
| | 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 | |
| 480 | 497 | /** |
| 481 | 498 | * Gets the value of the key {@code key} from the object's child. |
| 482 | 499 | * @param env the environment |