Class MBLayer

  • Direct Known Subclasses:
    BackgroundMBLayer, CircleMBLayer, FillExtrusionMBLayer, FillMBLayer, LineMBLayer, RasterMBLayer, SymbolMBLayer

    public abstract class MBLayer
    extends Object
    MBLayer wrapper (around one of the MBStyle layers).

    All methods act as accessors on provided JSON layer, no other state is maintained. This allows modifications to be made cleanly with out chance of side-effect.

    • get methods: access the json directly
    • query methods: provide logic / transforms to GeoTools classes as required.

    In the normal course of events MBLayer is constructed as a flyweight object by MBStyle to provide easy access to its layers list.

    Author:
    Torben Barsballe (Boundless)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MBLayer.Visibility
      Whether this layer is displayed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected FilterFactory ff
      Shared filter factory
      protected String id
      field access for "id" key (due to its use in error messages)
      protected JSONObject json
      JSON layer being wrapped.
      protected MBObjectParser parse
      Helper class used to provide json access and expression / filter conversions
      protected StyleFactory sf
      Shared style factory
    • Constructor Summary

      Constructors 
      Constructor Description
      MBLayer​(JSONObject json, MBObjectParser parse)  
    • Field Detail

      • parse

        protected final MBObjectParser parse
        Helper class used to provide json access and expression / filter conversions
      • json

        protected final JSONObject json
        JSON layer being wrapped.
      • id

        protected final String id
        field access for "id" key (due to its use in error messages)
    • Constructor Detail

    • Method Detail

      • create

        public static MBLayer create​(JSONObject layer)
        Factory method creating the appropriate MBStyle based on the "type" indicated in the layer JSON.
        Parameters:
        layer - JSON Layer definition
        Returns:
        Generated MBLayer subclass
      • getType

        public abstract String getType()
        Rendering type of this layer.

        One of:

        • fill:A filled polygon with an optional stroked border.
        • line: A stroked line.
        • symbol: An icon or a text label.
        • circle:A filled circle.
        • fill-extrusion: An extruded (3D) polygon.
        • raster: Raster map textures such as satellite imagery.
        • background: The background color or pattern of the map.
        Returns:
        One of fill, line, symbol, circle, fill-extrusion, raster, background.
      • getMetadata

        public JSONObject getMetadata()
        Arbitrary properties useful to track with the layer, but do not influence rendering. Properties should be prefixed to avoid collisions, like 'mapbox:' and 'gt:`.
        Returns:
        Arbitrary properties useful to track with the layer.
      • getRef

        public String getRef()
        References another layer to copy type, source, source-layer, minzoom, maxzoom, filter, and layout properties from. This allows the layers to share processing and be more efficient.
        Returns:
        References another layer to copy type, source, source-layer, minzoom, maxzoom, filter, and layout properties from.
      • getJson

        public JSONObject getJson()
      • getId

        public String getId()
        Unique layer name.
        Returns:
        layer name, required field
      • getSource

        public String getSource()
        Name of a source description to be used for this layer.

        While this value is optional, it may be obtained via getRef() if needed.

        Returns:
        name of source description to be used for this layer, or null if the style has no source.
      • getSourceLayer

        public String getSourceLayer()
        Layer to use from a vector tile source. Required if the source supports multiple layers.

        While this value is optional, it may be obtained via getRef() if needed.

        Returns:
        layer to use from a vector tile source, or null if the style has no source-layer.
      • getMinZoom

        public int getMinZoom()
        The minimum zoom level on which the layer gets parsed and appears on.
        Returns:
        minimum zoom level, or Integer.MIN_VALUE if the style has no minzoom.
      • getMaxZoom

        public int getMaxZoom()
        The maximum zoom level on which the layer gets parsed and appears on.
        Returns:
        maximum zoom level, or Integer.MAX_VALUE if the style has no maxzoom.
      • getFilter

        public MBFilter getFilter()
        A MBFilter wrapping optional json specifying conditions on source features. Only features that match the filter are displayed. This is available as a GeoTools Filter via filter().
        Returns:
        MBFilter expression specifying conditions on source features.
      • filter

        public Filter filter()
        The "filter" as a GeoTools Filter suitable for feature selection, as defined by getFilter().
        Returns:
        Filter, or Filter.INCLUDE if the style has no filter.
      • getLayout

        public JSONObject getLayout()
        Layout properties for the layer.

        Layout properties appear in the layer's "layout" object. They are applied early in the rendering process and define how data for that layer is passed to the renderer. For efficiency, a layer can share layout properties with another layer via the "ref" layer property, and should do so where possible. This will decrease processing time and allow the two layers will share GPU memory and other resources associated with the layer.

        Returns:
        Layout properties defined for layer, or an empty JSONObject if no layout properties are defined for the style.
      • layout

        public JSONObject layout()
        Query for layout information (making use of getRef() if available).
        Returns:
        Layout properties to use for this layer.
      • getPaint

        public JSONObject getPaint()
        Default paint properties for this layer.

        Paint properties are applied later in the rendering process. A layer that shares layout properties with another layer can have independent paint properties. Paint properties appear in the layer's "paint" object.

        Returns:
        Default paint properties for this layer, or an empty JSONObject if no paint properties are defined for the style.
      • getVisibility

        public MBLayer.Visibility getVisibility()
        Layout setting - whether this layer is displayed.
        Returns:
        One of visible, none. Defaults to visible if not defined in the style.
      • visibility

        public boolean visibility()
        Whether this layer is displayed.
        Returns:
        Whether the layout is visible. Defaults to true.
      • paint

        public JSONObject paint()
        Query for paint information (making use of getRef() if available).
        Returns:
        Paint properties to use for this layer.
      • transform

        public List<FeatureTypeStyle> transform​(MBStyle styleContext,
                                                Double minScaleDenominator,
                                                Double maxScaleDenominator)
        Transforms a given MBLayer to a GeoTools FeatureTypeStyle.
        Parameters:
        styleContext - The MBStyle to which this layer belongs, used to resolving sprite and glyph names to full urls.
        minScaleDenominator - Used to determine zoom level restrictions for generated rules
        maxScaleDenominator - Used to determine zoom level restrictions for generated rules
        Returns:
        A feature type style from the provided layer, or null if the visibility of that layer is false.
      • transform

        public final List<FeatureTypeStyle> transform​(MBStyle styleContext)
        Transforms a given MBLayer to a GeoTools FeatureTypeStyle.
        Parameters:
        styleContext - The MBStyle to which this layer belongs, used as a context for things like resolving sprite and glyph names to full urls.
        Returns:
        A feature type style from the provided layer, or null if the visibility of that layer is false.
      • hashCode

        public int hashCode()
        Hashcode based on wrapped json.
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object obj)
        Equality based on wrapped json.
        Overrides:
        equals in class Object
      • toString

        public String toString()
        Overrides:
        toString in class Object