Search in sources :

Example 6 with ExternalGraphic

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

the class VOGeoServerTextSymbolizer2 method updateSymbol.

/**
 * Update symbol.
 *
 * @param textSymbolizer the text symbolizer
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#updateSymbol(org.geotools.styling.TextSymbolizer)
     */
@Override
public void updateSymbol(TextSymbolizer textSymbolizer) {
    GroupConfigInterface fillGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_FILL);
    GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_STROKE);
    GroupConfigInterface group = null;
    if (textSymbolizer instanceof TextSymbolizer2) {
        TextSymbolizer2 textSymbol2 = (TextSymbolizer2) textSymbolizer;
        Expression featureDescription = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FEATURE_DESCRIPTION);
        if (!featureDescription.toString().isEmpty()) {
            textSymbol2.setFeatureDescription(featureDescription);
        }
        Expression snippet = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SNIPPET);
        if (!snippet.toString().isEmpty()) {
            textSymbol2.setSnippet(snippet);
        }
        // Extract OtherText
        OtherText otherText = null;
        group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT);
        if (group != null) {
            if (group.isPanelEnabled()) {
                String target = fieldConfigVisitor.getText(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TARGET);
                Expression text = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TEXT);
                if (!target.isEmpty() && !text.toString().isEmpty()) {
                    otherText = new OtherTextImpl();
                    otherText.setTarget(target);
                    otherText.setText(text);
                }
            }
        }
        textSymbol2.setOtherText(otherText);
        // Graphic
        Graphic graphic = null;
        group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_GRAPHIC);
        if (group.isPanelEnabled()) {
            Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SYMBOL_TYPE);
            boolean hasFill = (fillGroup == null) ? false : fillGroup.isPanelEnabled();
            boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
            Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SIZE);
            Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_ANGLE);
            List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
            AnchorPoint anchor = null;
            Displacement displacement = null;
            graphic = getStyleFactory().graphic(symbols, null, size, rotation, anchor, displacement);
            if (!symbols.isEmpty()) {
                boolean overallOpacity = (symbols.get(0) instanceof ExternalGraphic);
                if (overallOpacity) {
                    Expression opacity = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OVERALL_OPACITY);
                    graphic.setOpacity(opacity);
                }
            }
        }
        textSymbol2.setGraphic(graphic);
    }
}
Also used : ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OtherText(org.geotools.styling.OtherText) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) OtherTextImpl(org.geotools.styling.OtherTextImpl) AnchorPoint(org.geotools.styling.AnchorPoint) TextSymbolizer2(org.geotools.styling.TextSymbolizer2) Expression(org.opengis.filter.expression.Expression) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Example 7 with ExternalGraphic

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

the class SLDExternalImagesTest method createGraphic.

/**
 * Creates the graphic.
 *
 * @param url the url
 * @param styleFactory the style factory
 * @return the graphic
 */
private Graphic createGraphic(URL url, StyleFactory styleFactory) {
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(url, "image/png");
    symbolList.add(externalGraphic);
    Graphic graphicFill = styleFactory.graphicFill(symbolList, null, null, null, null, null);
    return graphicFill;
}
Also used : ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Example 8 with ExternalGraphic

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

the class PictureFillSymbol method getFill.

/**
 * Gets the fill.
 *
 * @param layerName the layer name
 * @param obj the obj
 * @param transparency the transparency
 * @return the fill
 */
