Package org.geotools.styling

Examples of org.geotools.styling.TextSymbolizer


        String name = DEFAULT_GEOMETRY;

        Stroke stroke = null;
        Fill fill = null;
        Graphic graphic = null;
        TextSymbolizer text = null;
        LabelPlacement placement = null;

        List<Rule> rules = Collections.emptyList();
        if (fts != null)
            rules = fts.rules();
        if (rules.size() > 1) {
            // simple mode trimms away all but the first rule
            Rule keepRule = rules.get(0);
            rules.clear();
            rules.add(keepRule);
        }
        this.mode = determineMode(schema, true);

        if (mode == Mode.NONE) {
            pointMode.setSelection(false);
            polyMode.setSelection(false);
            lineMode.setSelection(false);
        } else if (mode == Mode.LINE) {
            lineMode.setSelection(true);
            LineSymbolizer sym = SLDs.lineSymbolizer(fts);
            stroke = SLDs.stroke(sym);
            placement = SLDs.getPlacement(SLDs.ALIGN_LEFT, SLDs.ALIGN_MIDDLE, 0);

            name = sym == null ? null : sym.getGeometryPropertyName();
        } else if (mode == Mode.POLYGON) {
            polyMode.setSelection(true);
            PolygonSymbolizer sym = SLDs.polySymbolizer(fts);
            stroke = SLDs.stroke(sym);
            fill = SLDs.fill(sym);
            placement = SLDs.getPlacement(SLDs.ALIGN_CENTER, SLDs.ALIGN_MIDDLE, 0);

            name = sym == null ? null : sym.getGeometryPropertyName();
        } else if (mode == Mode.POINT || mode == Mode.ALL) { // default to handling as Point
            pointMode.setSelection(true);

            PointSymbolizer sym = SLDs.pointSymbolizer(fts);
            stroke = SLDs.stroke(sym);
            fill = SLDs.fill(sym);
            graphic = SLDs.graphic(sym);
            placement = SLDs.getPlacement(SLDs.ALIGN_LEFT, SLDs.ALIGN_MIDDLE, 0);

            name = sym == null ? null : sym.getGeometryPropertyName();
        }

        text = SLDs.textSymbolizer(fts);
        if (text != null && placement != null) {
            text.setLabelPlacement(placement);
        }

        if (name == null) {
            name = DEFAULT_GEOMETRY;
            geometryName.getCombo().setText(name);
View Full Code Here


    }

    /** Synchronize the SLD with the array of symbolizers */
    public void synchronize() {
        List<Symbolizer> acquire = new ArrayList<Symbolizer>();
        TextSymbolizer textSym = this.label.get(this.build);

        SimpleFeatureType schema = featureCollection.getSchema();
        this.mode = determineMode(schema, true);

        String geometryPropertyName = null;
View Full Code Here

    }

    public void test() throws Exception {
        SLDMockData.textSymbolizer(document, document);

        TextSymbolizer ts = (TextSymbolizer) parse();
        assertNotNull(ts);
        assertNotNull(ts.getFill());
        assertEquals(1, ts.getFonts().length);
        assertNotNull(ts.getGeometryPropertyName());
        assertNotNull(ts.getPlacement());
        assertNotNull(ts.getHalo());
        assertNotNull(ts.getLabel());
    }
View Full Code Here

    }
   
    public void testWithVendorOptions() throws Exception {
        SLDMockData.textSymbolizerWithVendorOptions(document, document);
       
        TextSymbolizer ts = (TextSymbolizer) parse();
        assertNotNull(ts);
       
        //vendorOption(document, textSymbolizer, "followLine", "true");
        //vendorOption(document, textSymbolizer, "spaceAround", "10");
        assertEquals("true", ts.getOptions().get("followLine"));
        assertEquals("10", ts.getOptions().get("spaceAround"));
    }
View Full Code Here

        <Fill>
            <SvgParameter name="fill">#000000</SvgParameter>
        </Fill>
    </TextSymbolizer>*/
       
        TextSymbolizer sym = (TextSymbolizer) parse("example-textsymbolizer.xml");
        assertEquals("MyTextSymbolizer", sym.getName());
        assertEquals("Example TextSymbolizer", sym.getDescription().getTitle().toString());
        assertEquals("This is just an example of a text symbolizer using the FormatNumber function.",
            sym.getDescription().getAbstract().toString());
       
        assertEquals("locatedAt", sym.getGeometryPropertyName());
       
        Function l = (Function) sym.getLabel();
        assertEquals("foobar (10)", l.evaluate(f1));
        //assertEquals("hospitalName", l);
       
        Font f = sym.getFont();
        assertEquals(2, f.getFamily().size());
        assertEquals("Arial", f.getFamily().get(0).evaluate(null, String.class));
        assertEquals("Sans-Serif", f.getFamily().get(1).evaluate(null, String.class));
        assertEquals("italic", f.getStyle().evaluate(null, String.class));
        assertEquals("10", f.getSize().evaluate(null, String.class));
       
        Fill fill = sym.getFill();
        assertEquals(Color.BLACK, fill.getColor().evaluate(null, Color.class));
    }
