コード例 #1
0
ファイル: Main.java プロジェクト: omusico/bisag-gis
  //	public void savePDF(){
  //		 Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize());
  //		  Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize);
  //		  //rotate if we need landscape
  //		  Document document = new Document(pageSize);
  //
  //		  PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
  //		  document.open();
  //		  Graphics2D graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());
  //
  //		  // call your GTRenderer here
  //		  GTRenderer draw = new StreamingRenderer();
  //		  draw.setMapContent(mapContent);
  //
  //		  draw.paint(graphics, outputArea, mapContent.getLayerBounds() );
  //
  //		  // cleanup
  //		  graphics.dispose();
  //
  //		  //cleanup
  //		  document.close();
  //		  writer.close();
  //	}
  public void saveImage(final MapContent map, final String file, final int imageWidth) {

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

    Rectangle imageBounds = null;
    ReferencedEnvelope mapBounds = null;
    try {
      mapBounds = map.getMaxBounds();
      double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
      imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));

    } catch (Exception e) {
      // failed to access mapContent layers
      throw new RuntimeException(e);
    }

    BufferedImage image =
        new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);

    Graphics2D gr = image.createGraphics();
    gr.setPaint(Color.WHITE);
    gr.fill(imageBounds);

    try {
      renderer.paint(gr, imageBounds, mapBounds);
      File fileToSave = new File(file);
      ImageIO.write(image, "jpeg", fileToSave);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: Main.java プロジェクト: omusico/bisag-gis
  public Main() {
    try {

      this.configureDisplay();
      mapPane.setForeground(Color.BLUE);
      refreshBtn.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {

              JMapFrame.splitPane.resetToPreferredSizes();
              JMapFrame.leftSplitPane.resetToPreferredSizes();
              JMapFrame.leftSplitPane.setBottomComponent(null);
              getMapPane().removeAll();
            }
          });
      queryBtn.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
              Thread t =
                  new Thread(
                      new Runnable() {
                        public void run() {
                          new QueryWindow(getMapContent(), getMapContent().layers().get(0))
                              .setVisible(true);
                        }
                      });
              if (getMapContent().layers().size() != 0) t.start();
              else JOptionPane.showMessageDialog(null, "No Layers are added !");
            }
          });
      printBtn.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
              saveNewImage(getMapContent(), "TEST");
              saveImage(getMapContent(), "TEST", 1000);
            }
          });

    } catch (Exception ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(null, ex.getMessage());
    }
  }
コード例 #3
0
ファイル: Main.java プロジェクト: omusico/bisag-gis
  public static void legendAction() {
    try {
      LegendColorTable.countTable = 0;
      Layer layer = content.layers().get(content.layers().size() - 1);
      SimpleFeatureSource featureSource = (SimpleFeatureSource) layer.getFeatureSource();
      String fieldName = getFieldForColour(featureSource);

      if (fieldName != null && fieldName.length() > 0) {

        Style style = createStyle(featureSource, fieldName);

        content.removeLayer(layer);
        Layer newLayer = new FeatureLayer(featureSource, style);
        content.addLayer(newLayer);

      } else throw new NullPointerException("Error occured during making legend");

    } catch (ArrayIndexOutOfBoundsException ex) {
      JOptionPane.showMessageDialog(null, "No layers are added !");
    } catch (Exception ex) {
      ex.printStackTrace();
      // JOptionPane.showMessageDialog(null, ex.getMessage());
    }
  }