private Rule createRule(Color outlineColor, Color fillColor, boolean bSelected) {
    Symbolizer symbolizer = null;
    Fill fill = null;
    Stroke stroke = sf.createStroke(ff.literal(outlineColor), ff.literal(LINE_WIDTH));

    switch (geometryType) {
      case POLYGON:
        fill = sf.createFill(ff.literal(fillColor), ff.literal(OPACITY));
        symbolizer = sf.createPolygonSymbolizer(stroke, fill, geometryAttributeName);
        break;

      case LINE:
        symbolizer = sf.createLineSymbolizer(stroke, geometryAttributeName);
        break;

      case POINT:
        fill = sf.createFill(ff.literal(fillColor), ff.literal(OPACITY));

        Mark mark = sf.getTriangleMark();
        mark.setFill(fill);
        mark.setStroke(stroke);

        Graphic graphic = sf.createDefaultGraphic();
        graphic.graphicalSymbols().clear();
        graphic.graphicalSymbols().add(mark);
        graphic.setSize(ff.literal(bSelected ? SELECTED_POINT_SIZE : POINT_SIZE));

        symbolizer = sf.createPointSymbolizer(graphic, geometryAttributeName);
    }

    Rule rule = sf.createRule();
    rule.symbolizers().add(symbolizer);
    return rule;
  }
Пример #2
0
  @SuppressWarnings("unchecked")
  private static Style createStyle(SimpleFeatureSource source, String fieldName) throws Exception {

    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    Function colourFn = ff.function("colorlookup", ff.literal(source), ff.property(fieldName));

    Stroke stroke =
        styleFactory.createStroke(
            colourFn,
            ff.literal(1.0f), // line
            // width
            ff.literal(1.0f)); // opacity

    Fill fill = styleFactory.createFill(colourFn, ff.literal(1.0f)); // opacity

    Class<?> geomClass = source.getSchema().getGeometryDescriptor().getType().getBinding();
    Symbolizer sym = null;
    Geometries geomType = Geometries.getForBinding((Class<? extends Geometry>) geomClass);

    switch (geomType) {
      case POLYGON:
      case MULTIPOLYGON:
        sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);
        break;

      case LINESTRING:
      case MULTILINESTRING:
        sym = styleFactory.createLineSymbolizer(stroke, null);
        break;

      case POINT:
      case MULTIPOINT:
        Graphic gr = styleFactory.createDefaultGraphic();
        gr.graphicalSymbols().clear();
        Mark mark = styleFactory.getCircleMark();
        mark.setFill(fill);
        mark.setStroke(stroke);
        gr.graphicalSymbols().add(mark);
        gr.setSize(ff.literal(10.0f));
        sym = styleFactory.createPointSymbolizer(gr, null);
        break;

      default:
        throw new IllegalArgumentException("Unsupported geometry type");
    }

    Style style = SLD.wrapSymbolizers(sym);

    return style;
  }