The domain objects of the Lucy drawing add-on are TLcySLDDomainObject
instances.
These domain objects contain both the geometry and the style of the object.
See the reference guide of the drawing add-on for more information.
The style is a TLcdSLDFeatureTypeStyle
and is accessible through the getStyle
and setStyle
methods.
This example shows how to retrieve the style of a polygon object, and update the fill color:
static void updateFillColor(ILcdModel aDrawingModel,
TLcySLDDomainObject aPolygonDomainObject,
String aColorValue) throws Exception {
//Since we are modifying the domain object, we need a lock
try (TLcdLockUtil.Lock lock = TLcdLockUtil.writeLock(aDrawingModel)) {
//Retrieve the SLD style from the domain object
TLcdSLDFeatureTypeStyle currentStyle = aPolygonDomainObject.getStyle();
//To update the style, we need to set a new TLcdSLDFeatureTypeStyle
//instance on the domain object
//Therefore, we first make a copy of the style
TLcdSLDFeatureTypeStyle copy =
TLcdSLDFeatureTypeStyleDecoder.decodeFromString(TLcdSLDFeatureTypeStyleEncoder.encodeToString(currentStyle));
//Retrieve the TLcdSLDPolygonSymbolizer from the SLD style
TLcdSLDPolygonSymbolizer polygonSymbolizer = findSymbolizer(copy, TLcdSLDPolygonSymbolizer.class);
//Adjust the fill color
TLcdSLDFill fill = new TLcdSLDFill();
fill.setCssParameter(TLcdSLDFill.CSS_PARAMETER_FILL, new TLcdSLDParameterValue(aColorValue));
polygonSymbolizer.setFill(fill);
//Replace the style on the drawing domain object with the updated copy
aPolygonDomainObject.setStyle(copy);
//Indicate to the model that the object has changed
aDrawingModel.elementChanged(aPolygonDomainObject, ILcdModel.FIRE_LATER);
} finally {
aDrawingModel.fireCollectedModelChanges();
}
}
Consult the SLD documentation for more information about working with SLD styles.