コード例 #1
0
ファイル: OMDistance.java プロジェクト: OpenMap-java/openmap
  /**
   * Get an OMText label for a segments between the given lat/lon points whose given distance and
   * cumulative distance is specified.
   */
  public OMText createLabel(
      Geo g1, Geo g2, double dist, double cumulativeDist, Length distanceUnits) {
    Geo mid;
    switch (getLineType()) {
      case LINETYPE_STRAIGHT:
        double lat = (g1.getLatitude() + g2.getLatitude()) / 2.0;
        double lon = (g1.getLongitude() + g2.getLongitude()) / 2.0;
        mid = new Geo(lat, lon);
        break;
      case LINETYPE_RHUMB:
        System.err.println("Rhumb distance calculation not implemented.");
      case LINETYPE_GREATCIRCLE:
      case LINETYPE_UNKNOWN:
      default:
        mid = g1.midPoint(g2);
    }

    // String text = ((int)dist) + " (" + ((int)cumulativeDist) +
    // ")";

    String text =
        (df.format(distanceUnits.fromRadians(dist)))
            + " ("
            + (df.format(distanceUnits.fromRadians(cumulativeDist)))
            + ") "
            + distanceUnits.getAbbr();
    OMText omtext = new OMText(mid.getLatitude(), mid.getLongitude(), text, OMText.JUSTIFY_LEFT);
    // omtext.setLinePaint(new Color(200, 200, 255));
    return omtext;
  }
コード例 #2
0
  private Position findIntersectionBottom(Position newPos) {
    // The mouse can be in 4 different areas
    int lengthMax = 500000;

    double bearing = C.rhumbLineBearingTo(newPos);

    System.out.println("Vertical bearing " + verticalBearing);
    System.out.println("Horizontal bearing " + horizontalBearing);

    Geo intersectionPoint = null;

    if (bearing >= 0 && bearing <= 180) {

      // if (bearing > 90 && bearing < 180){

      // Create a line going from C, in reverse vertical direction eg up
      Position verticalEndPosition = Calculator.findPosition(A, verticalBearing, lengthMax);
      Geo a1 = new Geo(A.getLatitude(), A.getLongitude());
      Geo a2 = new Geo(verticalEndPosition.getLatitude(), verticalEndPosition.getLongitude());

      // Create a line going from newPos in reverse horizontal direction
      // eg left
      Position horizontalEndPosition =
          Calculator.findPosition(
              newPos, Calculator.reverseDirection(horizontalBearing), lengthMax);

      Geo b1 = new Geo(newPos.getLatitude(), newPos.getLongitude());
      Geo b2 = new Geo(horizontalEndPosition.getLatitude(), horizontalEndPosition.getLongitude());

      intersectionPoint = Intersection.segmentsIntersect(a1, a2, b1, b2);
    }

    if (bearing > 180) {

      // Create a line going from C, in reverse vertical direction eg up
      Position verticalEndPosition = Calculator.findPosition(C, verticalBearing, lengthMax);
      Geo a1 = new Geo(C.getLatitude(), C.getLongitude());
      Geo a2 = new Geo(verticalEndPosition.getLatitude(), verticalEndPosition.getLongitude());

      // Create a line going from newPos in horizontal direction eg right
      Position horizontalEndPosition =
          Calculator.findPosition(newPos, horizontalBearing, lengthMax);

      Geo b1 = new Geo(newPos.getLatitude(), newPos.getLongitude());
      Geo b2 = new Geo(horizontalEndPosition.getLatitude(), horizontalEndPosition.getLongitude());

      intersectionPoint = Intersection.segmentsIntersect(a1, a2, b1, b2);
    }

    if (intersectionPoint != null) {

      newPos = Position.create(intersectionPoint.getLatitude(), intersectionPoint.getLongitude());

      return newPos;

    } else {
      System.out.println("something went bad... for mouse bearing " + bearing);

      return null;
    }
  }