The LuciadFusion Platform includes a few mechanisms for customizing the styling of a layer. By default it picks up SLD files that are located next to the data, see TLcdSLDFileGXYLayerFactory. LuciadFusion Studio also allows you to assign SLD styles to specific data.

This only affects the WMS and WMTS services. WCS and WFS deliver raw, unstyled data.

You may need more flexibility than SLD provides, though. In that case, you can use Java code to add custom styling logic. The following sections describe possible approaches to customizing the styling for a data format, and customizing a particular style.

Customizing styling for a data format

You can customize the styling for a particular data format by plugging in your own layer factory. The data format can be either a custom format, or an existing format such as SHP files. See How to plug in your own data format for more information about plugging in your own format.

Make sure not to associate a style with the data in LuciadFusion Studio, so that no SLD styling is applied, and your custom layer factory can be used. Now register a custom layer factory with the service loader by using the @LcdService annotation. You do not have to specify a priority in the LcdService. By default, your custom layer factory already has a higher priority than pre-configured layer factories. The custom layer factory detects the format of a data set by inspecting the ILcdModelDescriptor. If it is a suitable format, the layer factory returns a layer. If it is not a suitable format, the layer factory returns null, leaving layer creation to another factory.

Program: Custom format specific layer factory
@LcdService(service = ILcdGXYLayerFactory.class)
public class CustomFormatSpecificGXYLayerFactory implements ILcdGXYLayerFactory {

  public ILcdGXYLayer createGXYLayer(ILcdModel aModel) {
    if (!(aModel.getModelDescriptor() instanceof TLcdFormatSpecificModelDescriptor)) {
      return null; // let some other factory handle it
    TLcdGXYLayer layer = TLcdGXYLayer.create(aModel);
    return layer;

The sample code includes a host of example layer factories targeting various use cases, such as visualizing street data, aeronautical data or imagery. Look for implementations of ILcdGXYLayerFactory, such as samples.gxy.labels.streets.StatesLayerFactory. Note that not all of those factories have the @LcdService annotation and the check to distinguish your own data format from others, which is required to make it work as expected in the LuciadFusion Platform.

Customizing a particular style

Instead of changing the styling for all data of a particular format, you may need to differentiate the data styling based on other criteria, and you may still want to manage your styles using LuciadFusion Studio. For example, you could set up a WMS service that provides a certain trajectory data set as two distinct layers: once with plain lines for the trajectories, and once as a density map, also known as a heat map.

You can achieve this by:

  1. Crafting an .sld file that has a uniquely identifiable name.

  2. Plugging in an ILcdSLDGXYLayerFactory service that recognizes that name and creates a custom layer. It may use any painting code, and does not have to be SLD-related.

You can find examples in samples/resources/Data/LuciadFusionSLD/SampleDensityLineStyle.sld and samples.fusion.sld.DensityLineStyleLayerFactory.

You can try it out by following these steps:

  1. Start LuciadFusion Platform and Studio as you always do.

  2. Upload the abovementioned .sld file.

  3. Upload a data file with lines, for example samples/resources/Data/Shp/Usa/trajectories.shp. Do not forget to include the companion files if they exist, such as trajectories.dbf or trajectories.prj. If there is a directory.ref file, select that as well.

  4. Create a new product, add the trajectory data to it, and associate the uploaded style with it.

  5. Preview the product and see how the density style is applied.

trajectory density product preview
Figure 1. LuciadFusion Studio preview of a product containing trajectory data associated with the density style

Beware that such .sld files do not have the desired effect without the paired layer factory. They will also not work in other SLD-capable tools.

You could also use this approach to plug in vendor-specific SLD extensions. For example, this technique is used to add S52 (ECDIS) styling capabilities to SLD in a Luciad-specific vendor extension.