Package org.geotools.mbstyle
Class MBStyle
- Object
-
- 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 Summary
Fields Modifier and Type Field Description JSONObject
json
JSON document being wrapped by this class.
-
Constructor Summary
Constructors Constructor Description MBStyle(JSONObject json)
MBStyle wrapper on the provided json
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MBStyle
create(Object json)
Parse MBStyle for the provided json.Number
getBearing()
(Optional) Default bearing, in degrees clockwise from true north.Point2D
getCenter()
(Optional) Default map center in longitude and latitude.String
getGlyphs()
(Optional) A URL template for loading signed-distance-field glyph sets in PBF format.JSONObject
getMetadata()
(Optional) Arbitrary properties useful to track with the stylesheet, but do not influence rendering.String
getName()
A human-readable name for the styleNumber
getPitch()
(Optional) Default pitch, in degrees.Map<String,MBSource>
getSources()
Data source specifications.String
getSprite()
A base URL for retrieving the sprite image and metadata.Number
getZoom()
(Optional) Default zoom level.MBLayer
layer(String id)
Access the layer with the provided id.List<MBLayer>
layers()
Access all layers.List<MBLayer>
layers(String source)
Access layers matching provided source.StyledLayerDescriptor
transform()
Transform MBStyle to a GeoTools StyledLayerDescriptor.
-
-
-
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(String source) throws MBFormatException
Access layers matching provided source.- Parameters:
source
- Data source- Returns:
- list of layers matching provided source
- Throws:
MBFormatException
-
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
-
-