Пример #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;
  }
  /**
   * @param wfsClient
   * @throws NoSuchAuthorityCodeException
   * @throws FactoryException
   * @throws IOException
   * @throws IndexOutOfBoundsException
   * @throws ParseException
   */
  public OsmInspectorLayer(GeoFabrikWFSClient wfsClient, ProgressMonitor monitor)
      throws NoSuchAuthorityCodeException, FactoryException, IOException, IndexOutOfBoundsException,
          ParseException {
    super("OsmInspector");

    arrFeatures = new ArrayList<>();
    osmiBugInfo = new LinkedHashMap<>();
    selectGeomType = new ArrayList<>();

    // Step 3 - discovery; enhance to iterate over all types with bounds

    String typeNames[] = wfsClient.getTypeNames();
    renderer = new StreamingRenderer();
    CRS.decode(Main.getProjection().toCode());
    crsOSMI = CRS.decode("EPSG:4326");
    content = new MapContent(crsOSMI);

    selectGeomType.add(GeomType.POINT);
    for (int idx = 1; idx < typeNames.length; ++idx) {
      String typeName = typeNames[idx];
      Set<FeatureId> selectedFeatures = new HashSet<>();

      FeatureCollection<SimpleFeatureType, SimpleFeature> features =
          wfsClient.getFeatures(typeName, monitor);
      setGeometry(selectGeomType, typeName);

      Main.info("Osm Inspector Features size: " + features.size());
      Style style = createDefaultStyle(idx, selectedFeatures);

      OSMIFeatureTracker tracker = new OSMIFeatureTracker(features);
      arrFeatures.add(tracker);
      FeatureIterator<SimpleFeature> it = tracker.getFeatures().features();

      while (it.hasNext()) {
        BugInfo theInfo = new BugInfo(it.next(), osmiBugInfo.size());
        osmiBugInfo.put(theInfo, theInfo.bugId);
      }

      content.addLayer(new FeatureLayer(tracker.getFeatures(), style));
    }

    osmiIndex = new BugIndex(osmiBugInfo);
    content.setTitle("Osm Inspector Errors");
    renderer.setMapContent(content);
    bIsChanged = true;

    // finally initialize the dialog
    dialog = new OsmInspectorDialog(this);
    this.updateView();
  }