Java Code Examples for org.geotools.styling.PointSymbolizer#setGraphic()

The following examples show how to use org.geotools.styling.PointSymbolizer#setGraphic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtractAttributes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.PointSymbolizer)
 */
@Override
public void visit(PointSymbolizer ps) {
    PointSymbolizer copy = sf.getDefaultPointSymbolizer();

    copy.setGeometry(copy(Point.class, ps.getGeometry()));

    copy.setUnitOfMeasure(ps.getUnitOfMeasure());
    copy.setGraphic(copy(ps.getGraphic()));
    copy.getOptions().putAll(ps.getOptions());

    if (STRICT && !copy.equals(ps)) {
        throw new IllegalStateException("Was unable to duplicate provided Graphic:" + ps);
    }
    pages.push(copy);
}
 
Example 2
Source File: RuleRenderVisitor.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.PointSymbolizer)
 */
public void visit(PointSymbolizer ps) {
    PointSymbolizer copy = sf.getDefaultPointSymbolizer();

    copy.setGeometry(copy(ps.getGeometry()));

    copy.setUnitOfMeasure(ps.getUnitOfMeasure());
    copy.setGraphic(copy(ps.getGraphic()));
    copy.getOptions().putAll(ps.getOptions());

    if (STRICT) {
        if (!copy.equals(ps)) {
            throw new IllegalStateException("Was unable to duplicate provided Graphic:" + ps);
        }
    }
    pages.push(copy);
}
 
Example 3
Source File: SLDTreeLeafPoint.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFill(Symbolizer symbolizer) {
    if (symbolizer instanceof PointSymbolizer) {
        PointSymbolizer point = (PointSymbolizer) symbolizer;

        Graphic graphic = point.getGraphic();
        if (graphic == null) {
            graphic = styleFactory.createDefaultGraphic();
            point.setGraphic(graphic);
        }

        if ((graphic != null) && graphic.graphicalSymbols().isEmpty()) {
            Mark mark = styleFactory.getDefaultMark();

            graphic.graphicalSymbols().add(mark);
        }
    }
}
 
Example 4
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a default {@link Rule} for a point.
 * 
 * @return the default rule.
 */
public static Rule createDefaultPointRule() {
    Graphic graphic = sf.createDefaultGraphic();
    Mark circleMark = sf.getCircleMark();
    circleMark.setFill(sf.createFill(ff.literal("#" + Integer.toHexString(Color.RED.getRGB() & 0xffffff))));
    circleMark.setStroke(sf.createStroke(ff.literal("#" + Integer.toHexString(Color.BLACK.getRGB() & 0xffffff)),
            ff.literal(DEFAULT_WIDTH)));
    graphic.graphicalSymbols().clear();
    graphic.graphicalSymbols().add(circleMark);
    graphic.setSize(ff.literal(DEFAULT_SIZE));

    PointSymbolizer pointSymbolizer = sf.createPointSymbolizer();
    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(pointSymbolizer);

    pointSymbolizer.setGraphic(graphic);
    return rule;
}
 
Example 5
Source File: SLDTreeLeafPoint.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeFill(Symbolizer symbolizer) {
    if (symbolizer instanceof PointSymbolizer) {
        PointSymbolizer point = (PointSymbolizer) symbolizer;

        point.setGraphic(null);
    }
}
 
Example 6
Source File: SLDTreeLeafPointTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafPoint#hasFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testHasFill() {
    SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();

    assertFalse(leaf.hasFill(null));
    assertFalse(leaf.hasFill(DefaultSymbols.createDefaultPolygonSymbolizer()));

    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    assertTrue(leaf.hasFill(pointSymbolizer));

    pointSymbolizer.setGraphic(null);
    assertFalse(leaf.hasFill(pointSymbolizer));
}
 
Example 7
Source File: SLDTreeLeafPointTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.tree.leaf.SLDTreeLeafPoint#createFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testCreateFill() {
    SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    pointSymbolizer.setGraphic(null);

    leaf.createFill(pointSymbolizer);

    assertTrue(pointSymbolizer.getGraphic() != null);
}
 
Example 8
Source File: SLDExternalImagesTest.java    From sldeditor with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates the test point.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPoint(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();

    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    sld.addStyledLayer(namedLayer);

    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);

    PointSymbolizer point = styleFactory.createPointSymbolizer();

    rule.symbolizers().add(point);

    Graphic graphic = createGraphic(url, styleFactory);

    point.setGraphic(graphic);

    return sld;
}