Example #1
0
  @SuppressWarnings("unchecked")
  private void paintMe(PaintEvent e) {
    int width = e.gc.getClipping().width;
    int height = e.gc.getClipping().height;

    if (map != null) {
      // sort out the transforms
      org.eclipse.swt.graphics.Rectangle paintArea =
          new org.eclipse.swt.graphics.Rectangle(0, 0, width, height);
      ReferencedEnvelope mapArea = map.getViewport().getBounds();
      setTransforms(mapArea, paintArea);

      StreamingRenderer renderer = new StreamingRenderer();
      renderer.setMapContent(map);

      RenderingHints hints =
          new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      renderer.setJava2DHints(hints);

      @SuppressWarnings("rawtypes")
      Map rendererParams = new HashMap();
      rendererParams.put("optimizedDataLoadingEnabled", new Boolean(true));

      renderer.setRendererHints(rendererParams);

      org.eclipse.swt.graphics.Rectangle curPaintArea = e.gc.getClipping();
      BufferedImage baseImage =
          new BufferedImage(
              curPaintArea.width + 1, curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2d = baseImage.createGraphics();
      g2d.fillRect(0, 0, curPaintArea.width + 1, curPaintArea.height + 1);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      // renderer.setContext(context);
      java.awt.Rectangle awtRectangle = Utils.toAwtRectangle(curPaintArea);
      final ReferencedEnvelope mapAOI = map.getViewport().getBounds();
      renderer.paint(g2d, awtRectangle, mapAOI, getWorldToScreenTransform());
      // swtImage.dispose();

      if (swtImage != null && !swtImage.isDisposed()) {
        swtImage.dispose();
        swtImage = null;
      }
      swtImage =
          new Image(
              canvas.getDisplay(),
              awtToSwt(baseImage, curPaintArea.width + 1, curPaintArea.height + 1));

      // org.eclipse.swt.graphics.Image image = new
      // org.eclipse.swt.graphics.Image(
      // e.display, convertToSWT(tmpImage));
      e.gc.drawImage(swtImage, 0, 0);
    }

    double y2 = Math.random() * 120d;
    e.gc.drawLine(20, 40, 80, (int) y2);
  };
  @Override
  public void paint(Graphics2D g, MapView mv, Bounds box) {
    LatLon min = box.getMin();
    LatLon max = box.getMax();

    Envelope envelope2 =
        new Envelope(
            Math.min(min.lat(), max.lat()),
            Math.max(min.lat(), max.lat()),
            Math.min(min.lon(), max.lon()),
            Math.max(min.lon(), max.lon()));

    ReferencedEnvelope mapArea = new ReferencedEnvelope(envelope2, crsOSMI);

    renderer.setInteractive(false);
    renderer.paint(g, mv.getBounds(), mapArea);
    bIsChanged = false;
  }