Esempio n. 1
0
  private void quickTextSymbolizer() {
    // quickTextSymbolizer start
    // "labelPoint" feature type style
    StyleBuilder sb = new StyleBuilder();
    FilterFactory2 ff = sb.getFilterFactory();

    // creation of the TextSymbolizer
    AnchorPoint anchorPoint =
        sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y"));
    PointPlacement pointPlacement =
        sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0));
    TextSymbolizer textSymbolizer =
        sb.createTextSymbolizer(
            sb.createFill(Color.BLACK),
            new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)},
            sb.createHalo(),
            sb.attributeExpression("name"),
            pointPlacement,
            null);

    // creation of the Point symbolizer
    Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED);
    Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0);
    PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2);

    // creation of the style
    Style style = sb.createStyle();
    FeatureTypeStyle featureTypeStyle =
        sb.createFeatureTypeStyle("labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer});
    style.featureTypeStyles().add(featureTypeStyle);

    // creation of the style
    // quickTextSymbolizer end
  }
Esempio n. 2
0
  private void markTestSLD() {
    // markTestSLD start
    StyleBuilder sb = new StyleBuilder();
    FilterFactory ff = sb.getFilterFactory();
    Style style = sb.createStyle();
    style.setName("MyStyle");

    // "testPoint" feature type style
    Mark testMark =
        sb.createMark(sb.attributeExpression("name"), sb.createFill(Color.RED, 0.5), null);
    Graphic graph =
        sb.createGraphic(
            null,
            new Mark[] {testMark},
            null,
            sb.literalExpression(1),
            sb.attributeExpression("size"),
            sb.attributeExpression("rotation"));
    style
        .featureTypeStyles()
        .add(sb.createFeatureTypeStyle("testPoint", sb.createPointSymbolizer(graph)));

    // "labelPoint" feature type style
    AnchorPoint anchorPoint =
        sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y"));
    PointPlacement pointPlacement =
        sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0));
    TextSymbolizer textSymbolizer =
        sb.createTextSymbolizer(
            sb.createFill(Color.BLACK),
            new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)},
            sb.createHalo(),
            sb.attributeExpression("name"),
            pointPlacement,
            null);
    Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED);
    Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0);
    PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2);
    style
        .featureTypeStyles()
        .add(
            sb.createFeatureTypeStyle(
                "labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer}));
    // markTestSLD end
  }
Esempio n. 3
0
  public static Symbolizer[] getSymbolizers(
      Class<? extends Geometry> type, Color baseColor, boolean useTransparency) {

    StyleBuilder builder = new StyleBuilder();
    Symbolizer[] syms = new Symbolizer[1];
    if (LineString.class.isAssignableFrom(type) || MultiLineString.class.isAssignableFrom(type))
      syms[0] = builder.createLineSymbolizer(baseColor, 2);
    if (Point.class.isAssignableFrom(type) || MultiPoint.class.isAssignableFrom(type)) {
      PointSymbolizer point = builder.createPointSymbolizer(builder.createGraphic());
      FilterFactory ff = builder.getFilterFactory();
      // point.getGraphic().getMarks()[0].setSize((Expression) ff.literal(10));
      point.getGraphic().setSize(ff.literal(10));
      Mark mark = (Mark) point.getGraphic().graphicalSymbols().get(0);
      mark.setFill(builder.createFill(baseColor));
      syms[0] = point;
    }
    if (Polygon.class.isAssignableFrom(type) || MultiPolygon.class.isAssignableFrom(type)) {
      syms[0] =
          builder.createPolygonSymbolizer(
              builder.createStroke(baseColor, 2),
              builder.createFill(baseColor, useTransparency ? .6 : 1.0));
    }
    return syms;
  }
Esempio n. 4
0
  private void quickPointSymbolizer() {
    // quickPointSymbolizer start
    // "testPoint" feature type style
    StyleBuilder sb = new StyleBuilder();
    FilterFactory2 ff = sb.getFilterFactory();

    Mark testMark =
        sb.createMark(sb.attributeExpression("name"), sb.createFill(Color.RED, 0.5), null);
    Graphic graph =
        sb.createGraphic(
            null, // An external graphics if needed
            new Mark[] {testMark}, // a Mark if not an external graphics
            null, // aSymbol
            ff.literal(1), // opacity
            ff.property("size"), // read from feature "size" attribute
            ff.property("rotation")); // rotation, here read into the feature
    PointSymbolizer aPointSymbolizer = sb.createPointSymbolizer(graph);

    // creation of the style
    Style style = sb.createStyle(aPointSymbolizer);
    // quickPointSymbolizer end
  }
Esempio n. 5
0
  /**
   * Constructs a TextSymbolizer from the inputs
   *
   * @param build
   * @return TextSymbolizer defined by this model
   */
  public TextSymbolizer get(StyleBuilder build) {
    if (!this.enabled) {
      return null;
    }
    if (this.font == null || this.font.length == 0) {
      return null;
    }
    if (this.labelType == null || "".equals(this.labelType)) { // $NON-NLS-1$
      return null;
    }

    String fontName = this.font[0].getName();
    boolean fontBold = (this.font[0].getStyle() == SWT.BOLD);
    boolean fontItalic = (this.font[0].getStyle() == SWT.ITALIC);
    double fontSize = this.font[0].getHeight();
    Font gtFont = build.createFont(fontName, fontItalic, fontBold, fontSize);
    Fill fill = build.createFill(this.colour);

    LabelPlacement placement;
    if (pointPlacement) {
      // PointPlacement
      double horiz;
      if (this.place.getSelectionIndex() < 3) {
        switch (this.place.getSelectionIndex()) {
          case 0:
            horiz = SLDs.ALIGN_LEFT;
            break;
          case 1:
            horiz = SLDs.ALIGN_CENTER;
            break;
          case 2:
            horiz = SLDs.ALIGN_RIGHT;
            break;

          default:
            horiz = SLDs.ALIGN_CENTER;
            break;
        }
      } else { // custom value
        horiz = Double.parseDouble(this.place.getText());
      }

      double vert;
      if (this.place2.getSelectionIndex() < 3) {
        switch (this.place2.getSelectionIndex()) {
          case 0:
            vert = SLDs.ALIGN_BOTTOM;
            break;
          case 1:
            vert = SLDs.ALIGN_MIDDLE;
            break;
          case 2:
            vert = SLDs.ALIGN_TOP;
            break;

          default:
            vert = SLDs.ALIGN_MIDDLE;
            break;
        }
      } else { // custom value
        vert = Double.parseDouble(this.place2.getText());
      }

      double rotation = Double.parseDouble(this.place3.getText());

      placement = build.createPointPlacement(vert, horiz, rotation);
    } else {
      // LinePlacement
      double offset = Double.parseDouble(this.place.getText());
      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 (SLD.isLine(this.schema)) {
      text.addToOptions("group", "yes"); // $NON-NLS-1$ //$NON-NLS-2$
    }
    text.addToOptions("spaceAround", "2"); // $NON-NLS-1$ //$NON-NLS-2$
    return text;
  }