Class ElemStyles

    • Constructor Detail

      • ElemStyles

        public ElemStyles()
        Constructs a new ElemStyles.
      • ElemStyles

        public ElemStyles​(java.util.Collection<StyleSource> sources)
        Constructs a new ElemStyles with specific style sources. This does not listen to preference changes, and therefore should only be used with layers that have specific drawing requirements.
        Parameters:
        sources - The style sources (these cannot be added to, or removed from)
        Since:
        17862
    • Method Detail

      • clearCached

        public void clearCached()
        Clear the style cache for all primitives of all DataSets.
      • getStyleSources

        public java.util.List<StyleSourcegetStyleSources()
        Returns the list of style sources.
        Returns:
        the list of style sources
      • getBackgroundColor

        public java.awt.Color getBackgroundColor()
        Returns the background color.
        Returns:
        the background color
      • get

        public StyleElementList get​(IPrimitive osm,
                                    double scale,
                                    NavigatableComponent nc)
        Create the list of styles for one primitive.
        Parameters:
        osm - the primitive
        scale - the scale (in meters per 100 pixel)
        nc - display component
        Returns:
        list of styles
        Since:
        13810 (signature)
      • getStyleCacheWithRange

        public Pair<StyleElementList,​RangegetStyleCacheWithRange​(IPrimitive osm,
                                                                         double scale,
                                                                         NavigatableComponent nc)
        Create the list of styles and its valid scale range for one primitive. Automatically adds default styles in case no proper style was found. Uses the cache, if possible, and saves the results to the cache.
        Parameters:
        osm - OSM primitive
        scale - scale
        nc - navigable component
        Returns:
        pair containing style list and range
        Since:
        13810 (signature)
      • getImpl

        private Pair<StyleElementList,​RangegetImpl​(IPrimitive osm,
                                                           double scale,
                                                           NavigatableComponent nc)
        Create the list of styles and its valid scale range for one primitive. This method does multipolygon handling. If the primitive is a way, look for multipolygon parents. In case it is indeed member of some multipolygon as role "outer", all area styles are removed. (They apply to the multipolygon area.) Outer ways can have their own independent line styles, e.g. a road as boundary of a forest. Otherwise, in case, the way does not have an independent line style, take a line style from the multipolygon. If the multipolygon does not have a line style either, at least create a default line style from the color of the area. Now consider the case that the way is not an outer way of any multipolygon, but is member of a multipolygon as "inner". First, the style list is regenerated, considering only tags of this way. Then check, if the way describes something in its own right. (linear feature or area) If not, add a default line style from the area color of the multipolygon.
        Parameters:
        osm - OSM primitive
        scale - scale
        nc - navigable component
        Returns:
        pair containing style list and range
      • generateStyles

        public Pair<StyleElementList,​RangegenerateStyles​(IPrimitive osm,
                                                                 double scale,
                                                                 boolean pretendWayIsClosed)
        Create the list of styles and its valid scale range for one primitive. Loops over the list of style sources, to generate the map of properties. From these properties, it generates the different types of styles.
        Parameters:
        osm - the primitive to create styles for
        scale - the scale (in meters per 100 px), must be > 0
        pretendWayIsClosed - For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.
        Returns:
        the generated styles and the valid range as a pair
        Since:
        13810 (signature)
      • addIfNotNull

        private static <T> void addIfNotNull​(java.util.List<T> list,
                                             T obj)
      • isDefaultNodes

        private boolean isDefaultNodes()
        Draw a default node symbol for nodes that have no style?
        Returns:
        true if default node symbol must be drawn
      • isDefaultLines

        private boolean isDefaultLines()
        Draw a default line for ways that do not have an own line style?
        Returns:
        true if default line must be drawn
      • fromCanvas

        private <T> T fromCanvas​(java.lang.String key,
                                 T def,
                                 java.lang.Class<T> c)
      • isDrawMultipolygon

        public boolean isDrawMultipolygon()
        Determines whether multipolygons must be drawn.
        Returns:
        whether multipolygons must be drawn.
      • setDrawMultipolygon

        public void setDrawMultipolygon​(boolean drawMultipolygon)
        Sets whether multipolygons must be drawn.
        Parameters:
        drawMultipolygon - whether multipolygons must be drawn
      • clear

        void clear()
        remove all style sources; only accessed from MapPaintStyles
      • add

        void add​(StyleSource style)
        add a style source; only accessed from MapPaintStyles
        Parameters:
        style - style source to add
      • remove

        boolean remove​(StyleSource style)
        remove a style source; only accessed from MapPaintStyles
        Parameters:
        style - style source to remove
        Returns:
        true if this list contained the specified element
      • setStyleSources

        void setStyleSources​(java.util.Collection<StyleSource> sources)
        set the style sources; only accessed from MapPaintStyles
        Parameters:
        sources - new style sources
      • getAreaElemStyle

        public static AreaElement getAreaElemStyle​(IPrimitive p,
                                                   boolean pretendWayIsClosed)
        Returns the first AreaElement for a given primitive.
        Parameters:
        p - the OSM primitive
        pretendWayIsClosed - For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.
        Returns:
        first AreaElement found or null.
        Since:
        13810 (signature)
      • hasAreaElemStyle

        public static boolean hasAreaElemStyle​(IPrimitive p,
                                               boolean pretendWayIsClosed)
        Determines whether primitive has an AreaElement.
        Parameters:
        p - the OSM primitive
        pretendWayIsClosed - For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.
        Returns:
        true if primitive has an AreaElement
        Since:
        13810 (signature)
      • hasOnlyAreaElements

        public static boolean hasOnlyAreaElements​(IPrimitive p)
        Determines whether primitive has area-type StyleElements, but no line-type StyleElements. TextElement is ignored, as it can be both line and area-type.
        Parameters:
        p - the OSM primitive
        Returns:
        true if primitive has area elements, but no line elements
        Since:
        12700, 13810 (signature)
      • getPreferenceCached

        public java.lang.String getPreferenceCached​(StyleSource source,
                                                    java.lang.String key,
                                                    java.lang.String def)
        Looks up a preference value and ensures the style cache is invalidated as soon as this preference value is changed by the user. In addition, it adds an intermediate cache for the preference values, as frequent preference lookup (using Config.getPref().get()) for each primitive can be slow during rendering. If the default value can be converted to a Color, the NamedColorProperty is retrieved as string.
        Parameters:
        source - style source
        key - preference key
        def - default value
        Returns:
        the corresponding preference value
        See Also:
        AbstractPreferences.get(String, String)