org.geotools.styling.Fill类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中org.geotools.styling.Fill类的一些代码示例,展示了Fill类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fill类的具体详情如下:
包路径:org.geotools.styling.Fill
类名称:Fill

Fill介绍

[英]The Fill object encapsulates the graphical-symbolization parameters for areas of geometries.

There are two types of fill: solid-color and repeated graphic fill.

The details of this object are taken from the OGC Styled-Layer Descriptor Report (OGC 02-070) version 1.0.0.:

<xsd:element name="Fill"> 
<xsd:annotation> 
<xsd:documentation> 
A "Fill" specifies the pattern for filling an area geometry. 
The allowed CssParameters are: "fill" (color) and "fill-opacity". 
</xsd:documentation> 
</xsd:annotation> 
<xsd:complexType> 
<xsd:sequence> 
<xsd:element ref="sld:GraphicFill" minOccurs="0"/> 
<xsd:element ref="sld:CssParameter" minOccurs="0" 
maxOccurs="unbounded"/> 
</xsd:sequence> 
</xsd:complexType> 
</xsd:element>

Renderers can use this information when displaying styled features, though it must be remembered that not all renderers will be able to fully represent strokes as set out by this interface. For example, opacity may not be supported.

Notes:

  • The graphical parameters and their values are derived from SVG/CSS2 standards with names and semantics which are as close as possible.
    [中]填充对象封装了几何图形区域的图形符号化参数。
    有两种类型的填充:纯色和重复图形填充。
    此对象的详细信息取自OGC Styled-Layer Descriptor Report (OGC 02-070) version 1.0.0.
<xsd:element name="Fill"> 
<xsd:annotation> 
<xsd:documentation> 
A "Fill" specifies the pattern for filling an area geometry. 
The allowed CssParameters are: "fill" (color) and "fill-opacity". 
</xsd:documentation> 
</xsd:annotation> 
<xsd:complexType> 
<xsd:sequence> 
<xsd:element ref="sld:GraphicFill" minOccurs="0"/> 
<xsd:element ref="sld:CssParameter" minOccurs="0" 
maxOccurs="unbounded"/> 
</xsd:sequence> 
</xsd:complexType> 
</xsd:element>

渲染器可以在显示样式化特征时使用此信息,但必须记住,并非所有渲染器都能够完全表示此接口设置的笔划。例如,不透明度可能不受支持。
笔记:
*图形参数及其值源自SVG/CSS2标准,其名称和语义尽可能接近。

代码示例

代码示例来源:origin: geotools/geotools

public Fill createFill(
    Expression color, Expression backgroundColor, Expression opacity, Graphic graphicFill) {
  Fill fill = new FillImpl(filterFactory);
  if (color == null) {
    color = Fill.DEFAULT.getColor();
  }
  fill.setColor(color);
  if (backgroundColor == null) {
    backgroundColor = Fill.DEFAULT.getBackgroundColor();
  }
  fill.setBackgroundColor(backgroundColor);
  if (opacity == null) {
    opacity = Fill.DEFAULT.getOpacity();
  }
  // would be nice to check if this was within bounds but we have to wait until use since it
  // may depend on an attribute
  fill.setOpacity(opacity);
  fill.setGraphicFill(graphicFill);
  return fill;
}

代码示例来源:origin: geotools/geotools

