Search in sources :

Example 6 with Mark

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

the class FieldConfigMarker method getFill.

/**
 * Gets the fill.
 *
 * @param graphicFill the graphic fill
 * @param fieldConfigManager the field config manager
 * @return the fill
 */
@Override
public Fill getFill(GraphicFill graphicFill, GraphicPanelFieldManager fieldConfigManager) {
    if (fieldConfigManager == null) {
        return null;
    }
    Expression fillColour = null;
    FieldConfigBase field = fieldConfigManager.get(fillFieldConfig.getColour());
    if (field != null) {
        if ((field instanceof FieldConfigColour) && field.isEnabled()) {
            fillColour = ((FieldConfigColour) field).getColourExpression();
        }
    }
    Expression fillColourOpacity = null;
    field = fieldConfigManager.get(fillFieldConfig.getOpacity());
    if (field != null) {
        fillColourOpacity = field.getExpression();
    }
    GraphicFill _graphicFill = null;
    Expression _fillColour = fillColour;
    Expression _fillColourOpacity = fillColourOpacity;
    if (graphicFill != null) {
        List<GraphicalSymbol> symbolList = graphicFill.graphicalSymbols();
        if ((symbolList != null) && (!symbolList.isEmpty())) {
            GraphicalSymbol symbol = symbolList.get(0);
            Mark mark = (Mark) symbol;
            if (mark.getWellKnownName() != null) {
                _graphicFill = graphicFill;
                _fillColour = null;
                _fillColourOpacity = null;
            }
        }
    }
    Fill fill = getStyleFactory().fill(_graphicFill, _fillColour, _fillColourOpacity);
    return fill;
}
Also used : Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) GraphicFill(org.opengis.style.GraphicFill) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour)

Example 7 with Mark

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

the class StyleModelTest method testSimplePoint.

@Test
public void testSimplePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    PointStyle style = fs.members().createElement(PointStyle.defaults);
    assertTrue(style.visibleIf.get() instanceof ConstantFilter);
    style.diameter.createValue(ConstantNumber.defaults(100.0));
    style.rotation.createValue(ConstantNumber.defaults(45.0));
    style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
    style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
    style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
    style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
    style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    assertEquals(1, result.featureTypeStyles().size());
    FeatureTypeStyle fts = result.featureTypeStyles().get(0);
    assertEquals(1, fts.rules().size());
    Rule rule = fts.rules().get(0);
    assertEquals(0, rule.getMinScaleDenominator(), 0);
    assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
    assertEquals(1, rule.symbolizers().size());
    assertNull(rule.getFilter());
    PointSymbolizer sym = (PointSymbolizer) rule.symbolizers().get(0);
    assertEqualsLiteral(100.0, sym.getGraphic().getSize());
    assertEqualsLiteral(45.0, sym.getGraphic().getRotation());
    assertEquals(1, sym.getGraphic().graphicalSymbols().size());
    GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
    Mark mark = (Mark) symbol;
    assertEqualsLiteral(0.0, mark.getFill().getOpacity());
    assertEqualsLiteral(0.5, mark.getStroke().getOpacity());
    assertEqualsLiteral(5.0, mark.getStroke().getWidth());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Style(org.geotools.styling.Style) ConstantStrokeDashStyle(org.polymap.core.style.model.feature.ConstantStrokeDashStyle) ConstantStrokeJoinStyle(org.polymap.core.style.model.feature.ConstantStrokeJoinStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) ConstantStrokeCapStyle(org.polymap.core.style.model.feature.ConstantStrokeCapStyle) StrokeDashStyle(org.polymap.core.style.model.feature.StrokeDashStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) Mark(org.geotools.styling.Mark) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 8 with Mark

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

the class StyleHelper method mutatePointSymbolizer.

/**
 * Create a new point symbolizer based on the given one.
 *
 * @param symbolizer the point symbolizer
 * @param color the new color
 * @param width the new line width
 * @return the mutated symbolizer
 */
