Package org.geotools.mbstyle.transform
Class MBStyleTransformer
- Object
-
- MBStyleTransformer
-
public class MBStyleTransformer extends Object
Responsible for traverseMBStyleand generatingStyledLayerDescriptor.- Author:
- Jody Garnett (Jody Garnett)
-
-
Field Summary
Fields Modifier and Type Field Description protected static PatternmapboxTokenPattern
-
Constructor Summary
Constructors Constructor Description MBStyleTransformer(MBObjectParser parse)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExpressioncqlExpressionFromTokens(String tokenStr)Take a string that may contain Mapbox-style tokens, and convert it to a CQL expression.StringcqlStringFromTokens(String tokenStr)Take a string that may contain Mapbox-style tokens, and convert it to a CQL expression string.ExternalGraphiccreateExternalGraphicForSprite(Expression iconName, Expression iconSize, MBStyle styleContext)Takes the name of an icon, and anMBStyleas a context, and returns an External Graphic referencing the full URL of the image for consumption by theSpriteGraphicFactory.ExternalGraphiccreateExternalGraphicForSprite(Expression iconName, MBStyle styleContext)Takes the name of an icon, and anMBStyleas a context, and returns an External Graphic referencing the full URL of the image for consumption by theSpriteGraphicFactory.List<String>getDefaultFonts()static <T> TrequireLiteral(Expression expression, Class<T> clazz, T fallback, String propertyName, String layerId)Utility method for getting a concrete value out of an expression, used by transformer methods when GeoTools is unable to accept an expression.
-
-
-
Field Detail
-
mapboxTokenPattern
protected static final Pattern mapboxTokenPattern
-
-
Constructor Detail
-
MBStyleTransformer
public MBStyleTransformer(MBObjectParser parse)
-
-
Method Detail
-
createExternalGraphicForSprite
public ExternalGraphic createExternalGraphicForSprite(Expression iconName, Expression iconSize, MBStyle styleContext)
Takes the name of an icon, and anMBStyleas a context, and returns an External Graphic referencing the full URL of the image for consumption by theSpriteGraphicFactory. (The format of the image will beSpriteGraphicFactory.FORMAT).- Parameters:
iconName- The name of the icon inside the spritesheet.iconSize- The size (scale multiplier) to apply to the icon. (Nullable).styleContext- The style context in which to resolve the icon name to the full sprite URL (for consumption by theSpriteGraphicFactory).- Returns:
- An external graphic with the full URL of the mage for the
SpriteGraphicFactory. - See Also:
SpriteGraphicFactory
-
createExternalGraphicForSprite
public ExternalGraphic createExternalGraphicForSprite(Expression iconName, MBStyle styleContext)
Takes the name of an icon, and anMBStyleas a context, and returns an External Graphic referencing the full URL of the image for consumption by theSpriteGraphicFactory. (The format of the image will beSpriteGraphicFactory.FORMAT).- Parameters:
iconName- The name of the icon inside the spritesheet.styleContext- The style context in which to resolve the icon name to the full sprite URL (for consumption by theSpriteGraphicFactory).- Returns:
- An external graphic with the full URL of the mage for the
SpriteGraphicFactory. - See Also:
SpriteGraphicFactory
-
cqlStringFromTokens
public String cqlStringFromTokens(String tokenStr)
Take a string that may contain Mapbox-style tokens, and convert it to a CQL expression string.E.g., convert "
String with {tokens}" to a CQL Expression (String) "String with ${tokens}".See documentation of Mapbox {token} values, linked below.
- Parameters:
tokenStr- A string with mapbox-style tokens- Returns:
- A CQL Expression
- See Also:
- Mapbox Style Spec: {token} values for icon-image, Mapbox Style Spec: {token} values for text-field
-
cqlExpressionFromTokens
public Expression cqlExpressionFromTokens(String tokenStr)
Take a string that may contain Mapbox-style tokens, and convert it to a CQL expression.E.g., convert "
String with {tokens}" to a CQL Expression: "String with ${tokens}".See documentation of Mapbox {token} values, linked below.
- Parameters:
tokenStr- A string with mapbox-style tokens- Returns:
- A CQL Expression
- See Also:
- Mapbox Style Spec: {token} values for icon-image, Mapbox Style Spec: {token} values for text-field
-
requireLiteral
public static <T> T requireLiteral(Expression expression, Class<T> clazz, T fallback, String propertyName, String layerId)
Utility method for getting a concrete value out of an expression, used by transformer methods when GeoTools is unable to accept an expression.- If the provided
Expressionis aLiteral, evaluates it and returns the value. - Otherwise, returns the provided fallback value and logs a warning that dynamic styling is not yet supported for this property.
- Parameters:
expression- The expressionclazz- The type to provide as the context for the expression's evaluation.fallback- The value to return if the expression is not a literalpropertyName- The name of the property that the expression corresponds to, for logging purposes.layerId- The ID of the layer that the expression corresponds to, for logging purposes.- Returns:
- The evaluated value of the provided
Expression, or the provided fallback value.
- If the provided
-
-