Ticket #17845: 17845_v3.patch

File 17845_v3.patch, 1.9 KB (added by taylor.smock, 7 years ago)

Same as v2, except with the ability to county multiple roles at once (count_role->count_roles) (probably unnecessary, count_role("to") + count_role("via") should be functionally equivalent)

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

     
    2828import org.openstreetmap.josm.data.osm.IPrimitive;
    2929import org.openstreetmap.josm.data.osm.Node;
    3030import org.openstreetmap.josm.data.osm.OsmPrimitive;
     31import org.openstreetmap.josm.data.osm.Relation;
     32import org.openstreetmap.josm.data.osm.RelationMember;
    3133import org.openstreetmap.josm.data.osm.Way;
    3234import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    3335import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     
    570572        }
    571573
    572574        /**
     575         * Returns true if role is in relation. Returns false if not a relation or it does not have the role.
     576         * @param env the environment
     577         * @param roles The roles to count in the relation
     578         * @return The number of relation members with the specified role
     579         * @since xxx
     580         */
     581        public static int count_roles(final Environment env, String... roles) { // NO_UCD (unused code)
     582            int rValue = 0;
     583            if (env.osm instanceof Relation) {
     584                List<String> roleList = Arrays.asList(roles);
     585                Relation rel = (Relation) env.osm;
     586                for (RelationMember member : rel.getMembers()) {
     587                    if (roleList.contains(member.getRole())) rValue++;
     588                }
     589            }
     590            return rValue;
     591        }
     592
     593        /**
    573594         * Returns the area of a closed way or multipolygon in square meters or {@code null}.
    574595         * @param env the environment
    575596         * @return the area of a closed way or multipolygon in square meters or {@code null}