Class MBStyle


  • public class MBStyle
    extends Object
    MapBox Style implemented as wrapper around parsed JSON file.

    This class is responsible for presenting the wrapped JSON in an easy to use / navigate form for Java developers:

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

    Access methods should return Java Objects, rather than generic maps. Additional access methods to perform common queries are expected and encouraged.

    This class works closely with MBLayer hierarchy used to represent the fill, line, symbol, raster, circle layers. Additional support will be required to work with sprites and glyphs.

    Author:
    Jody Garnett (Boundless)
    • Field Detail

      • json

        public final JSONObject json
        JSON document being wrapped by this class.

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

    • Constructor Detail

      • MBStyle

        public MBStyle​(JSONObject json)
        MBStyle wrapper on the provided json
        Parameters:
        json - Map Box Style as parsed JSON
    • Method Detail

      • create

        public static MBStyle create​(Object json)
                              throws MBFormatException
        Parse MBStyle for the provided json.
        Parameters:
        json - Required to be a JSONObject
        Returns:
        MBStyle wrapping the provided json
        Throws:
        MBFormatException - JSON content inconsistent with specification
      • layer

        public MBLayer layer​(String id)
        Access the layer with the provided id.
        Parameters:
        id - Id of layer to access
        Returns:
        layer with the provided id, or null if not found.
      • layers

        public List<MBLayer> layers()
        Access all layers.
        Returns:
        list of layers
      • getName

        public String getName()
        A human-readable name for the style
        Returns:
        human-readable name, or "name" if the style has no name.
      • getMetadata

        public JSONObject getMetadata()
        (Optional) Arbitrary properties useful to track with the stylesheet, but do not influence rendering. Properties should be prefixed to avoid collisions, like 'mapbox:'.
        Returns:
        JSONObject containing the metadata, or an empty JSON object the style has no metadata.
      • getCenter

        public Point2D getCenter()
        (Optional) Default map center in longitude and latitude. The style center will be used only if the map has not been positioned by other means (e.g. map options or user interaction).
        Returns:
        A Point for the map center, or null if the style contains no center.
      • getZoom

        public Number getZoom()
        (Optional) Default zoom level. The style zoom will be used only if the map has not been positioned by other means (e.g. map options or user interaction).
        Returns:
        Number for the zoom level, or null if the style has no default zoom level.
      • getBearing

        public Number getBearing()
        (Optional) Default bearing, in degrees clockwise from true north. The style bearing will be used only if the map has not been positioned by other means (e.g. map options or user interaction).
        Returns:
        The bearing in degrees. Defaults to 0 if the style has no bearing.
      • getPitch

        public Number getPitch()
        (Optional) Default pitch, in degrees. Zero is perpendicular to the surface, for a look straight down at the map, while a greater value like 60 looks ahead towards the horizon. The style pitch will be used only if the map has not been positioned by other means (e.g. map options or user interaction).
        Returns:
        The pitch in degrees. Defaults to 0 if the style has no pitch.
      • getSprite

        public String getSprite()
        A base URL for retrieving the sprite image and metadata. The extensions .png, .json and scale factor @2x.png will be automatically appended. This property is required if any layer uses the background-pattern, fill-pattern, line-pattern, fill-extrusion-pattern, or icon-image properties.
        Returns:
        The sprite URL, or null if the style has no sprite URL.
      • getGlyphs

        public String getGlyphs()
        (Optional) A URL template for loading signed-distance-field glyph sets in PBF format. The URL must include {fontstack} and {range} tokens. This property is required if any layer uses the text-field layout property.
        Example:
        "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"
        Returns:
        The glyphs URL template, or null if the style has no glyphs URL template.
      • transform

        public StyledLayerDescriptor transform()
        Transform MBStyle to a GeoTools StyledLayerDescriptor.
        Returns:
        StyledLayerDescriptor