I've taken the Geotools example for showing map data. There is a function setting a color (yellow) for selected items. The function sets the rest of the items to a default color even though the layer has another defined color. I would like to have the color unchanged for the not-selected items, but the yellow color for the selected items. How can I change the code to keep the original color setting while setting yellow for the selected items? See example:
public void displaySelectedFeatures(Set<FeatureId> IDs) {
Style style;
if (IDs.isEmpty()) {
style = createDefaultStyle();
} else {
style = createSelectedStyle(IDs);
}
Layer layer = mapFrame.getMapContent().layers().get(0);
((FeatureLayer) layer).setStyle(style);
mapFrame.getMapPane().repaint();
}
private Style createDefaultStyle() {
Rule rule = createRule(LINE_COLOUR, FILL_COLOUR);
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(rule);
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
private Style createSelectedStyle(Set<FeatureId> IDs) {
Rule selectedRule = createRule(SELECTED_COLOUR, SELECTED_COLOUR);
selectedRule.setFilter(ff.id(IDs));
Rule otherRule = createRule(LINE_COLOUR, FILL_COLOUR);
otherRule.setElseFilter(true);
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(selectedRule);
fts.rules().add(otherRule);
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
return style;
}