예제 #1
0
  @Test
  public void testRepeatedEnvelopeExpansion() throws Exception {
    final List<Filter> filters = new ArrayList<Filter>();

    SimpleFeatureSource testSource =
        new CollectionFeatureSource(createLineCollection()) {
          @Override
          public SimpleFeatureCollection getFeatures(Query query) {
            filters.add(query.getFilter());
            return super.getFeatures(query);
          }
        };

    StyleBuilder sb = new StyleBuilder();
    Style style20 = sb.createStyle(sb.createLineSymbolizer(20));
    Style style10 = sb.createStyle(sb.createLineSymbolizer(10));

    MapContent mc = new MapContent();
    mc.addLayer(new FeatureLayer(testSource, style20));
    mc.addLayer(new FeatureLayer(testSource, style10));

    StreamingRenderer sr = new StreamingRenderer();
    sr.setMapContent(mc);
    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D graphics = bi.createGraphics();
    sr.paint(
        graphics,
        new Rectangle(0, 0, 100, 100),
        new ReferencedEnvelope(0, 100, 0, 100, DefaultGeographicCRS.WGS84));
    graphics.dispose();

    System.out.println(filters);
    assertEquals(2, filters.size());
    Filter f1 = filters.get(0);
    assertTrue(f1 instanceof BBOX);
    BoundingBox bbox1 = ((BBOX) f1).getBounds();
    ReferencedEnvelope expected =
        new ReferencedEnvelope(-11, 111, -11, 111, DefaultGeographicCRS.WGS84);
    assertEquals(expected, bbox1);
    Filter f2 = filters.get(1);
    assertTrue(f2 instanceof BBOX);
    BoundingBox bbox2 = ((BBOX) f2).getBounds();
    assertEquals(new ReferencedEnvelope(-6, 106, -6, 106, DefaultGeographicCRS.WGS84), bbox2);
  }
예제 #2
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;
  }
예제 #3
0
  @Test
  public void testScreenMapMemory() {
    // build a feature source with two zig-zag line occupying the same position
    LiteCoordinateSequence cs =
        new LiteCoordinateSequence(new double[] {0, 0, 1, 1, 2, 0, 3, 1, 4, 0});
    SimpleFeature zigzag1 =
        SimpleFeatureBuilder.build(
            testLineFeatureType, new Object[] {gf.createLineString(cs)}, "zz1");
    SimpleFeature zigzag2 =
        SimpleFeatureBuilder.build(
            testLineFeatureType, new Object[] {gf.createLineString(cs)}, "zz2");
    DefaultFeatureCollection fc = new DefaultFeatureCollection();
    fc.add(zigzag1);
    fc.add(zigzag2);
    SimpleFeatureSource zzSource = new CollectionFeatureSource(fc);

    // prepare the map
    MapContent mc = new MapContent();
    StyleBuilder sb = new StyleBuilder();
    mc.addLayer(new FeatureLayer(zzSource, sb.createStyle(sb.createLineSymbolizer())));
    StreamingRenderer sr = new StreamingRenderer();
    sr.setMapContent(mc);

    // collect rendered features
    final List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    RenderListener renderedFeaturesCollector =
        new RenderListener() {

          @Override
          public void featureRenderer(SimpleFeature feature) {
            features.add(feature);
          }

          @Override
          public void errorOccurred(Exception e) {
            // nothing to do
          }
        };
    sr.addRenderListener(renderedFeaturesCollector);
    BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D graphics = bi.createGraphics();
    // have the lines be smaller than a 1/3 of a pixel
    sr.paint(
        graphics,
        new Rectangle(0, 0, 1, 1),
        new ReferencedEnvelope(0, 8, 0, 8, DefaultGeographicCRS.WGS84));

    // check we only rendered one feature
    assertEquals(1, features.size());
    assertEquals("zz1", features.get(0).getID());

    // now have the lines be big enough to be painted instead
    features.clear();
    sr.paint(
        graphics,
        new Rectangle(0, 0, 1, 1),
        new ReferencedEnvelope(0, 1, 0, 1, DefaultGeographicCRS.WGS84));
    assertEquals(2, features.size());
    assertEquals("zz1", features.get(0).getID());
    assertEquals("zz2", features.get(1).getID());

    graphics.dispose();
  }
예제 #4
0
 private Style createLineStyle() {
   StyleBuilder sb = new StyleBuilder();
   return sb.createStyle(sb.createLineSymbolizer());
 }