Java Examples for org.geotools.styling.Mark
The following java examples will help you to understand the usage of org.geotools.styling.Mark. These source code samples are taken from different open source projects.
Example 1
| Project: geotools_trunk-master File: sldComplexTypes2.java View source code |
public Object getValue(Element element, ElementValue[] value, Attributes attrs1, Map hints) {
Mark symbol = StyleFactoryFinder.createStyleFactory().getDefaultMark();
for (int i = 0; i < value.length; i++) {
if ((value[i] == null) || value[i].getElement() == null) {
continue;
}
Element e = value[i].getElement();
if (elems[WELLKNOWNNAME].getName().equals(e.getName()))
symbol.setWellKnownName((Expression) value[i].getValue());
if (elems[FILL].getName().equals(e.getName()))
symbol.setFill((Fill) value[i].getValue());
if (elems[STROKE].getName().equals(e.getName()))
symbol.setStroke((Stroke) value[i].getValue());
}
return symbol;
}Example 2
| Project: geoserver-master File: ResourcePoolTest.java View source code |
@Test
public void testParseExternalMark() throws Exception {
StyleInfo si = getCatalog().getStyleByName(HUMANS);
// used to blow here with an NPE
Style s = si.getStyle();
s.accept(new AbstractStyleVisitor() {
@Override
public void visit(Mark mark) {
assertEquals("ttf://Webdings", mark.getExternalMark().getOnlineResource().getLinkage().toASCIIString());
}
});
}Example 3
| Project: nz.co.kakariki.NetworkUtilities-master File: SectorDisplayStyle.java View source code |
/**
* Create a Style to draw point features as circles with blue outlines
* and cyan fill
*/
protected Style createPointStyle(Color colour) {
Graphic gr = styleFactory.createDefaultGraphic();
Mark mark = styleFactory.getCircleMark();
mark.setStroke(styleFactory.createStroke(filterFactory.literal(colour), filterFactory.literal(5)));
mark.setFill(styleFactory.createFill(filterFactory.literal(colour)));
gr.graphicalSymbols().clear();
gr.graphicalSymbols().add(mark);
gr.setSize(filterFactory.literal(5));
/*
* Setting the geometryPropertyName arg to null signals that we want to
* draw the default geomettry of features
*/
PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
Style style = styleFactory.createStyle();
style.featureTypeStyles().add(fts);
return style;
}Example 4
| Project: spatial_statistics_for_geotools_udig-master File: GraduatedSymbolStyleBuilder.java View source code |
private void setDefaultSymbolizer(SimpleFeatureCollection inputFeatures) {
GeometryDescriptor geomDesc = inputFeatures.getSchema().getGeometryDescriptor();
String geometryPropertyName = geomDesc.getLocalName();
Class<?> geomBinding = geomDesc.getType().getBinding();
SimpleShapeType shapeType = FeatureTypes.getSimpleShapeType(geomBinding);
switch(shapeType) {
case POINT:
case POLYGON:
// default Point Symbolizer
Mark mark = sf.getCircleMark();
// createStroke(Expression color, Expression width, Expression opacity)
Stroke markStroke = sf.createStroke(ff.literal(Color.WHITE), ff.literal(outlineWidth), ff.literal(outlineOpacity));
mark.setStroke(markStroke);
mark.setFill(sf.createFill(ff.literal(Color.RED), ff.literal(fillOpacity)));
Graphic graphic = sf.createDefaultGraphic();
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(mark);
graphic.setSize(ff.literal(minSize));
this.templateSymbol = sf.createPointSymbolizer(graphic, null);
break;
case LINESTRING:
// Default Line Symbolizer
Stroke stroke = sf.createStroke(ff.literal(new Color(0, 112, 255)), ff.literal(lineWidth), ff.literal(outlineOpacity));
this.templateSymbol = sf.createLineSymbolizer(stroke, geometryPropertyName);
break;
}
}Example 5
| Project: geotools-tike-master File: JStreamSelectMap.java View source code |
private Style createStyle(MapLayer layer) {
Class jtsClass = layer.getFeatureSource().getSchema().getGeometryDescriptor().getType().getBinding();
if (jtsClass.equals(Point.class) || jtsClass.equals(MultiPoint.class)) {
Fill fill = STYLE_BUILDER.createFill(selectionStyleColor, 0.6f);
Stroke stroke = STYLE_BUILDER.createStroke(selectionStyleColor, 2);
stroke.setOpacity(STYLE_BUILDER.literalExpression(1f));
Mark mark = STYLE_BUILDER.createMark("circle", fill, stroke);
Graphic gra = STYLE_BUILDER.createGraphic();
gra.setOpacity(STYLE_BUILDER.literalExpression(1f));
gra.setMarks(new Mark[] { mark });
gra.setSize(STYLE_BUILDER.literalExpression(15));
PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(gra);
Style pointSelectionStyle = STYLE_BUILDER.createStyle();
pointSelectionStyle.addFeatureTypeStyle(STYLE_BUILDER.createFeatureTypeStyle(ps));
return pointSelectionStyle;
} else if (jtsClass.equals(LineString.class) || jtsClass.equals(MultiLineString.class)) {
Fill fill = STYLE_BUILDER.createFill(selectionStyleColor, 0.6f);
Stroke stroke = STYLE_BUILDER.createStroke(selectionStyleColor, 2);
stroke.setOpacity(STYLE_BUILDER.literalExpression(1f));
Mark mark = STYLE_BUILDER.createMark("circle", fill, stroke);
Graphic gra = STYLE_BUILDER.createGraphic();
gra.setOpacity(STYLE_BUILDER.literalExpression(1f));
gra.setMarks(new Mark[] { mark });
gra.setSize(STYLE_BUILDER.literalExpression(5));
PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(gra);
LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(stroke);
Rule r1 = STYLE_BUILDER.createRule(new Symbolizer[] { ps });
Rule r2 = STYLE_BUILDER.createRule(new Symbolizer[] { ls });
Style lineSelectionStyle = STYLE_BUILDER.createStyle();
lineSelectionStyle.addFeatureTypeStyle(STYLE_BUILDER.createFeatureTypeStyle(null, new Rule[] { r1, r2 }));
return lineSelectionStyle;
} else if (jtsClass.equals(Polygon.class) || jtsClass.equals(MultiPolygon.class)) {
Fill fill = STYLE_BUILDER.createFill(selectionStyleColor, 0.6f);
Stroke stroke = STYLE_BUILDER.createStroke(selectionStyleColor, 2);
stroke.setOpacity(STYLE_BUILDER.literalExpression(1f));
PolygonSymbolizer pls = STYLE_BUILDER.createPolygonSymbolizer(stroke, fill);
Mark mark = STYLE_BUILDER.createMark("circle", fill, stroke);
Graphic gra = STYLE_BUILDER.createGraphic();
gra.setOpacity(STYLE_BUILDER.literalExpression(1f));
gra.setMarks(new Mark[] { mark });
gra.setSize(STYLE_BUILDER.literalExpression(5));
PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(gra);
Rule r1 = STYLE_BUILDER.createRule(new Symbolizer[] { ps });
Rule r3 = STYLE_BUILDER.createRule(new Symbolizer[] { pls });
Style polySelectionStyle = STYLE_BUILDER.createStyle();
polySelectionStyle.addFeatureTypeStyle(STYLE_BUILDER.createFeatureTypeStyle(null, new Rule[] { r1, r3 }));
return polySelectionStyle;
}
Fill fill = STYLE_BUILDER.createFill(selectionStyleColor, 0.4f);
Stroke stroke = STYLE_BUILDER.createStroke(selectionStyleColor, 2);
stroke.setOpacity(STYLE_BUILDER.literalExpression(0.6f));
PolygonSymbolizer pls = STYLE_BUILDER.createPolygonSymbolizer(stroke, fill);
Mark mark = STYLE_BUILDER.createMark("circle", fill, stroke);
Graphic gra = STYLE_BUILDER.createGraphic();
gra.setOpacity(STYLE_BUILDER.literalExpression(0.6f));
gra.setMarks(new Mark[] { mark });
gra.setSize(STYLE_BUILDER.literalExpression(14));
PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(gra);
LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(stroke);
Rule r1 = STYLE_BUILDER.createRule(new Symbolizer[] { ps });
r1.setFilter(new GeometryClassFilter(Point.class, MultiPoint.class));
Rule r2 = STYLE_BUILDER.createRule(new Symbolizer[] { ls });
r2.setFilter(new GeometryClassFilter(LineString.class, MultiLineString.class));
Rule r3 = STYLE_BUILDER.createRule(new Symbolizer[] { pls });
r3.setFilter(new GeometryClassFilter(Polygon.class, MultiPolygon.class));
Style LineSelectionStyle = STYLE_BUILDER.createStyle();
LineSelectionStyle.addFeatureTypeStyle(STYLE_BUILDER.createFeatureTypeStyle(null, new Rule[] { r1, r2, r3 }));
return LineSelectionStyle;
}Example 6
| Project: jgrasstools-master File: Utilities.java View source code |
/**
* Creates a default {@link Rule} for a point.
*
* @return the default rule.
*/
public static Rule createDefaultPointRule() {
Graphic graphic = sf.createDefaultGraphic();
Mark circleMark = sf.getCircleMark();
circleMark.setFill(sf.createFill(ff.literal("#" + Integer.toHexString(Color.RED.getRGB() & 0xffffff))));
circleMark.setStroke(sf.createStroke(ff.literal("#" + Integer.toHexString(Color.BLACK.getRGB() & 0xffffff)), ff.literal(DEFAULT_WIDTH)));
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(circleMark);
graphic.setSize(ff.literal(DEFAULT_SIZE));
PointSymbolizer pointSymbolizer = sf.createPointSymbolizer();
Rule rule = sf.createRule();
rule.setName("New rule");
rule.symbolizers().add(pointSymbolizer);
pointSymbolizer.setGraphic(graphic);
return rule;
}Example 7
| Project: geotools-master File: YsldEncodeTest.java View source code |
@Test
public void testLabelShield() throws IOException {
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
sld.layers().add(layer);
Style style = sf.createStyle();
layer.userStyles().add(style);
FeatureTypeStyle featureStyle = sf.createFeatureTypeStyle();
style.featureTypeStyles().add(featureStyle);
Rule rule = sf.createRule();
featureStyle.rules().add(rule);
Stroke stroke = sf.stroke(ff.literal("#555555"), null, null, null, null, null, null);
rule.symbolizers().add(sf.lineSymbolizer("line", null, null, null, stroke, null));
Mark mark = sf.mark(ff.literal("circle"), sf.fill(null, ff.literal("#995555"), null), null);
List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
symbols.add(mark);
TextSymbolizer2 text = (TextSymbolizer2) sf.textSymbolizer(null, ff.property("geom"), null, null, ff.property("name"), null, null, null, null);
text.setGraphic(sf.graphic(symbols, null, null, null, null, null));
rule.symbolizers().add(text);
StringWriter out = new StringWriter();
Ysld.encode(sld, out);
YamlMap yaml = new YamlMap(new Yaml().load(out.toString()));
assertThat(yaml.lookupY("feature-styles/0/rules/0/symbolizers/1/text"), yHasEntry("label", equalTo("${name}")));
assertThat(yaml.lookupY("feature-styles/0/rules/0/symbolizers/1/text"), yHasEntry("graphic"));
assertThat(yaml.lookupY("feature-styles/0/rules/0/symbolizers/1/text/graphic/symbols/0/mark"), yHasEntry("shape", equalTo("circle")));
}Example 8
| Project: mapfish-print-master File: JsonStyleParserHelper.java View source code |
/**
* Add a point symbolizer definition to the rule.
*
* @param styleJson The old style.
*/
@Nullable
public PointSymbolizer createPointSymbolizer(final PJsonObject styleJson) {
if (this.allowNullSymbolizer && !(styleJson.has(JSON_EXTERNAL_GRAPHIC) || styleJson.has(JSON_GRAPHIC_NAME) || styleJson.has(JSON_POINT_RADIUS))) {
return null;
}
Graphic graphic = this.styleBuilder.createGraphic();
graphic.graphicalSymbols().clear();
if (styleJson.has(JSON_EXTERNAL_GRAPHIC)) {
String externalGraphicUrl = validateURL(styleJson.getString(JSON_EXTERNAL_GRAPHIC));
try {
final URI uri = URI.create(externalGraphicUrl);
if (uri.getScheme().startsWith("http")) {
final ClientHttpRequest request = this.requestFactory.createRequest(uri, HttpMethod.GET);
externalGraphicUrl = request.getURI().toString();
}
} catch (IOException ignored) {
}
final String graphicFormat = getGraphicFormat(externalGraphicUrl, styleJson);
final ExternalGraphic externalGraphic = this.styleBuilder.createExternalGraphic(externalGraphicUrl, graphicFormat);
graphic.graphicalSymbols().add(externalGraphic);
}
if (styleJson.has(JSON_GRAPHIC_NAME)) {
Expression graphicName = parseProperty(styleJson.getString(JSON_GRAPHIC_NAME), new Function<String, Object>() {
public Object apply(final String input) {
return input;
}
});
Fill fill = createFill(styleJson);
Stroke stroke = createStroke(styleJson, false);
final Mark mark = this.styleBuilder.createMark(graphicName, fill, stroke);
graphic.graphicalSymbols().add(mark);
}
if (graphic.graphicalSymbols().isEmpty()) {
Fill fill = createFill(styleJson);
Stroke stroke = createStroke(styleJson, false);
final Mark mark = this.styleBuilder.createMark(DEFAULT_POINT_MARK, fill, stroke);
graphic.graphicalSymbols().add(mark);
}
graphic.setOpacity(parseExpression(null, styleJson, JSON_GRAPHIC_OPACITY, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String opacityString) {
return Double.parseDouble(opacityString);
}
}));
if (!Strings.isNullOrEmpty(styleJson.optString(JSON_POINT_RADIUS))) {
Expression size = parseExpression(null, styleJson, JSON_POINT_RADIUS, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(input) * 2;
}
});
graphic.setSize(size);
} else if (!Strings.isNullOrEmpty(styleJson.optString(JSON_GRAPHIC_WIDTH))) {
Expression size = parseExpression(null, styleJson, JSON_GRAPHIC_WIDTH, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(input);
}
});
graphic.setSize(size);
}
if (!Strings.isNullOrEmpty(styleJson.optString(JSON_GRAPHIC_Y_OFFSET)) && !Strings.isNullOrEmpty(styleJson.optString(JSON_GRAPHIC_X_OFFSET))) {
Expression dy = parseExpression(null, styleJson, JSON_GRAPHIC_Y_OFFSET, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(input);
}
});
Expression dx = parseExpression(null, styleJson, JSON_GRAPHIC_X_OFFSET, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(input);
}
});
Displacement offset = this.styleBuilder.createDisplacement(dx, dy);
graphic.setDisplacement(offset);
}
if (!Strings.isNullOrEmpty(styleJson.optString(JSON_ROTATION))) {
final Expression rotation = parseExpression(null, styleJson, JSON_ROTATION, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String rotation) {
return Double.parseDouble(rotation);
}
});
graphic.setRotation(rotation);
}
return this.styleBuilder.createPointSymbolizer(graphic);
}Example 9
| Project: suite-master File: StyleAdaptor.java View source code |
@Override
public Object visit(Graphic gr, Object data) {
if (gr.getAnchorPoint() != null) {
data = gr.getAnchorPoint().accept(this, data);
}
if (gr.getDisplacement() != null) {
data = gr.getDisplacement().accept(this, data);
}
for (GraphicalSymbol eg : gr.graphicalSymbols()) {
if (eg instanceof ExternalGraphic) {
data = ((ExternalGraphic) eg).accept(this, data);
} else if (eg instanceof Mark) {
data = ((Mark) eg).accept(this, data);
}
}
return data;
}Example 10
| Project: hale-master File: StyledInstanceMarker.java View source code |
/**
* Creates a certain Point Symbolizer if the waypoint is selected
*
* @param symbolizer a symbolizer which is used to create the selection
* symbolizer
* @return returns the selection symbolizer
*/
private PointSymbolizer getSelectionSymbolizer(PointSymbolizer symbolizer) {
// XXX only works with marks and external graphics right now
Mark mark = SLD.mark(symbolizer);
if (mark != null) {
Mark mutiMark = styleBuilder.createMark(mark.getWellKnownName(), styleBuilder.createFill(StylePreferences.getSelectionColor(), StyleHelper.DEFAULT_FILL_OPACITY), styleBuilder.createStroke(StylePreferences.getSelectionColor(), StylePreferences.getSelectionWidth()));
// create new symbolizer
return styleBuilder.createPointSymbolizer(styleBuilder.createGraphic(null, mutiMark, null));
} else {
return symbolizer;
}
}Example 11
| Project: josm-plugins-master File: OsmInspectorLayer.java View source code |
private Rule createRule(Color outlineColor, Color fillColor, boolean bSelected) {
Symbolizer symbolizer = null;
Fill fill = null;
Stroke stroke = sf.createStroke(ff.literal(outlineColor), ff.literal(LINE_WIDTH));
switch(geometryType) {
case POLYGON:
fill = sf.createFill(ff.literal(fillColor), ff.literal(OPACITY));
symbolizer = sf.createPolygonSymbolizer(stroke, fill, geometryAttributeName);
break;
case LINE:
symbolizer = sf.createLineSymbolizer(stroke, geometryAttributeName);
break;
case POINT:
fill = sf.createFill(ff.literal(fillColor), ff.literal(OPACITY));
Mark mark = sf.getTriangleMark();
mark.setFill(fill);
mark.setStroke(stroke);
Graphic graphic = sf.createDefaultGraphic();
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(mark);
graphic.setSize(ff.literal(bSelected ? SELECTED_POINT_SIZE : POINT_SIZE));
symbolizer = sf.createPointSymbolizer(graphic, geometryAttributeName);
}
Rule rule = sf.createRule();
rule.symbolizers().add(symbolizer);
return rule;
}Example 12
| Project: atlasframework-master File: ASUtil.java View source code |
public static void replaceGraphicSize(final Graphic graphic, final Float factor) {
if (graphic == null)
return;
final Expression gSize = graphic.getSize();
if (gSize != null && gSize != Expression.NIL) {
final Double newSize = Double.valueOf(gSize.toString()) * factor;
// System.out.println("Changed a Graphics's size from to "
// + Float.valueOf(graphic.getSize().toString()) + " to "
// + newSize);
graphic.setSize(ASUtil.ff2.literal(newSize));
}
// else if (graphic.getMarks() != null) {
// // TODO Stefan Tzeggai 12.9.11 GT8 Migration
// for (final Mark m : graphic.getMarks()) {
// final Expression mSize = m.getSize();
// if (mSize != null && mSize != Expression.NIL) {
// final Float newSize = Float.valueOf(mSize.toString())
// * factor;
// // System.out.println("Changed a Mark's size from to "
// // + Double.valueOf(m.getSize().toString()) + " to "
// // + newSize);
// m.setSize(ASUtil.ff2.literal(newSize));
// }
// }
// }
}Example 13
| Project: geoserver-old-master File: KMLMapTransformer.java View source code |
/**
* Encodes a KML IconStyle from a point style and symbolizer.
*/
protected void encodePointStyle(SimpleFeature feature, Style2D style, PointSymbolizer symbolizer) {
start("IconStyle");
if (style instanceof MarkStyle2D) {
Mark mark = SLD.mark(symbolizer);
if (mark != null) {
Double opacity = mark.getFill().getOpacity().evaluate(feature, Double.class);
if (opacity == null || Double.isNaN(opacity)) {
// default to full opacity
opacity = 1.0;
}
if (mark.getFill() != null) {
final Color color = (Color) mark.getFill().getColor().evaluate(feature, Color.class);
encodeColor(color, opacity);
}
}
}
element("colorMode", "normal");
// placemark icon
String iconHref = null;
// if the point symbolizer uses an external graphic use it
if ((symbolizer.getGraphic() != null) && (symbolizer.getGraphic().getExternalGraphics() != null) && (symbolizer.getGraphic().getExternalGraphics().length > 0)) {
ExternalGraphic graphic = symbolizer.getGraphic().getExternalGraphics()[0];
try {
if ("file".equals(graphic.getLocation().getProtocol())) {
// it is a local file, reference locally from "styles"
// directory
File file = DataUtilities.urlToFile(graphic.getLocation());
File styles = null;
File graphicFile = null;
if (file.isAbsolute()) {
GeoServerDataDirectory dataDir = (GeoServerDataDirectory) GeoServerExtensions.bean("dataDirectory");
// we grab the canonical path to make sure we can compare them, no
// relative parts in them and so on
styles = dataDir.findOrCreateStyleDir().getCanonicalFile();
graphicFile = file.getCanonicalFile();
file = graphicFile;
if (file.getAbsolutePath().startsWith(styles.getAbsolutePath())) {
// ok, part of the styles directory, extract only the relative path
file = new File(file.getAbsolutePath().substring(styles.getAbsolutePath().length() + 1));
} else {
// we wont' transform this, other dirs are not published
file = null;
}
}
if (file != null && styles != null) {
iconHref = ResponseUtils.buildURL(mapContent.getRequest().getBaseUrl(), "styles/" + styles.toURI().relativize(graphicFile.toURI()), null, URLType.RESOURCE);
}
} else if ("http".equals(graphic.getLocation().getProtocol())) {
iconHref = graphic.getLocation().toString();
} else {
// TODO: should we check for http:// and use it
// directly?
// other protocols?
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error processing external graphic:" + graphic, e);
}
}
iconHref = evaluateDynamicSymbolizer(iconHref, feature);
if (iconHref == null) {
iconHref = "http://maps.google.com/mapfiles/kml/pal4/icon25.png";
}
start("Icon");
element("href", iconHref);
end("Icon");
end("IconStyle");
}Example 14
| Project: geoserver-2.0.x-master File: KMLWriter.java View source code |
/**
* Adds the <style> tag to the KML document.
*
* @param style
* @param id
* @throws IOException
*/
private void writeStyle(final Style2D style, final String id, Symbolizer sym) throws IOException {
if (style instanceof PolygonStyle2D && sym instanceof PolygonSymbolizer) {
if ((((PolygonStyle2D) style).getFill() == null) && (((PolygonStyle2D) style).getStroke() == null)) {
LOGGER.info("Empty PolygonSymbolizer, using default fill and stroke.");
}
final StringBuffer styleString = new StringBuffer();
PolygonSymbolizer polySym = (PolygonSymbolizer) sym;
// ** LABEL **
styleString.append("<IconStyle>");
if (!mapContext.getRequest().getKMattr()) {
// if they don't want
// attributes
// fully
styleString.append("<color>#00ffffff</color>");
// transparent
}
styleString.append("<Icon><href>root://icons/palette-3.png</href><x>224</x><w>32</w><h>32</h></Icon>");
styleString.append("</IconStyle>");
// ** FILL **
styleString.append("<PolyStyle><color>");
if (// if they specified a fill
polySym.getFill() != null) {
// default to full opacity
int opacity = 255;
if (polySym.getFill().getOpacity() != null) {
float op = getOpacity(polySym.getFill().getOpacity());
opacity = (new Float(255 * op)).intValue();
}
Paint p = ((PolygonStyle2D) style).getFill();
if (p instanceof Color) {
styleString.append("#").append(intToHex(opacity)).append(// transparancy needs to
colorToHex((Color) p));
// come from the opacity
// value.
} else {
// should not occure in
styleString.append("#ffaaaaaa");
// normal parsing
}
} else {
// no fill specified, make transparent
styleString.append("#00aaaaaa");
}
// if there is an outline, specify that we have one, then style it
styleString.append("</color>");
if (polySym.getStroke() != null) {
styleString.append("<outline>1</outline>");
} else {
styleString.append("<outline>0</outline>");
}
styleString.append("</PolyStyle>");
// ** OUTLINE **
if (// if there is an outline
polySym.getStroke() != null) {
styleString.append("<LineStyle><color>");
// default to full opacity
int opacity = 255;
if (polySym.getStroke().getOpacity() != null) {
float op = getOpacity(polySym.getStroke().getOpacity());
opacity = (new Float(255 * op)).intValue();
}
Paint p = ((PolygonStyle2D) style).getContour();
if (p instanceof Color) {
styleString.append("#").append(intToHex(opacity)).append(// transparancy needs to
colorToHex((Color) p));
// come from the opacity
// value.
} else {
// should not occure in
styleString.append("#ffaaaaaa");
// normal parsing
}
styleString.append("</color>");
// stroke width
if (polySym.getStroke().getWidth() != null) {
int width = getWidth(polySym.getStroke().getWidth());
styleString.append("<width>").append(width).append("</width>");
}
styleString.append("</LineStyle>");
}
write(styleString.toString());
} else if (style instanceof LineStyle2D && sym instanceof LineSymbolizer) {
if (((LineStyle2D) style).getStroke() == null) {
LOGGER.info("Empty LineSymbolizer, using default stroke.");
}
LineSymbolizer lineSym = (LineSymbolizer) sym;
// ** LABEL **
final StringBuffer styleString = new StringBuffer();
styleString.append("<IconStyle>");
if (!mapContext.getRequest().getKMattr()) {
// if they don't want
// attributes
// fully
styleString.append("<color>#00ffffff</color>");
// transparent
}
styleString.append("</IconStyle>");
// ** LINE **
styleString.append("<LineStyle><color>");
if (lineSym.getStroke() != null) {
int opacity = 255;
if (lineSym.getStroke().getOpacity() != null) {
float op = getOpacity(lineSym.getStroke().getOpacity());
opacity = (new Float(255 * op)).intValue();
}
Paint p = ((LineStyle2D) style).getContour();
if (p instanceof Color) {
styleString.append("#").append(intToHex(opacity)).append(// transparancy needs to
colorToHex((Color) p));
// come from the opacity
// value.
} else {
// should not occure in
styleString.append("#ffaaaaaa");
// normal parsing
}
styleString.append("</color>");
// stroke width
if (lineSym.getStroke().getWidth() != null) {
int width = getWidth(lineSym.getStroke().getWidth());
styleString.append("<width>").append(width).append("</width>");
}
} else // no style defined, so use default
{
styleString.append("#ffaaaaaa");
styleString.append("</color><width>1</width>");
}
styleString.append("</LineStyle>");
write(styleString.toString());
} else if (style instanceof TextStyle2D && sym instanceof TextSymbolizer) {
final StringBuffer styleString = new StringBuffer();
TextSymbolizer textSym = (TextSymbolizer) sym;
styleString.append("<LabelStyle><color>");
if (textSym.getFill() != null) {
int opacity = 255;
if (textSym.getFill().getOpacity() != null) {
float op = getOpacity(textSym.getFill().getOpacity());
opacity = (new Float(255 * op)).intValue();
}
Paint p = ((TextStyle2D) style).getFill();
if (p instanceof Color) {
styleString.append("#").append(intToHex(opacity)).append(colorToHex((Color) p));
// transparancy needs to come from the opacity value.
} else {
// should not occure in
styleString.append("#ffaaaaaa");
// normal parsing
}
styleString.append("</color></LabelStyle>");
} else {
styleString.append("#ffaaaaaa");
styleString.append("</color></LabelStyle>");
}
write(styleString.toString());
} else if (style instanceof MarkStyle2D && sym instanceof PointSymbolizer) {
// we can sorta style points. Just with color however.
final StringBuffer styleString = new StringBuffer();
PointSymbolizer pointSym = (PointSymbolizer) sym;
styleString.append("<IconStyle><color>");
if ((pointSym.getGraphic() != null) && (pointSym.getGraphic().getMarks() != null)) {
Mark[] marks = pointSym.getGraphic().getMarks();
if ((marks.length > 0) && (marks[0] != null)) {
Mark mark = marks[0];
int opacity = 255;
if (mark.getFill().getOpacity() != null) {
float op = getOpacity(mark.getFill().getOpacity());
opacity = (new Float(255 * op)).intValue();
}
Paint p = ((MarkStyle2D) style).getFill();
if (p instanceof Color) {
styleString.append("#").append(intToHex(opacity)).append(colorToHex((Color) p));
// transparancy needs to comefrom the opacity value.
} else {
// should not occure
styleString.append("#ffaaaaaa");
// in normal parsing
}
} else {
styleString.append("#ffaaaaaa");
}
} else {
styleString.append("#ffaaaaaa");
}
styleString.append("</color>");
styleString.append("<colorMode>normal</colorMode>");
styleString.append("<Icon><href>root://icons/palette-4.png</href>");
styleString.append("<x>32</x><y>128</y><w>32</w><h>32</h></Icon>");
styleString.append("</IconStyle>");
write(styleString.toString());
}
}