View Full Code Here

       
        PointSymbolizer point = (PointSymbolizer) rule.symbolizers().get(2);
        assertEquals(1, point.getOptions().size());
        assertEquals("true", point.getOptions().get("labelObstacle"));
       
        TextSymbolizer text = (TextSymbolizer) rule.symbolizers().get(3);
        assertEquals(1, text.getOptions().size());
        assertEquals("100", text.getOptions().get("repeat"));
       
        // check it passes validation
        List errors = validate(file);
        assertEquals(0, errors.size());
    }
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        TextSymbolizer ts = styleFactory.createTextSymbolizer();

        //&lt;xsd:element ref="sld:Geometry" minOccurs="0"/&gt;
        if(node.hasChild("Geometry")) {
            Expression geometry = (Expression) node.getChildValue("Geometry");
            if(geometry instanceof PropertyName) {
                PropertyName propertyName = (PropertyName) geometry;
                ts.setGeometryPropertyName(propertyName.getPropertyName());
            } else {
                ts.setGeometry(geometry);
            }
        }

        //&lt;xsd:element ref="sld:Label" minOccurs="0"/&gt;
        if (node.hasChild("Label")) {
            ts.setLabel((Expression) node.getChildValue("Label"));
        }

        //&lt;xsd:element ref="sld:Font" minOccurs="0"/&gt;
        if (node.hasChild("Font")) {
            ts.setFonts(new Font[] { (Font) node.getChildValue("Font") });
        }

        //&lt;xsd:element ref="sld:LabelPlacement" minOccurs="0"/&gt;
        if (node.hasChild("LabelPlacement")) {
            ts.setPlacement((LabelPlacement) node.getChildValue("LabelPlacement"));
        }

        //&lt;xsd:element ref="sld:Halo" minOccurs="0"/&gt;
        if (node.hasChild("Halo")) {
            ts.setHalo((Halo) node.getChildValue("Halo"));
        }

        //&lt;xsd:element ref="sld:Fill" minOccurs="0"/&gt;
        if (node.hasChild("Fill")) {
            ts.setFill((Fill) node.getChildValue("Fill"));
        }

        //&lt;xsd:element ref="sld:VendorOption" minOccurs="0" maxOccurs="unbounded"/&gt;
        for (CssParameter param : (List<CssParameter>) node.getChildValues(CssParameter.class)) {
            ts.getOptions().put(param.getName(), param.getExpression().evaluate(null, String.class));
        }
        return ts;
    }
View Full Code Here

        assertEquals(20.0f, clone.getDashArray()[1], 0d);
    }
   
    @Test
    public void testTextSymbolizer() throws Exception {
        TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "label");
        ts.getOptions().put(TextSymbolizer.MAX_DISPLACEMENT_KEY, "10");
        ts.getOptions().put(TextSymbolizer.GRAPHIC_MARGIN_KEY, "10 20");
       
        ts.accept(visitor);
        TextSymbolizer clone = (TextSymbolizer) visitor.getCopy();
        assertEquals("20", clone.getOptions().get(TextSymbolizer.MAX_DISPLACEMENT_KEY));
        assertEquals("20 40", clone.getOptions().get(TextSymbolizer.GRAPHIC_MARGIN_KEY));
    }
View Full Code Here

        assertEquals("20 40", clone.getOptions().get(TextSymbolizer.GRAPHIC_MARGIN_KEY));
    }
   
    @Test
    public void testTextSymbolizerArraySingleValue() throws Exception {
        TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "label");
        ts.getOptions().put(TextSymbolizer.GRAPHIC_MARGIN_KEY, "10");
       
        ts.accept(visitor);
        TextSymbolizer clone = (TextSymbolizer) visitor.getCopy();
        assertEquals("20", clone.getOptions().get(TextSymbolizer.GRAPHIC_MARGIN_KEY));
    }
View Full Code Here

            placement = build.createLinePlacement(offset);
        }
        this.labelPlacement = placement;

        Expression exp = (Expression) CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()).property(this.labelType);
        TextSymbolizer text = build.createTextSymbolizer(fill, new Font[]{gtFont}, null, exp, placement, null);
        if (SLDs.isLine(this.schema)) {
            text.getOptions().put("group", "yes"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        text.getOptions().put("spaceAround", "2"); //$NON-NLS-1$ //$NON-NLS-2$
        return text;
    }
View Full Code Here

TOP

Related Classes of org.geotools.styling.TextSymbolizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.