@Override public Feature decorate(Feature feature, KmlEncodingContext context) { Placemark pm = (Placemark) feature; // while it's possible to have more than one style object, GE will only paint // the first one Style style = pm.createAndAddStyle(); List<Symbolizer> symbolizers = context.getCurrentSymbolizers(); SimpleFeature sf = context.getCurrentFeature(); if (symbolizers.size() > 0 && sf.getDefaultGeometry() != null) { // sort by point, text, line and polygon Map<Class, List<Symbolizer>> classified = classifySymbolizers(symbolizers); // if no point symbolizers, create a default one List<Symbolizer> points = classified.get(PointSymbolizer.class); if (points.size() == 0) { if (context.isDescriptionEnabled()) { setDefaultIconStyle(style, sf, context); } } else { org.geotools.styling.Style wholeStyle = context.getCurrentLayer().getStyle(); IconProperties properties = IconPropertyExtractor.extractProperties(wholeStyle, sf); setIconStyle(style, wholeStyle, properties, context); } // handle label styles List<Symbolizer> texts = classified.get(TextSymbolizer.class); if (texts.size() == 0) { if (context.isDescriptionEnabled()) { setDefaultLabelStyle(style); } } else { // the XML schema allows only one text style, follow painter's model // and set the last one TextSymbolizer lastTextSymbolizer = (TextSymbolizer) texts.get(texts.size() - 1); setLabelStyle(style, sf, lastTextSymbolizer); } // handle line styles List<Symbolizer> lines = classified.get(LineSymbolizer.class); // the XML schema allows only one line style, follow painter's model // and set the last one if (lines.size() > 0) { LineSymbolizer lastLineSymbolizer = (LineSymbolizer) lines.get(lines.size() - 1); setLineStyle(style, sf, lastLineSymbolizer.getStroke()); } // handle polygon styles boolean forceOutiline = lines.size() == 0; List<Symbolizer> polygons = classified.get(PolygonSymbolizer.class); if (polygons.size() > 0) { // the XML schema allows only one polygon style, follow painter's model // and set the last one PolygonSymbolizer lastPolygonSymbolizer = (PolygonSymbolizer) polygons.get(polygons.size() - 1); setPolygonStyle(style, sf, lastPolygonSymbolizer, forceOutiline); } } return feature; }
@Override public Feature decorate(Feature feature, KmlEncodingContext context) { Placemark pm = (Placemark) feature; // try with the template SimpleFeature sf = context.getCurrentFeature(); String title = null; try { title = context.getTemplate().title(sf); } catch (IOException e) { String msg = "Error occured processing 'title' template."; LOGGER.log(Level.WARNING, msg, e); } // if we got nothing, set the title to the ID, but also try the text symbolizers if (title == null || "".equals(title)) { title = sf.getID(); StringBuffer label = new StringBuffer(); for (Symbolizer sym : context.getCurrentSymbolizers()) { if (sym instanceof TextSymbolizer) { Expression e = SLD.textLabel((TextSymbolizer) sym); String value = e.evaluate(feature, String.class); if ((value != null) && !"".equals(value.trim())) { label.append(value); } } } if (label.length() > 0) { title = label.toString(); } } pm.setName(title); return pm; }