Exemple #1
0
  /**
   * Fits screen to specified geometry bounds.
   *
   * @param aArea A geometry in geo coordinates space.
   * @throws Exception
   */
  public void fit(Geometry aArea) throws Exception {

    Geometry bounds = aArea.getBoundary();
    Envelope envBounds = bounds.getEnvelopeInternal();
    Point2D.Double leftUpCorner = new Point2D.Double(envBounds.getMinX(), envBounds.getMinY());
    Point2D.Double rightBottomCorner = new Point2D.Double(envBounds.getMaxX(), envBounds.getMaxY());
    Point2D.Double cartlu = geo2Cartesian(leftUpCorner);
    Point2D.Double cartrb = geo2Cartesian(rightBottomCorner);
    double destWidth = Math.abs(cartrb.getX() - cartlu.getX());
    double destHeight = Math.abs(cartrb.getY() - cartlu.getY());
    Coordinate centre =
        new Coordinate((cartrb.getX() + cartlu.getX()) / 2, (cartrb.getY() + cartlu.getY()) / 2);

    Dimension size = getSize();
    Point2D.Double screenLT = awtScreen2Cartesian(new Point(0, 0));
    Point2D.Double screenBR = awtScreen2Cartesian(new Point(size.width, size.height));

    double srcWidth = screenBR.x - screenLT.x;
    double srcHeight = screenBR.y - screenLT.y;
    double sx = srcWidth / destWidth;
    double sy = srcHeight / destHeight;
    double coef = Math.min(sx, sy);
    coef = snapScale(coef);
    scaleView(coef, coef, false);

    Point2D.Double projectedScreenCenter = screen2Cartesian(new Point(0, 0));
    translateView(projectedScreenCenter.x - centre.x, projectedScreenCenter.y - centre.y, true);
    repaint();
  }
Exemple #2
0
 @Override
 protected void paintScreenContext(Graphics2D g) {
   if (screenContext != null) {
     synchronized (screenContext) {
       try {
         // let's paint selection and phanton layers
         screenRenderer.setMapContent(screenContext);
         Rectangle clip = g.getClipBounds();
         Point2D.Double lu = screen2Cartesian(clip.getLocation());
         Point2D.Double br =
             screen2Cartesian(new Point(clip.x + clip.width, clip.y + clip.height));
         Geometry aoiGeometry = constructRectyPolygonGeometry(lu, br);
         Envelope aoiEnvelope =
             new ReferencedEnvelope(
                 aoiGeometry.getEnvelopeInternal(), screenContext.getCoordinateReferenceSystem());
         screenRenderer.paint(g, clip, aoiEnvelope, cartesian2Screen);
       } catch (NoninvertibleTransformException ex) {
         Logger.getLogger(JGeoPane.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
   super.paintScreenContext(g);
 }