/** * This will extract the properties from the sld (first occurence / best effort (not every posibility is checked)). * * @return map of properties */ public static Map<String, Object> getProperties(UserStyleInfo usi) { Map<String, Object> props = new HashMap<String, Object>(); if (usi != null) { if (usi.getTitle() != null) { props.put(STYLENAME, usi.getTitle()); } SymbolizerTypeInfo symbolizer = extractSymbolizer(usi); if (symbolizer != null) { if (symbolizer instanceof PointSymbolizerInfo) { extractProperties((PointSymbolizerInfo) symbolizer, props); } else if (symbolizer instanceof LineSymbolizerInfo) { extractProperties((LineSymbolizerInfo) symbolizer, props); } else if (symbolizer instanceof PolygonSymbolizerInfo) { extractProperties((PolygonSymbolizerInfo) symbolizer, props); } } TextSymbolizerInfo textSym = extractTextSymbolizer(usi); if (textSym != null && textSym.getLabel() != null && textSym.getLabel().getExpressionList().size() > 0 && textSym.getLabel().getExpressionList().get(0) instanceof PropertyNameInfo) { props.put(LABELFEATURENAME, textSym.getLabel().getExpressionList().get(0).getValue()); } } return props; }
/** * Creates a text symbolizer with the specified font style. * * @param style font style * @return the symbolizer */ public static TextSymbolizerInfo createSymbolizer(FontStyleInfo style) { TextSymbolizerInfo symbolizerInfo = new TextSymbolizerInfo(); FontInfo font = new FontInfo(); font.setFamily(style.getFamily()); font.setStyle(style.getStyle()); font.setWeight(style.getWeight()); font.setSize(style.getSize()); symbolizerInfo.setFont(font); symbolizerInfo.setFill(createFill(style.getColor(), style.getOpacity())); return symbolizerInfo; }
TextSymbolizerInfo tsi = new TextSymbolizerInfo(); tsi.setLabel(new LabelInfo()); PropertyNameInfo pni = new PropertyNameInfo(); pni.setValue(properties.get(LABELFEATURENAME).toString()); tsi.getLabel().getExpressionList().add(pni); tsi.getLabel().setValue("\n "); for (RuleInfo rule : rules) { rule.getSymbolizerList().add(tsi);