Search in sources :

Example 1 with Graphic

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

the class CharacterMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the marker graphic
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markerList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
    if (fontElement != null) {
        JsonObject fontObj = fontElement.getAsJsonObject();
        String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
        int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
        Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
        // Create colour
        Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
        Fill fill = styleFactory.createFill(colour);
        Stroke stroke = null;
        Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
        ExternalGraphic[] externalGraphics = null;
        Mark[] marks = new Mark[1];
        marks[0] = mark;
        Symbol[] symbols = null;
        Expression opacity = null;
        Expression rotation = ff.literal(angle);
        Expression size = ff.literal(symbolSize);
        Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
        // Displacement (offsets)
        if ((xOffset > 0.0) && (yOffset > 0.0)) {
            Expression expressionX = ff.literal(xOffset);
            Expression expressionY = ff.literal(yOffset);
            Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
            graphic.setDisplacement(displacement);
        }
        markerList.add(graphic);
    }
    return markerList;
}
Also used : Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement)

Example 2 with Graphic

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

the class MultiLayerMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param rule the rule
 * @param element the element
 * @param layerName the layer name
 * @param transparency the transparency
 */
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if (rule == null)
        return;
    if (element == null)
        return;
    JsonArray layerArray = element.getAsJsonArray();
    List<Symbolizer> symbolizerList = rule.symbolizers();
    if (layerArray.size() > 0) {
        for (int index = 0; index < layerArray.size(); index++) {
            JsonObject obj = layerArray.get(index).getAsJsonObject();
            JsonElement jsonElement = obj.get(MultiLayerMarkerSymbolKeys.MARKER);
            if (jsonElement != null) {
                JsonObject asJsonObject = jsonElement.getAsJsonObject();
                if (asJsonObject != null) {
                    List<Graphic> markerList = SymbolManager.getInstance().getMarkerList(asJsonObject);
                    if (markerList != null) {
                        for (Graphic marker : markerList) {
                            PointSymbolizer pointSymbolizer = styleFactory.createPointSymbolizer(marker, null);
                            symbolizerList.add(pointSymbolizer);
                        }
                    }
                }
            }
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) PointSymbolizer(org.geotools.styling.PointSymbolizer) JsonElement(com.google.gson.JsonElement) Graphic(org.geotools.styling.Graphic) JsonObject(com.google.gson.JsonObject) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 3 with Graphic

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

the class SimpleMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the graphic marker list
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
    double size = getDouble(obj, CommonSymbolKeys.SIZE);
    int style = getInt(obj, CommonSymbolKeys.STYLE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
    Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
    Expression wellKnownName = ff.literal(styleMap.get(style));
    Stroke stroke = null;
    if (outlineSize > 0.0) {
        stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
    }
    Fill fill = styleFactory.createFill(markerColour);
    Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
    Expression expressionOpacity = null;
    ExternalGraphic[] externalGraphics = null;
    Symbol[] symbols = null;
    Mark[] marks = new Mark[1];
    marks[0] = mark;
    Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
    // Set offset
    if ((xOffset > 0.0) && (yOffset > 0.0)) {
        Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
        graphic.setDisplacement(displacement);
    }
    markList.add(graphic);
    return markList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression)

Example 4 with Graphic

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

the class SymbolManager method getMarkerList.

/**
 * Gets the marker list.
 *
 * @param jsonSymbol the json symbol
 * @return the marker list
 */
public List<Graphic> getMarkerList(JsonObject jsonSymbol) {
    List<Graphic> markList = null;
    for (String markSymbolType : markSymbolMap.keySet()) {
        JsonElement obj = jsonSymbol.get(markSymbolType);
        if (obj != null) {
            EsriMarkSymbolInterface esriMarkSymbol = markSymbolMap.get(markSymbolType);
            markList = esriMarkSymbol.convert(obj);
            break;
        }
    }
    return markList;
}
Also used : Graphic(org.geotools.styling.Graphic) JsonElement(com.google.gson.JsonElement)

Example 5 with Graphic

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

the class VOGeoServerTextSymbolizer2Test method testVOGeoServerTextSymbolizer2.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2#VOGeoServerTextSymbolizer2(java.lang.Class, com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSymbolizer2() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();
    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);
    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);
    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);
    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols().add(styleFactory.createExternalGraphic(new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);
    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());
    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());
    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());
    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);
    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
Also used : VendorOptionPresent(com.sldeditor.common.vendoroption.minversion.VendorOptionPresent) MalformedURLException(java.net.MalformedURLException) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) ArrayList(java.util.ArrayList) OtherText(org.geotools.styling.OtherText) FilterFactory(org.opengis.filter.FilterFactory) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) OtherTextImpl(org.geotools.styling.OtherTextImpl) TextSymbolizer2(org.geotools.styling.TextSymbolizer2) VOGeoServerTextSymbolizer2(com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) Literal(org.opengis.filter.expression.Literal) VOGeoServerTextSymbolizer2(com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2) File(java.io.File) TextSymbolizerDetails(com.sldeditor.ui.detail.TextSymbolizerDetails) Test(org.junit.Test)

Aggregations

Graphic (org.geotools.styling.Graphic)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicalSymbol (org.opengis.style.GraphicalSymbol)16 Fill (org.geotools.styling.Fill)13 Expression (org.opengis.filter.expression.Expression)12 ExternalGraphic (org.geotools.styling.ExternalGraphic)11 Stroke (org.geotools.styling.Stroke)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)9 AnchorPoint (org.geotools.styling.AnchorPoint)8 Displacement (org.geotools.styling.Displacement)8 ArrayList (java.util.ArrayList)7 Mark (org.geotools.styling.Mark)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 MarkImpl (org.geotools.styling.MarkImpl)6 Rule (org.geotools.styling.Rule)6 JsonObject (com.google.gson.JsonObject)5 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 JsonElement (com.google.gson.JsonElement)4 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)4 NamedLayer (org.geotools.styling.NamedLayer)4