I am trying to define the value for the method PropertyFactory.iconImage
for my layer object. The return value PropertyValue<String>
should use a certain field inside the Feature to define it's value.
The result could look something like that:
PropertyFactory.iconImage(Expression.step(Expression.get("myfield"),"mydefaultValue", Expression.Stop.stop("case1", "valueForCase1"), Expression.Stop.stop("case2", "valueForCase2"));
Unfortunately I was not able to find a similar solution so far.
The following expression solved my problem:
SymbolLayer("asset-layer", "assetMapDataSource").withProperties(
PropertyFactory.iconImage(Expression.match(
Expression.get("asset_type"), Expression.literal("bbq_default"),
Expression.stop("bridge", Expression.literal("bridge_default")))))
Edit:
Some more information why I used the method in my example:
- PropertyFactory.iconImage expects a string which points to a certain bitmap that you have saved before via MapBoxMap.addImage(...).
- Expression.match is used to "match" a certain String based on the given stop and default cases.
- Expression.get is used to access a certain field inside your feature property. In this case the field "asset_type" provides a certain type that I can match against.
- The default case of the Expression.match and each Expression.stop are using the Expression.literal. This method is used to tell the underlying expression system that your value is from type x (in that case String). Take a look at the Expression.literal methods to get an idea of that.
- Each Expression.stop is used to symbolize that the Expression.match is trying to "match" the given value from the first parameter of Expression.stop against the given Expression.get value. If Expression.get and that method value are the same, the 2nd value of the Expression.stop is used which provides the actual value for the Expression.iconImage. If the underlying expression system wasn't able to find a "matching" stop for the given Expression.get value, the system will use the default value (in that case Expression.literal("bbq_default")).