Search in sources :

Example 16 with Stroke

use of org.geotools.styling.Stroke in project polymap4-core by Polymap4.

the class DefaultStyles method createPolygonStyle.

/**
 * Create a Style to draw polygon features with a thin blue outline and
 * a cyan fill
 */
public static Style createPolygonStyle(Style style) {
    // create a partially opaque outline stroke
    Stroke stroke = sf.createStroke(ff.literal(Color.DARK_GRAY), ff.literal(0.5), ff.literal(0.5));
    // create a partial opaque fill
    Fill fill = sf.createFill(ff.literal(Color.CYAN), ff.literal(0.5));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to
         * draw the default geometry of features
         */
    PolygonSymbolizer sym = sf.createPolygonSymbolizer(stroke, fill, null);
    Rule rule = sf.createRule();
    rule.setName("Rule for PolygonSymbolizer");
    rule.symbolizers().add(sym);
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Rule(org.geotools.styling.Rule)

Example 17 with Stroke

use of org.geotools.styling.Stroke in project polymap4-core by Polymap4.

the class DefaultStyles method createLineStyle.

/**
 * Create a Style to draw line features as thin blue lines
 */
public static Style createLineStyle(Style style) {
    Stroke stroke = sf.createStroke(ff.literal(Color.DARK_GRAY), ff.literal(0.5));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to
         * draw the default geometry of features
         */
    LineSymbolizer sym = sf.createLineSymbolizer(stroke, null);
    Rule rule = sf.createRule();
    rule.symbolizers().add(sym);
    rule.setName("Rule for LineSymbolizer");
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : Stroke(org.geotools.styling.Stroke) LineSymbolizer(org.geotools.styling.LineSymbolizer) Rule(org.geotools.styling.Rule)

Example 18 with Stroke

use of org.geotools.styling.Stroke in project hale by halestudio.

the class StyledInstanceMarker method strokeStyle.

/**
 * retrieves the stroke for the map marker
 *
 * @param rule a certain rule to apply, maybe null
 * @param context the InstanceWayPoint, wich gets marked
 */
private synchronized void strokeStyle(Rule rule, InstanceWaypoint context) {
    // retrieve stroke
    Stroke stroke = null;
    for (int i = 0; rule != null && stroke == null && i < rule.getSymbolizers().length; i++) {
        if (rule.getSymbolizers()[i] instanceof LineSymbolizer) {
            stroke = SLD.stroke((LineSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PolygonSymbolizer) {
            stroke = SLD.stroke((PolygonSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PointSymbolizer) {
            stroke = SLD.stroke((PointSymbolizer) rule.getSymbolizers()[i]);
        }
    }
    // if we have a stroke now
    if (stroke != null) {
        // XXX is there any Geotools stroke to AWT stroke lib/code
        // somewhere?!
        // XXX have a look at the renderer code (StreamingRenderer)
        // stroke color
        Color sldColor = SLD.color(stroke);
        double opacity = SLD.opacity(stroke);
        if (Double.isNaN(opacity)) {
            // fall back to default opacity
            opacity = StyleHelper.DEFAULT_FILL_OPACITY;
        }
        if (sldColor != null) {
            styleStrokeColor = new Color(sldColor.getRed(), sldColor.getGreen(), sldColor.getBlue(), (int) (opacity * 255));
        } else {
            styleStrokeColor = super.getBorderColor(context);
        }
        // stroke width
        int strokeWidth = SLD.width(stroke);
        if (strokeWidth == SLD.NOTFOUND) {
            // fall back to default width
            strokeWidth = StylePreferences.getDefaultWidth();
        }
        styleStroke = new BasicStroke(strokeWidth);
    } else {
        styleStroke = null;
        styleStrokeColor = null;
    }
}
Also used : BasicStroke(java.awt.BasicStroke) PointSymbolizer(org.geotools.styling.PointSymbolizer) BasicStroke(java.awt.BasicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 19 with Stroke

use of org.geotools.styling.Stroke in project sldeditor by robward-scisys.

the class LineFillSymbol method convertToFill.

/**
 * Convert to fill.
 *
 * @param layerName the layer name
 * @param element the element
 * @param transparency the transparency
 * @return the list
 */
/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
     */
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
    if (layerName == null) {
        return null;
    }
    if (element == null) {
        return null;
    }
    List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
    JsonObject obj = element.getAsJsonObject();
    Expression size = ff.literal(getDouble(obj, LineFillSymbolKeys.SEPARATION));
    Expression opacity = null;
    double lineAngle = normaliseAngle(getDouble(obj, CommonSymbolKeys.ANGLE));
    Expression rotation = null;
    AnchorPoint anchorPoint = null;
    Displacement displacement = null;
    Expression fillColour = getColour(obj.get(LineFillSymbolKeys.FILL_COLOUR));
    Expression fillColourOpacity = null;
    Expression join = null;
    Expression cap = null;
    float[] dashes = null;
    Expression offset = null;
    Expression width = ff.literal(1.0);
    Stroke outlineStroke = null;
    List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(LineFillSymbolKeys.OUTLINE));
    // TODO
    if ((strokeList != null) && (strokeList.size() == 1)) {
        outlineStroke = strokeList.get(0);
        width = outlineStroke.getWidth();
    }
    Expression wellKnownName = null;
    if (isDoubleEqual(lineAngle, 0.0) || isDoubleEqual(lineAngle, 180.0)) {
        wellKnownName = ff.literal("shape://horline");
    } else if (isDoubleEqual(lineAngle, 90.0) || isDoubleEqual(lineAngle, 270.0)) {
        wellKnownName = ff.literal("shape://vertline");
    } else if (isDoubleEqual(lineAngle, 45.0) || isDoubleEqual(lineAngle, 225.0)) {
        wellKnownName = ff.literal("shape://slash");
    } else if (isDoubleEqual(lineAngle, 135.0) || isDoubleEqual(lineAngle, 315.0)) {
        wellKnownName = ff.literal("shape://backslash");
    } else {
        wellKnownName = ff.literal("shape://vertline");
        rotation = ff.literal(lineAngle);
    }
    Fill fill = null;
    Stroke markStroke = styleFactory.stroke(fillColour, fillColourOpacity, width, join, cap, dashes, offset);
    Mark mark = styleFactory.createMark(wellKnownName, markStroke, fill, size, rotation);
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    symbolList.add(mark);
    GraphicFill graphicFill = styleFactory.graphicFill(symbolList, opacity, size, rotation, anchorPoint, displacement);
    Fill completeFill = styleFactory.fill(graphicFill, null, null);
    PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
    polygonSymbolizer.setFill(completeFill);
    polygonSymbolizer.setStroke(outlineStroke);
    symbolizerList.add(polygonSymbolizer);
    return symbolizerList;
}
Also used : Stroke(org.geotools.styling.Stroke) GraphicFill(org.opengis.style.GraphicFill) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) GraphicFill(org.opengis.style.GraphicFill)

Example 20 with Stroke

use of org.geotools.styling.Stroke in project sldeditor by robward-scisys.

the class MultiLayerLineSymbol method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriLineSymbolInterface#convert(com.google.gson.JsonElement)
     */
@Override
public List<Stroke> convert(JsonElement element) {
    if (element == null)
        return null;
    List<Stroke> strokeList = null;
    JsonArray layerList = element.getAsJsonArray();
    if (layerList.size() > 0) {
        strokeList = new ArrayList<Stroke>();
        for (int index = 0; index < layerList.size(); index++) {
            JsonObject obj = layerList.get(index).getAsJsonObject();
            List<Stroke> strokeSymbolList = SymbolManager.getInstance().getStrokeList(obj.get(MultiLayerLineSymbolKeys.LINE));
            if (strokeSymbolList != null) {
                strokeList.addAll(strokeSymbolList);
            }
        }
    }
    return strokeList;
}
Also used : JsonArray(com.google.gson.JsonArray) Stroke(org.geotools.styling.Stroke) JsonObject(com.google.gson.JsonObject)

Aggregations

Stroke (org.geotools.styling.Stroke)36 Fill (org.geotools.styling.Fill)18 Expression (org.opengis.filter.expression.Expression)16 JsonObject (com.google.gson.JsonObject)13 GraphicalSymbol (org.opengis.style.GraphicalSymbol)13 LineSymbolizer (org.geotools.styling.LineSymbolizer)12 ArrayList (java.util.ArrayList)11 Graphic (org.geotools.styling.Graphic)10 Mark (org.geotools.styling.Mark)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)10 GraphicFill (org.opengis.style.GraphicFill)8 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)7 JsonElement (com.google.gson.JsonElement)6 Symbolizer (org.geotools.styling.Symbolizer)6 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)5 Displacement (org.geotools.styling.Displacement)5 ExternalGraphic (org.geotools.styling.ExternalGraphic)5 GraphicStroke (org.opengis.style.GraphicStroke)5 JsonArray (com.google.gson.JsonArray)4 AnchorPoint (org.geotools.styling.AnchorPoint)4