コード例 #1
0
ファイル: JGeoPane.java プロジェクト: cbsistem/PlatypusJS
  /**
   * 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();
  }
コード例 #2
0
ファイル: JGeoPane.java プロジェクト: cbsistem/PlatypusJS
 public void fit() throws Exception {
   MapContent generalMapContext = getGeneralMapContext();
   Dimension size = getSize();
   Envelope projectedBounds = generalMapContext.getMaxBounds();
   double destWidth = projectedBounds.getWidth();
   double destHeight = projectedBounds.getHeight();
   Coordinate centre = projectedBounds.centre();
   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();
 }