public static Symbolizer mutatePointSymbolizer(PointSymbolizer symbolizer, Color color, int width) {
    // mutate mark
    Mark mark = SLD.mark(symbolizer);
    Mark mutiMark = styleBuilder.createMark(mark.getWellKnownName(), styleBuilder.createFill(color, DEFAULT_FILL_OPACITY), styleBuilder.createStroke(color, width));
    // create new symbolizer
    return styleBuilder.createPointSymbolizer(styleBuilder.createGraphic(null, mutiMark, null));
}
Also used : Mark(org.geotools.styling.Mark)

Example 9 with Mark

use of org.geotools.styling.Mark 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 10 with Mark

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

the class StrokeDetails method populateStroke.

/**
 * Populate stroke.
 *
 * @param symbolizerType the symbolizer type
 * @param stroke the stroke
 */
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
    Expression expColour = null;
    Expression expStrokeColour = null;
    Expression expOpacity = null;
    Expression expStrokeWidth = null;
    Expression expStrokeOffset = null;
    Expression expStrokeLineCap = null;
    Expression expStrokeLineJoin = null;
    Expression expStrokeDashArray = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Expression expSymbolSize = null;
    Expression expSymbolRotation = null;
    if (stroke == null) {
        expColour = getFilterFactory().literal("#000000");
        expOpacity = getFilterFactory().literal(1.0);
        symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
        expStrokeWidth = getFilterFactory().literal(1.0);
        expStrokeOffset = getFilterFactory().literal(0.0);
        expStrokeLineCap = getFilterFactory().literal("round");
        expStrokeLineJoin = getFilterFactory().literal("round");
        expStrokeDashArray = getFilterFactory().literal("");
    } else {
        Graphic graphicFill = stroke.getGraphicFill();
        Graphic graphicStroke = stroke.getGraphicStroke();
        if ((graphicFill == null) && (graphicStroke == null)) {
            expOpacity = stroke.getOpacity();
            symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
        }
        expOpacity = stroke.getOpacity();
        expStrokeWidth = stroke.getWidth();
        expStrokeOffset = stroke.getDashOffset();
        expStrokeLineCap = stroke.getLineCap();
        expStrokeLineJoin = stroke.getLineJoin();
        expColour = stroke.getColor();
        List<Float> dashesArray = getStrokeDashArray(stroke);
        expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
        if (graphicStroke != null) {
            // Anchor points
            AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Displacement
            Displacement displacement = graphicStroke.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphicStroke.getGap();
            expInitialGap = graphicStroke.getInitialGap();
            expSymbolSize = graphicStroke.getSize();
            expSymbolRotation = graphicStroke.getRotation();
            List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
            for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
                if (graphicSymbol instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) graphicSymbol;
                    Mark defaultMark = getStyleFactory().getDefaultMark();
                    Fill markFill = mark.getFill();
                    if (markFill != null) {
                        expColour = markFill.getColor();
                    }
                    expStrokeColour = defaultMark.getStroke().getColor();
                    Stroke markStroke = mark.getStroke();
                    if (markStroke != null) {
                        expStrokeColour = markStroke.getColor();
                    }
                } else if (graphicSymbol instanceof ExternalGraphicImpl) {
                    @SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
                }
                symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
            }
        }
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
        if ((graphicFill == null) && (graphicStroke == null)) {
            GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
            if (fillColourGroup != null) {
                fillColourGroup.enable(true);
            }
        }
    // 
    // GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
    // if (strokeColourGroup != null) {
    // strokeColourGroup.enable(strokeColourEnabled);
    // }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) MarkImpl(org.geotools.styling.MarkImpl) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Aggregations

Mark (org.geotools.styling.Mark)34 Test (org.junit.Test)17 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)16 StyleBuilder (org.geotools.styling.StyleBuilder)16 Expression (org.opengis.filter.expression.Expression)16 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)13 Fill (org.geotools.styling.Fill)11 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)10 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)10 Stroke (org.geotools.styling.Stroke)10 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)9 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)8 ArrayList (java.util.ArrayList)8 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)7 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)7 Graphic (org.geotools.styling.Graphic)7 GraphicFill (org.opengis.style.GraphicFill)7 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)6