Search in sources :

Example 56 with PointSymbolizer

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

the class PointFillDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Expression expSize = null;
    Expression expRotation = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    PointSymbolizer pointSymbolizer = null;
    if (selectedSymbol != null) {
        Symbolizer symbolizer = selectedSymbol.getSymbolizer();
        if (symbolizer instanceof PointSymbolizerImpl) {
            pointSymbolizer = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbolizer.getGraphic();
            if (graphic != null) {
                expSize = graphic.getSize();
                expRotation = graphic.getRotation();
                // Anchor point
                AnchorPoint anchorPoint = graphic.getAnchorPoint();
                if (anchorPoint != null) {
                    expAnchorPointX = anchorPoint.getAnchorPointX();
                    expAnchorPointY = anchorPoint.getAnchorPointY();
                } else {
                    expAnchorPointX = AnchorPoint.DEFAULT.getAnchorPointX();
                    expAnchorPointY = AnchorPoint.DEFAULT.getAnchorPointY();
                }
                // Offset
                Displacement displacement = graphic.getDisplacement();
                if (displacement != null) {
                    expDisplacementX = displacement.getDisplacementX();
                    expDisplacementY = displacement.getDisplacementY();
                } else {
                    expDisplacementX = Displacement.DEFAULT.getDisplacementX();
                    expDisplacementY = Displacement.DEFAULT.getDisplacementY();
                }
                expGap = graphic.getGap();
                expInitialGap = graphic.getInitialGap();
                List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
                if (!graphicalSymbolList.isEmpty()) {
                    GraphicalSymbol symbol = graphicalSymbolList.get(0);
                    symbolTypeFactory.setValue(PointSymbolizer.class, this.fieldConfigManager, graphic, symbol);
                }
            }
        }
    }
    fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
    fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
    fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
    fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
    if (vendorOptionFillFactory != null) {
        vendorOptionFillFactory.populate(pointSymbolizer);
    }
    updateSymbol();
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) Symbolizer(org.opengis.style.Symbolizer) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl) Displacement(org.geotools.styling.Displacement)

Example 57 with PointSymbolizer

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

the class PointSymbolizerDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        StandardData standardData = getStandardData();
        Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);
        PointSymbolizer pointSymbolizer = (PointSymbolizer) SelectedSymbol.getInstance().getSymbolizer();
        if (pointSymbolizer != null) {
            pointSymbolizer.setName(standardData.name);
            pointSymbolizer.setDescription(standardData.description);
            pointSymbolizer.setUnitOfMeasure(standardData.unit);
            pointSymbolizer.setGeometry(geometryField);
            this.fireUpdateSymbol();
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Expression(org.opengis.filter.expression.Expression)

Example 58 with PointSymbolizer

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

the class CreateInternalDataSourceTest method testDetermineGeometryType.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
 */
@Test
public void testDetermineGeometryType() {
    TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
    assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
    // Create StyledLayerDescriptor
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    UserLayer userLayer = styleFactory.createUserLayer();
    sld.addStyledLayer(userLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    // Raster
    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    rule.symbolizers().add(raster);
    assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
    // Polygon
    rule.symbolizers().clear();
    PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
    // Line
    rule.symbolizers().clear();
    LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Point
    rule.symbolizers().clear();
    PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
    // Add line to point
    rule.symbolizers().add(line);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add point, line
    rule.symbolizers().clear();
    rule.symbolizers().add(line);
    rule.symbolizers().add(point);
    assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
    // Add polygon, line
    rule.symbolizers().clear();
    rule.symbolizers().add(point);
    rule.symbolizers().add(polygon);
    assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) 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) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 59 with PointSymbolizer

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

the class PointSymbolizerDetailsTest method testPointSymbolizerDetails.

/**
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#preLoadSymbol()}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#PointSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testPointSymbolizerDetails() {
    SelectedSymbol.destroyInstance();
    PointSymbolizerDetails panel = new PointSymbolizerDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);
    PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    panel.dataChanged(null);
    FieldConfigString descriptionField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.DESCRIPTION);
    assertNull(descriptionField);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
}
Also used : PointSymbolizerDetails(com.sldeditor.ui.detail.PointSymbolizerDetails) PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Example 60 with PointSymbolizer

use of org.geotools.styling.PointSymbolizer 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

PointSymbolizer (org.geotools.styling.PointSymbolizer)67 Test (org.junit.Test)32 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)25 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)23 LineSymbolizer (org.geotools.styling.LineSymbolizer)23 Style (org.geotools.styling.Style)22 Rule (org.geotools.styling.Rule)19 Graphic (org.geotools.styling.Graphic)16 NamedLayer (org.geotools.styling.NamedLayer)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)13 Symbolizer (org.geotools.styling.Symbolizer)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)10 GraphicalSymbol (org.opengis.style.GraphicalSymbol)9 SLDTreeLeafPoint (com.sldeditor.common.tree.leaf.SLDTreeLeafPoint)8 MarkImpl (org.geotools.styling.MarkImpl)8 FeatureStyle (org.polymap.core.style.model.FeatureStyle)7 PointStyle (org.polymap.core.style.model.feature.PointStyle)7 Fill (org.geotools.styling.Fill)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)6 ArrayList (java.util.ArrayList)5