/** Encodes a KML IconStyle + PolyStyle from a polygon style and symbolizer. */
    protected void setPolygonStyle(
        Style style, SimpleFeature feature, PolygonSymbolizer symbolizer, boolean forceOutline) {
      // if stroke specified add line style as well (it has to be before the fill, otherwise
      // we'll get a white filling...)
      if (symbolizer.getStroke() != null) {
        setLineStyle(style, feature, symbolizer.getStroke());
      }

      // fill
      PolyStyle ps = style.createAndSetPolyStyle();
      Fill fill = symbolizer.getFill();
      if (fill != null) {
        // get opacity
        Double opacity = fill.getOpacity().evaluate(feature, Double.class);
        if (opacity == null || Double.isNaN(opacity)) {
          opacity = 1.0;
        }

        Color color = (Color) fill.getColor().evaluate(feature, Color.class);
        ps.setColor(colorToHex(color, opacity));
      } else {
        // make it transparent
        ps.setColor("00aaaaaa");
      }

      // outline
      if (symbolizer.getStroke() != null || forceOutline) {
        ps.setOutline(true);
      }
    }
  @Test
  public void testConvertJsonElement() {
    LineFillSymbol symbol = new LineFillSymbol();

    String layerName = "test layer";
    int transparency = 1;

    JsonElement json = ParserUtils.readTestData("/LineFillSymbol.json");

    assertNull(symbol.convertToFill(null, null, transparency));

    List<Symbolizer> symbolizerList = symbol.convertToFill(layerName, json, transparency);

    assertEquals(1, symbolizerList.size());

    SupportingUtils.outputSymbolizer(symbolizerList);

    PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizerList.get(0);

    Graphic graphicFill = polygon.getFill().getGraphicFill();
    Mark mark = (Mark) graphicFill.graphicalSymbols().get(0);

    assertNull(mark.getFill());
    Stroke stroke = mark.getStroke();
    String strokeColour = ((LiteralExpressionImpl) stroke.getColor()).toString();
    assertEquals("#E60000", strokeColour);

    assertEquals(
        "shape://slash", (String) SupportingUtils.getExpressionValue(mark.getWellKnownName()));
    assertEquals(
        "#00FF00", (String) SupportingUtils.getExpressionValue(polygon.getStroke().getColor()));
  }
Example #3
0
  private void quickPolygonSymbolizer() {
    // quickPolygonSymbolizer start
    StyleBuilder styleBuilder = new StyleBuilder();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    PolygonSymbolizer polygonSymbolizer = styleBuilder.createPolygonSymbolizer(Color.BLUE);
    polygonSymbolizer.getFill().setOpacity(ff.literal(0.5)); // 50% blue

    polygonSymbolizer.setStroke(styleBuilder.createStroke(Color.BLACK, 2.0));

    // will create a default feature type style and rule etc...
    Style style = styleBuilder.createStyle(polygonSymbolizer);
    // quickPolygonSymbolizer end
  }
Example #4
0
  @Test
  public void testSEStyleWithRelativePath() throws IOException {
    StyleInfo si = getCatalog().getStyleByName("relative");

    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 = DataUtilities.urlToFile(uri.toURL()).getCanonicalFile();
    assertEquals(rockFillSymbolFile, actual);
  }