Search in sources :

Example 36 with PolygonSymbolizer

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

the class StyleHelper method createPolygonStyle.

/**
 * Create a default polygon style.
 *
 * @param color the polygon color
 * @param width the line width
 * @return a Style for Polygon objects
 */
private static FeatureTypeStyle createPolygonStyle(Color color, double width) {
    PolygonSymbolizer symbolizer = createPolygonSymbolizer(color, width);
    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);
    return fts;
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 37 with PolygonSymbolizer

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

the class StyleHelper method createPolygonSymbolizer.

/**
 * Create a default polygon symbolizer.
 *
 * @param color the color
 * @param width the line width
 * @return the polygon symbolizer
 */
public static PolygonSymbolizer createPolygonSymbolizer(Color color, double width) {
    PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
    SLD.setPolyColour(symbolizer, color);
    symbolizer.getStroke().setWidth(filterFactory.literal(width));
    Fill fill = styleFactory.createFill(filterFactory.literal(color), filterFactory.literal(DEFAULT_FILL_OPACITY));
    symbolizer.setFill(fill);
    return symbolizer;
}
Also used : Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Example 38 with PolygonSymbolizer

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

the class StyleServiceImpl method getSelectionSymbolizers.

/**
 * Get the symbolizers representing the given symbolizer for a selection
 *
 * @param symbolizer the symbolizer
 *
 * @return the selection symbolizers
 */
private List<Symbolizer> getSelectionSymbolizers(Symbolizer symbolizer) {
    List<Symbolizer> result = new ArrayList<Symbolizer>();
    Color color = StylePreferences.getSelectionColor();
    int width = StylePreferences.getSelectionWidth();
    if (symbolizer instanceof PolygonSymbolizer) {
        result.add(StyleHelper.createPolygonSymbolizer(color, width));
    } else if (symbolizer instanceof LineSymbolizer) {
        result.add(StyleHelper.createLineSymbolizer(color, width));
    } else if (symbolizer instanceof PointSymbolizer) {
        result.add(StyleHelper.mutatePointSymbolizer((PointSymbolizer) symbolizer, color, width));
    // result.add(createPointSymbolizer(color, width));
    } else {
    // do not fall-back to original symbolizer cause we are painting
    // over it
    // result.add(symbolizer);
    }
    return result;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Color(java.awt.Color) LineSymbolizer(org.geotools.styling.LineSymbolizer) ArrayList(java.util.ArrayList) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 39 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer 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 40 with PolygonSymbolizer

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

the class SelectedSymbolTest method testReplacment.

/**
 * Test method for
 * {@link com.sldeditor.common.data.SelectedSymbol#removeRule(org.geotools.styling.Rule)}.
 */
@Test
public void testReplacment() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyle(style);
    instance.setStyle(style);
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    instance.addNewRule(rule);
    instance.setRule(rule);
    instance.addSymbolizerToRule(polygonSymbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    instance.setSymbolizer(polygonSymbolizer);
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    DummySLDTreeUpdated dummyTreeUpdated = new DummySLDTreeUpdated();
    instance.setTreeUpdateListener(dummyTreeUpdated);
    instance.replaceSymbolizer(lineSymbolizer);
    assertEquals(lineSymbolizer, instance.getSymbolizer());
    assertEquals(dummyTreeUpdated.objectOld, polygonSymbolizer);
    assertEquals(dummyTreeUpdated.objectNew, lineSymbolizer);
    Rule newRule = DefaultSymbols.createNewRule();
    newRule.setTitle("Replacement rule");
    instance.replaceRule(newRule);
    assertEquals(newRule, instance.getRule());
    assertNull(instance.getSymbolizer());
    FeatureTypeStyle newFts = DefaultSymbols.createNewFeatureTypeStyle();
    newFts.setName("Replacement fts");
    instance.replaceFeatureTypeStyle(newFts);
    assertEquals(newFts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    Style newStyle = DefaultSymbols.createNewStyle();
    newStyle.setName("Replacement style");
    instance.replaceStyle(newStyle);
    assertEquals(newStyle, instance.getStyle());
    assertNull(instance.getRule());
    NamedLayer newNamedLayer = DefaultSymbols.createNewNamedLayer();
    newNamedLayer.setName("Replacement named layer");
    instance.replaceStyledLayer(newNamedLayer);
    assertEquals(newNamedLayer, instance.getStyledLayer());
    assertNull(instance.getStyle());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Aggregations

PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)65 Test (org.junit.Test)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)25 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)19 Rule (org.geotools.styling.Rule)18 Style (org.geotools.styling.Style)18 Symbolizer (org.geotools.styling.Symbolizer)15 Fill (org.geotools.styling.Fill)14 NamedLayer (org.geotools.styling.NamedLayer)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 Stroke (org.geotools.styling.Stroke)10 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)9 TextSymbolizer (org.geotools.styling.TextSymbolizer)9 SLDTreeLeafPolygon (com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon)8 Graphic (org.geotools.styling.Graphic)8 ArrayList (java.util.ArrayList)7 Expression (org.opengis.filter.expression.Expression)7 JsonObject (com.google.gson.JsonObject)5 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5