Class MBLayer
- Object
-
- 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 factoryprotected 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 conversionsprotected StyleFactory
sf
Shared style factory
-
Constructor Summary
Constructors Constructor Description MBLayer(JSONObject json, MBObjectParser parse)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static MBLayer
create(JSONObject layer)
Factory method creating the appropriate MBStyle based on the "type" indicated in the layer JSON.boolean
equals(Object obj)
Equality based on wrappedjson
.Filter
filter()
The "filter" as a GeoToolsFilter
suitable for feature selection, as defined bygetFilter()
.MBFilter
getFilter()
A MBFilter wrapping optional json specifying conditions on source features.String
getId()
Unique layer name.JSONObject
getJson()
JSONObject
getLayout()
Layout properties for the layer.int
getMaxZoom()
The maximum zoom level on which the layer gets parsed and appears on.JSONObject
getMetadata()
Arbitrary properties useful to track with the layer, but do not influence rendering.int
getMinZoom()
The minimum zoom level on which the layer gets parsed and appears on.JSONObject
getPaint()
Default paint properties for this layer.String
getRef()
References another layer to copy type, source, source-layer, minzoom, maxzoom, filter, and layout properties from.String
getSource()
Name of a source description to be used for this layer.String
getSourceLayer()
Layer to use from a vector tile source.abstract String
getType()
Rendering type of this layer.MBLayer.Visibility
getVisibility()
Layout setting - whether this layer is displayed.int
hashCode()
Hashcode based on wrappedjson
.JSONObject
layout()
Query for layout information (making use ofgetRef()
if available).JSONObject
paint()
Query for paint information (making use ofgetRef()
if available).String
toString()
List<FeatureTypeStyle>
transform(MBStyle styleContext)
Transforms a givenMBLayer
to a GeoToolsFeatureTypeStyle
.List<FeatureTypeStyle>
transform(MBStyle styleContext, Double minScaleDenominator, Double maxScaleDenominator)
Transforms a givenMBLayer
to a GeoToolsFeatureTypeStyle
.abstract List<FeatureTypeStyle>
transformInternal(MBStyle styleContext)
boolean
visibility()
Whether this layer is displayed.
-
-
-
Field Detail
-
parse
protected final MBObjectParser parse
Helper class used to provide json access and expression / filter conversions
-
ff
protected final FilterFactory ff
Shared filter factory
-
sf
protected final StyleFactory sf
Shared style factory
-
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
-
MBLayer
public MBLayer(JSONObject json, MBObjectParser parse)
-
-
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 GeoToolsFilter
viafilter()
.- Returns:
- MBFilter expression specifying conditions on source features.
-
filter
public Filter filter()
The "filter" as a GeoToolsFilter
suitable for feature selection, as defined bygetFilter()
.- 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 ofgetRef()
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 ofgetRef()
if available).- Returns:
- Paint properties to use for this layer.
-
transform
public List<FeatureTypeStyle> transform(MBStyle styleContext, Double minScaleDenominator, Double maxScaleDenominator)
Transforms a givenMBLayer
to a GeoToolsFeatureTypeStyle
.- 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 rulesmaxScaleDenominator
- 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 givenMBLayer
to a GeoToolsFeatureTypeStyle
.- 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.
-
transformInternal
public abstract List<FeatureTypeStyle> transformInternal(MBStyle styleContext)
-
-