Ejemplo 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
  }
Ejemplo 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
  }
Ejemplo n.º 3
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;
  }