Ejemplo n.º 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();
  }
Ejemplo n.º 2
0
 public double snapScale(double coef) {
   if (getBackingUrl() != null && !getBackingUrl().isEmpty()) {
     double powValue = Math.log(coef) / Math.log(2);
     Long lPowValue = Math.round(powValue);
     return Math.pow(2, lPowValue);
   } else {
     return coef;
   }
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
 public Point cartesian2Screen(Point2D.Double aPt) throws FactoryException, TransformException {
   Point2D.Double screenPt = new Point2D.Double();
   cartesian2Screen.transform(aPt, screenPt);
   return new Point((int) Math.round(screenPt.getX()), (int) Math.round(screenPt.getY()));
 }