@SuppressWarnings("unused")
private Fill getFill(String layerName, JsonObject obj, int transparency) {
    double angle = getInt(obj, CommonSymbolKeys.ANGLE);
    double xOffset = getInt(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getInt(obj, CommonSymbolKeys.Y_OFFSET);
    double xScale = getInt(obj, PictureFillSymbolKeys.X_SCALE);
    double yScale = getInt(obj, PictureFillSymbolKeys.Y_SCALE);
    Graphic graphic = null;
    JsonElement pictureElement = obj.get(PictureFillSymbolKeys.PICTURE);
    if (pictureElement != null) {
        JsonObject pictureObj = pictureElement.getAsJsonObject();
        JsonElement imageElement = pictureObj.get(CommonPictureKeys.IMAGE);
        if (imageElement != null) {
            String imageString = imageElement.getAsString();
            byte[] decodedBytes = DatatypeConverter.parseBase64Binary(imageString);
            int height = getInt(pictureObj, CommonPictureKeys.HEIGHT);
            int width = getInt(pictureObj, CommonPictureKeys.WIDTH);
            String imageType = getString(pictureObj, CommonPictureKeys.TYPE);
            ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
            BufferedImage image = null;
            try {
                image = ImageIO.read(bis);
                bis.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (image != null) {
                String filename = String.format("%s.%s", layerName, imageType);
                File file = new File(filename);
                BufferedOutputStream buffOutStream = null;
                try {
                    buffOutStream = new BufferedOutputStream(new FileOutputStream(file));
                    Expression foregroundColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
                    Expression backgroundColour = getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR));
                    if ((foregroundColour != null) && (backgroundColour != null)) {
                        setForegroundColour(foregroundColour, backgroundColour, image);
                    }
                    ImageIO.write(image, imageType, buffOutStream);
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                } finally {
                    if (buffOutStream != null) {
                        try {
                            buffOutStream.close();
                        } catch (IOException e) {
                            ConsoleManager.getInstance().exception(this, e);
                        }
                    }
                }
                String fileExtension = ExternalFilenames.getFileExtension(filename);
                String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
                ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(file.toURI().toString(), imageFormat);
                List<GraphicalSymbol> symbols = getSymbolList(externalGraphic);
                Expression size = null;
                Expression opacity = null;
                Displacement displacement = styleFactory.createDisplacement(ff.literal(xOffset), ff.literal(yOffset));
                AnchorPoint anchorPoint = null;
                graphic = styleFactory.graphic(symbols, opacity, size, ff.literal(angle), anchorPoint, displacement);
            }
        }
    }
    Fill fill = styleFactory.createFill(getColour(obj.get(CommonSymbolKeys.COLOUR)), getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR)), getTransparency(transparency), graphic);
    return fill;
}
Also used : Fill(org.geotools.styling.Fill) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ExternalGraphic(org.geotools.styling.ExternalGraphic) AnchorPoint(org.geotools.styling.AnchorPoint) BufferedImage(java.awt.image.BufferedImage) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with ExternalGraphic

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

the class PointStyleSerializer method serialize.

@Override
public void serialize(PointStyle style, Style result) {
    // default symbolizer
    Graphic gr = sf.createGraphic(null, new Mark[] {}, null, null, null, null);
    PointSymbolizer point = sf.createPointSymbolizer(gr, null);
    // basics / init symbolizer
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, point);
    fts.setName(style.title.opt().orElse("PointStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("PointStyle"));
    accessor.set(rule -> (PointSymbolizer) rule.symbolizers().get(0));
    serialize(style, fts);
    // fill
    style.fill.opt().ifPresent(fill -> {
        // color
        set(fts, style.fill.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setColor(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill", SLDSerializer2.toHexString(literalValue(value)));
                addParam((ExternalGraphic) symbol, "fill-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.fill.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setOpacity(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
    // stroke
    style.stroke.opt().ifPresent(stroke -> {
        // color
        set(fts, style.stroke.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setColor(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.stroke.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setOpacity(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // width
        set(fts, style.stroke.get().width, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setWidth(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-width", literalValue(value).toString() + "px");
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Aggregations

ExternalGraphic (org.geotools.styling.ExternalGraphic)9 Graphic (org.geotools.styling.Graphic)6 GraphicalSymbol (org.opengis.style.GraphicalSymbol)6 Displacement (org.geotools.styling.Displacement)4 Expression (org.opengis.filter.expression.Expression)4 JsonObject (com.google.gson.JsonObject)3 ArrayList (java.util.ArrayList)3 Fill (org.geotools.styling.Fill)3 Mark (org.geotools.styling.Mark)3 JsonElement (com.google.gson.JsonElement)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 AnchorPoint (org.geotools.styling.AnchorPoint)2 Stroke (org.geotools.styling.Stroke)2 Symbol (org.geotools.styling.Symbol)2 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1