Package org.geotools.mbstyle
Class MBStyle
Object
MBStyle
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
FieldsModifier and TypeFieldDescriptionfinal JSONObject
JSON document being wrapped by this class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MBStyle
Parse MBStyle for the provided json.(Optional) Default bearing, in degrees clockwise from true north.(Optional) Default map center in longitude and latitude.(Optional) A URL template for loading signed-distance-field glyph sets in PBF format.JSONObject
(Optional) Arbitrary properties useful to track with the stylesheet, but do not influence rendering.getName()
A human-readable name for the stylegetPitch()
(Optional) Default pitch, in degrees.Data source specifications.A base URL for retrieving the sprite image and metadata.getZoom()
(Optional) Default zoom level.Access the layer with the provided id.layers()
Access all layers.Access layers matching provided source.Transform MBStyle to a GeoTools StyledLayerDescriptor.
-
Field Details
-
json
public final JSONObject jsonJSON 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 Details
-
MBStyle
public MBStyle(JSONObject json) MBStyle wrapper on the provided json- Parameters:
json
- Map Box Style as parsed JSON
-
-
Method Details
-
create
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
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
Access all layers.- Returns:
- list of layers
-
layers
Access layers matching provided source.- Parameters:
source
- Data source- Returns:
- list of layers matching provided source
- Throws:
MBFormatException
-
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
(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
(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
(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
(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
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
(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.
-
getSources
Data source specifications. -
transform
Transform MBStyle to a GeoTools StyledLayerDescriptor.- Returns:
- StyledLayerDescriptor
-