/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Fill) */
public void visit(Fill fill) {
  if (fill.getBackgroundColor() != null) {
    fill.getBackgroundColor().accept(this, null);
  }
  if (fill.getColor() != null) {
    fill.getColor().accept(this, null);
  }
  if (fill.getGraphicFill() != null) {
    fill.getGraphicFill().accept(this);
  }
  if (fill.getOpacity() != null) {
    fill.getOpacity().accept(this, null);
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Null safe fill copy
 *
 * @param graphic
 * @return copy of graphic or null if not provided
 */
protected Fill copy(Fill fill) {
  if (fill == null) return null;
  fill.accept(this);
  return (Fill) pages.pop();
}

代码示例来源:origin: geotools/geotools

/** Reset to produce the default Fill. */
public FillBuilder reset() {
  unset = false;
  color = Fill.DEFAULT.getColor();
  opacity = Fill.DEFAULT.getOpacity();
  graphic.unset();
  return this;
}

代码示例来源:origin: geotools/geotools

@Override
  protected void encode(Fill fill) {
    putColor("fill-color", fill.getColor());
    put("fill-opacity", nullIf(fill.getOpacity(), 1d));
    if (fill.getGraphicFill() != null) {
      push("fill-graphic").inline(new GraphicEncoder(fill.getGraphicFill()));
    }
  }
}

代码示例来源:origin: geotools/geotools

if (LOGGER.isLoggable(Level.FINEST))
      LOGGER.finest("setting fill graphic with " + g);
    fill.setGraphicFill(g);
    fill.setColor(parseCssParameter(child));
  } else if (res.equalsIgnoreCase(opacityString)
      || res.equalsIgnoreCase("fill-opacity")) {
    fill.setOpacity(parseCssParameter(child));
LOGGER.finest("fill graphic " + fill.getGraphicFill());

代码示例来源:origin: geotools/geotools

@Test
  public void testRescalePolygonMargin() throws Exception {
    // create a graphic that needs rescaling
    StyleBuilder sb = new StyleBuilder();

    // a graphic fill
    Fill fill = sb.createFill();
    fill.setColor(null);
    fill.setGraphicFill(
        sb.createGraphic(null, sb.createMark("square", null, sb.createStroke(2)), null));

    // a polygon and line symbolizer using them
    PolygonSymbolizer polygonSymbolizer = sb.createPolygonSymbolizer(sb.createStroke(), fill);
    polygonSymbolizer.getOptions().put(PolygonSymbolizer.GRAPHIC_MARGIN_KEY, "1 2 3 4");

    // rescale it
    polygonSymbolizer.accept(visitor);
    PolygonSymbolizer rps = (PolygonSymbolizer) visitor.getCopy();
    Mark rm = (Mark) rps.getFill().getGraphicFill().graphicalSymbols().get(0);
    assertEquals(4.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d);
    assertEquals("2 4 6 8", rps.getOptions().get(PolygonSymbolizer.GRAPHIC_MARGIN_KEY));
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Retrieve the color of a fill object
 *
 * @param fill a Fill object
 * @return color or null if fill was null
 */
public static Color color(Fill fill) {
  if (fill == null) {
    return null;
  }
  return color(fill.getColor());
}

代码示例来源:origin: geotools/geotools

public Fill getDefaultFill() {
  Fill fill = new FillImpl(filterFactory);
  try {
    fill.setColor(filterFactory.literal("#808080"));
    fill.setOpacity(filterFactory.literal(new Double(1.0)));
    fill.setBackgroundColor(filterFactory.literal("#FFFFFF"));
  } catch (org.geotools.filter.IllegalFilterException ife) {
    throw new RuntimeException("Error creating fill", ife);
  }
  return fill;
}

代码示例来源:origin: geotools/geotools

protected Paint getPaint(Fill fill, Object feature, Symbolizer symbolizer) {
  if (fill == null) {
    return null;
  }
  // get fill color
  Paint fillPaint = evalToColor(fill.getColor(), feature, null);
  // if a graphic fill is to be used, prepare the paint accordingly....
  org.geotools.styling.Graphic gr = fill.getGraphicFill();
  if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) {
    fillPaint = getTexturePaint(gr, feature, symbolizer);
  }
  return fillPaint;
}

代码示例来源:origin: geotools/geotools

@Override
public void handle(YamlObject<?> obj, YamlParseContext context) {
  YamlMap map = obj.map();
  if (map.has("fill-color")) {
    fill().setColor(Util.color(map.get("fill-color"), factory));
  }
  if (map.has("fill-opacity")) {
    fill().setOpacity(Util.expression(map.str("fill-opacity"), factory));
  }
  context.push(
      "fill-graphic",
      new GraphicParser(factory) {
        @Override
        protected void graphic(Graphic g) {
          fill().setGraphicFill(g);
        }
      });
}

代码示例来源:origin: geotools/geotools

/**
 * Retrieve the opacity from the provided fill; or return the default.
 *
 * @param fill
 * @return opacity from the above fill; or return the Fill.DEFAULT value
 */
public static double opacity(Fill fill) {
  if (fill == null) {
    fill = Fill.DEFAULT;
  }
  Expression opacityExp = fill.getOpacity();
  if (opacityExp == null) {
    opacityExp = Fill.DEFAULT.getOpacity();
  }
  return Filters.asDouble(opacityExp);
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testSEStyleWithRelativePathProtocol() throws IOException {
  StyleInfo si = getCatalog().getStyleByName("relative_protocol");
  assertNotNull(si);
  Style style = si.getStyle();
  PolygonSymbolizer ps =
      (PolygonSymbolizer)
          style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
  ExternalGraphic eg =
      (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0);
  URI uri = eg.getOnlineResource().getLinkage();
  assertNotNull(uri);
  File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile();
  assertEquals(rockFillSymbolFile, actual);
}

代码示例来源:origin: geotools/geotools

if (fill.getGraphicFill() != null) {
  double size = evalToDouble(fill.getGraphicFill().getSize(), feature, 0);
  if (isVectorRenderingEnabled() || size > MAX_RASTERIZATION_SIZE) {
            feature, symbolizer, fill.getGraphicFill(), scaleRange, false);
    if (!(style2DFill instanceof GraphicStyle2D)) {
      style.setGraphicFill(style2DFill);
  opacity = evalOpacity(symbolizer.getFill().getOpacity(), feature);

代码示例来源:origin: geotools/geotools

fill.setOpacity(opacity);
fill.setGraphicFill(graphicFill);

代码示例来源:origin: bcdev/beam

@Override
  public void visit(TextSymbolizer text) {
    super.visit(text);
    TextSymbolizer textCopy = (TextSymbolizer) pages.peek();
    Fill textFill = textCopy.getFill();
    if (textFill != null) {
      textFill.setOpacity(textExp);
    } else {
      textCopy.setFill(defaultTextFill);
    }
  }
}

代码示例来源:origin: org.geotools/gt-widgets-swing-pending

private void butFillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butFillActionPerformed
  JDialog dia = new JDialog();
  JGraphicPane pane = new JGraphicPane();
  pane.setLayer(layer);
  if (fill != null) {
    pane.setEdited(fill.getGraphicFill());
  }
  dia.setContentPane(pane);
  dia.pack();
  dia.setLocationRelativeTo(butFill);
  dia.setModal(true);
  dia.setVisible(true);
  if (fill == null) {
    fill = new StyleBuilder().createFill();
  }
  fill.setGraphicFill(pane.getEdited());
}//GEN-LAST:event_butFillActionPerformed

代码示例来源:origin: geotools/geotools

/**
 * Sets the colour to use for outline (stroke) and fill in a polygon symbolizer
 *
 * @param symbolizer the polygon symbolizer
 * @param colour the colour for polygon outlines and fill
 */
public static void setPolyColour(PolygonSymbolizer symbolizer, Color colour) {
  if (symbolizer == null || colour == null) {
    return;
  }
  Expression colourExp = ff.literal(colour);
  Stroke stroke = symbolizer.getStroke();
  if (stroke == null) {
    stroke = sf.createStroke(colourExp, Stroke.DEFAULT.getWidth());
    symbolizer.setStroke(stroke);
  } else {
    stroke.setColor(ff.literal(colour));
  }
  Fill fill = symbolizer.getFill();
  if (fill != null) {
    fill.setColor(colourExp);
  }
}

代码示例来源:origin: geotools/geotools

@Override
  protected void graphic(Graphic g) {
    fill().setGraphicFill(g);
  }
});

代码示例来源:origin: geotools/geotools

public void visit(Fill fill) {
  start("Fill");
  if (fill.getGraphicFill() != null) {
    start("GraphicFill");
    fill.getGraphicFill().accept(this);
    end("GraphicFill");
  }
  encodeCssParam("fill", fill.getColor(), "#808080");
  encodeCssParam("fill-opacity", fill.getOpacity(), 1.0);
  end("Fill");
}

相关文章