Exemple #1
0
 public void run() {
   double[] p;
   try {
     try {
       String[] split = q.split(",");
       p = new double[] {Integer.parseInt(split[0].trim()), Integer.parseInt(split[1].trim())};
     } catch (NumberFormatException e) {
       p = Nominatim.getPoint(q);
     }
     if (p == null) {
       JOptionPane.showMessageDialog(
           appFrame, "Location Not Found.", "", JOptionPane.ERROR_MESSAGE);
     } else {
       View v = wwd.getView();
       if (v != null) {
         v.goTo(Position.fromDegrees(p[0], p[1]), 512 * 30 * 10);
       }
     }
   } catch (MalformedURLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (URISyntaxException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  protected void setEyePosition(
      AnimationController animControl,
      View view,
      Position position,
      ViewInputAttributes.ActionAttributes attrib) {

    MoveToPositionAnimator posAnimator =
        (MoveToPositionAnimator) animControl.get(VIEW_ANIM_POSITION);

    double smoothing = attrib.getSmoothingValue();
    if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;

    if (smoothing != 0.0) {

      double elevation =
          ((FlyViewLimits) view.getViewPropertyLimits())
              .limitEyeElevation(position, view.getGlobe());
      if (elevation != position.getElevation()) {
        position = new Position(position, elevation);
      }
      if (posAnimator == null) {
        posAnimator =
            new MoveToPositionAnimator(
                view.getEyePosition(),
                position,
                smoothing,
                OrbitViewPropertyAccessor.createEyePositionAccessor(view));
        animControl.put(VIEW_ANIM_POSITION, posAnimator);
      } else {
        posAnimator.setEnd(position);
        posAnimator.start();
      }
    }
    view.firePropertyChange(AVKey.VIEW, null, view);
  }
 protected void onResetHeadingPitchRoll(ViewInputAttributes.ActionAttributes actionAttribs) {
   View view = this.getView();
   if (view == null) // include this test to ensure any derived implementation performs it
   {
     return;
   }
   double smoothing = 0.95;
   this.gotoAnimControl.put(
       VIEW_ANIM_HEADING,
       new RotateToAngleAnimator(
           view.getHeading(),
           Angle.ZERO,
           smoothing,
           ViewPropertyAccessor.createHeadingAccessor(view)));
   this.gotoAnimControl.put(
       VIEW_ANIM_PITCH,
       new RotateToAngleAnimator(
           view.getPitch(),
           Angle.POS90,
           smoothing,
           ViewPropertyAccessor.createPitchAccessor(view)));
   this.gotoAnimControl.put(
       VIEW_ANIM_ROLL,
       new RotateToAngleAnimator(
           view.getPitch(), Angle.ZERO, smoothing, ViewPropertyAccessor.createRollAccessor(view)));
   view.firePropertyChange(AVKey.VIEW, null, view);
 }
  protected static boolean isTileVisible(
      DrawContext dc, Tile tile, double minDistanceSquared, double maxDistanceSquared) {
    if (!tile.getSector().intersects(dc.getVisibleSector())) return false;

    View view = dc.getView();
    Position eyePos = view.getEyePosition();
    if (eyePos == null) return false;

    Angle lat =
        clampAngle(
            eyePos.getLatitude(),
            tile.getSector().getMinLatitude(),
            tile.getSector().getMaxLatitude());
    Angle lon =
        clampAngle(
            eyePos.getLongitude(),
            tile.getSector().getMinLongitude(),
            tile.getSector().getMaxLongitude());
    Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
    double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
    //noinspection RedundantIfStatement
    if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

    return true;
  }
  @Override
  protected void doRender(final DrawContext dc) {
    if (dc.isPickingMode()) {
      return;
    }

    if (!_isInitialized) {
      final View view = GGlobeApplication.instance().getView();
      if (view instanceof GCustomView) {
        _isInitialized = true;
      } else {
        throw new RuntimeException(
            "Panoramics only work with a GCustomView. The current View is of type "
                + view.getClass());
      }
    }

    initializeEvents();

    for (final GPanoramic panoramic : _panoramics) {
      if (!panoramic.isHidden()) {
        panoramic.doRender(dc);
      }
    }
  }
  protected void movePolygon(Point previousMousePoint, Point mousePoint) {
    // Intersect a ray through each mouse point, with a geoid passing through the reference
    // elevation.
    // If either ray fails to intersect the geoid, then ignore this event. Use the difference
    // between the two
    // intersected positions to move the control point's location.

    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = this.polygon.getReferencePosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousRay =
        view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.0));
  }
  protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) {
    View view = getWwd().getView();
    EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe();

    // Compute ref-point position in screen coordinates.
    Position refPos = dragObject.getReferencePosition();
    if (refPos == null) return;

    Vec4 refPoint = globe.computePointFromPosition(refPos);
    Vec4 screenRefPoint = view.project(refPoint);

    // Compute screen-coord delta since last event.
    int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x;
    int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y;

    // Find intersection of screen coord ref-point with globe.
    double x = screenRefPoint.x + dx;
    double y =
        dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1;
    Line ray = view.computeRayFromScreenPoint(x, y);
    Intersection inters[] = globe.intersect(ray, refPos.getElevation());

    if (inters != null) {
      // Intersection with globe. Move reference point to the intersection point.
      Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint());
      dragObject.moveTo(p);
    }
  }
 public double getSizeInPixels(DrawContext dc) {
   View view = dc.getView();
   Vec4 centerPoint =
       getSurfacePoint(dc, this.centroid.getLatitude(), this.centroid.getLongitude());
   Double distance = view.getEyePoint().distanceTo3(centerPoint);
   return this.size / view.computePixelSizeAtDistance(distance);
 }
  /**
   * Set the position of the map to the indicated position. If "fly" is true, the map will animate
   * from the current position to the indicated position, otherwise it will jump there immediately.
   *
   * @param pos - desired destination position
   * @param fly - fly if true, jump if false
   */
  public void setPosition(Position pos, boolean fly) {
    View mapView = getWWD().getView();
    if (mapView.isAnimating()) {
      mapView.stopAnimations();
    }

    if (fly) {
      mapView.goTo(pos, pos.getAltitude());
    } else {
      mapView.setEyePosition(pos);
      getWWD().redraw();
    }
  }
  protected void doMoveAirspaceLaterally(
      WorldWindow wwd, Airspace airspace, Point mousePoint, Point previousMousePoint) {
    // Intersect a ray throuh each mouse point, with a geoid passing through the reference
    // elevation. Since
    // most airspace control points follow a fixed altitude, this will track close to the intended
    // mouse position.
    // If either ray fails to intersect the geoid, then ignore this event. Use the difference
    // between the two
    // intersected positions to move the control point's location.

    if (!(airspace instanceof Movable)) {
      return;
    }

    Movable movable = (Movable) airspace;
    View view = wwd.getView();
    Globe globe = wwd.getModel().getGlobe();

    Position refPos = movable.getReferencePosition();
    if (refPos == null) return;

    // Convert the reference position into a cartesian point. This assumes that the reference
    // elevation is defined
    // by the airspace's lower altitude.
    Vec4 refPoint = null;
    if (airspace.isTerrainConforming()[LOWER_ALTITUDE])
      refPoint = wwd.getSceneController().getTerrain().getSurfacePoint(refPos);
    if (refPoint == null) refPoint = globe.computePointFromPosition(refPos);

    // Convert back to a position.
    refPos = globe.computePositionFromPoint(refPoint);

    Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousRay =
        view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(wwd, refPos.getElevation(), ray);
    Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    movable.move(new Position(change.getLatitude(), change.getLongitude(), 0.0));

    this.fireAirspaceMoved(new AirspaceEditEvent(wwd, airspace, this));
  }
  public void apply() {
    super.apply();

    View view = this.getView();
    if (view == null) {
      return;
    }
    if (this.gotoAnimControl.stepAnimators()) {
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
    if (this.uiAnimControl.stepAnimators()) {
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
  /**
   * Determine if this label intersects the view or pick frustum.
   *
   * @param dc Current draw context.
   * @return True if this label intersects the active frustum (view or pick). Otherwise false.
   */
  protected boolean intersectsFrustum(DrawContext dc) {
    View view = dc.getView();
    Frustum frustum = view.getFrustumInModelCoordinates();

    // Test the label's model coordinate point against the near and far clipping planes.
    if (this.placePoint != null
        && (frustum.getNear().distanceTo(this.placePoint) < 0
            || frustum.getFar().distanceTo(this.placePoint) < 0)) {
      return false;
    }

    if (dc.isPickingMode()) return dc.getPickFrustums().intersectsAny(this.screenExtent);
    else return view.getViewport().intersects(this.screenExtent);
  }
  /**
   * Called when the roll changes due to user input.
   *
   * @param rollChange Change in roll.
   * @param actionAttribs Action that caused the change.
   */
  protected void onRoll(Angle rollChange, ViewInputAttributes.ActionAttributes actionAttribs) {
    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }

    if (view instanceof BasicFlyView) {
      BasicFlyView flyView = (BasicFlyView) view;
      this.setRoll(flyView, this.uiAnimControl, flyView.getRoll().add(rollChange), actionAttribs);

      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
Exemple #14
0
  /**
   * Compute the lat/lon position of the view center
   *
   * @param dc the current DrawContext
   * @param view the current View
   * @return the ground position of the view center or null
   */
  protected Position computeGroundPosition(DrawContext dc, View view) {
    if (view == null) return null;

    Position groundPos =
        view.computePositionFromScreenPoint(
            view.getViewport().getWidth() / 2, view.getViewport().getHeight() / 2);
    if (groundPos == null) return null;

    double elevation =
        dc.getGlobe().getElevation(groundPos.getLatitude(), groundPos.getLongitude());
    return new Position(
        groundPos.getLatitude(),
        groundPos.getLongitude(),
        elevation * dc.getVerticalExaggeration());
  }
  protected void onVerticalTranslate(
      double translateChange,
      double totalTranslateChange,
      ViewInputAttributes.DeviceAttributes deviceAttributes,
      ViewInputAttributes.ActionAttributes actionAttribs) {
    this.stopGoToAnimators();
    double elevChange =
        -(totalTranslateChange * getScaleValueElevation(deviceAttributes, actionAttribs));
    View view = this.getView();
    Position position = view.getEyePosition();
    Position newPos = new Position(position, position.getElevation() + (elevChange));
    this.setEyePosition(uiAnimControl, view, newPos, actionAttribs);

    view.firePropertyChange(AVKey.VIEW, null, view);
  }
    public void doActionOnButton1() {
      Logging.logger().info("Zooming to Matterhorn");

      View view = this.wwd.getView();

      Position matterhorn =
          new Position(LatLon.fromDegrees(45.9763888888889d, 7.65833333333333d), 0d);

      //            Position eyePos = new Position( LatLon.fromDegrees( 46.01066860997058d,
      // 7.633097536001656d ), 3363d );
      //
      //            view.setEyePosition( eyePos );
      //            view.setHeading( Angle.fromDegrees( 156d ));
      //            view.setPitch( Angle.fromDegrees( 89.9d ));

      view.goTo(matterhorn, 5000d);
    }
  protected void onResetPitch(ViewInputAttributes.ActionAttributes actionAttribs) {

    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }
    double smoothing = actionAttribs.getSmoothingValue();
    if (!(actionAttribs.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;
    this.gotoAnimControl.put(
        VIEW_ANIM_PITCH,
        new RotateToAngleAnimator(
            view.getPitch(),
            Angle.POS90,
            smoothing,
            ViewPropertyAccessor.createPitchAccessor(view)));
    view.firePropertyChange(AVKey.VIEW, null, view);
  }
  protected void onHorizontalTranslateRel(
      Angle forwardChange, Angle sideChange, ViewInputAttributes.ActionAttributes actionAttribs) {
    View view = this.getView();
    if (view == null) // include this test to ensure any derived implementation performs it
    {
      return;
    }

    if (forwardChange.equals(Angle.ZERO) && sideChange.equals(Angle.ZERO)) {
      return;
    }

    if (view instanceof BasicFlyView) {

      Vec4 forward = view.getForwardVector();
      Vec4 up = view.getUpVector();
      Vec4 side = forward.transformBy3(Matrix.fromAxisAngle(Angle.fromDegrees(90), up));

      forward = forward.multiply3(forwardChange.getDegrees());
      side = side.multiply3(sideChange.getDegrees());
      Vec4 eyePoint = view.getEyePoint();
      eyePoint = eyePoint.add3(forward.add3(side));
      Position newPosition = view.getGlobe().computePositionFromPoint(eyePoint);

      this.setEyePosition(this.uiAnimControl, view, newPosition, actionAttribs);
      view.firePropertyChange(AVKey.VIEW, null, view);
    }
  }
  /**
   * Set the roll in a view.
   *
   * @param view View to modify.
   * @param animControl Animator controller for the view.
   * @param roll new roll value.
   * @param attrib action that caused the roll to change.
   */
  protected void setRoll(
      View view,
      AnimationController animControl,
      Angle roll,
      ViewInputAttributes.ActionAttributes attrib) {
    double smoothing = attrib.getSmoothingValue();
    if (!(attrib.isEnableSmoothing() && this.isEnableSmoothing())) smoothing = 0.0;

    AngleAnimator angleAnimator =
        new RotateToAngleAnimator(
            view.getRoll(), roll, smoothing, ViewPropertyAccessor.createRollAccessor(view));
    animControl.put(VIEW_ANIM_ROLL, angleAnimator);
  }
  private boolean needToSplit(DrawContext dc, Sector sector) {
    Vec4[] corners = sector.computeCornerPoints(dc.getGlobe(), dc.getVerticalExaggeration());
    Vec4 centerPoint = sector.computeCenterPoint(dc.getGlobe(), dc.getVerticalExaggeration());

    View view = dc.getView();
    double d1 = view.getEyePoint().distanceTo3(corners[0]);
    double d2 = view.getEyePoint().distanceTo3(corners[1]);
    double d3 = view.getEyePoint().distanceTo3(corners[2]);
    double d4 = view.getEyePoint().distanceTo3(corners[3]);
    double d5 = view.getEyePoint().distanceTo3(centerPoint);

    double minDistance = d1;
    if (d2 < minDistance) minDistance = d2;
    if (d3 < minDistance) minDistance = d3;
    if (d4 < minDistance) minDistance = d4;
    if (d5 < minDistance) minDistance = d5;

    double cellSize =
        (Math.PI * sector.getDeltaLatRadians() * dc.getGlobe().getRadius()) / 20; // TODO

    return !(Math.log10(cellSize) <= (Math.log10(minDistance) - this.splitScale));
  }
  protected void moveControlPoint(
      ControlPointMarker controlPoint, Point lastMousePoint, Point moveToPoint) {
    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = controlPoint.getPosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(moveToPoint.getX(), moveToPoint.getY());
    Line previousRay = view.computeRayFromScreenPoint(lastMousePoint.getX(), lastMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    java.util.List<LatLon> boundary = new ArrayList<LatLon>();
    for (LatLon ll : this.polygon.getOuterBoundary()) {
      boundary.add(ll);
    }

    boundary.set(controlPoint.getIndex(), new Position(pos.add(change), refPos.getAltitude()));

    // ExtrudedPolygon ensures that the last boundary position is the same as the first. Remove the
    // last point
    // before setting the boundary.
    boundary.remove(boundary.size() - 1);

    this.polygon.setOuterBoundary(boundary);
  }
    /**
     * Loads .track file from newTrackFile to trackLDMIO, inits debug run, zooms to newest GpsPoint
     *
     * @param newTrackFile URI to track file
     * @return if loading the trackfile was successful
     */
    private boolean loadNewData(String newTrackFile) {
      LDMIOTrack tmpTrackLDMIO;
      try {
        tmpTrackLDMIO = new LDMIOTrack(newTrackFile);
      } catch (IOException e) {
        return false;
      }

      save();
      trackLDMIO = tmpTrackLDMIO;

      enableSettingsMode(true);
      initDebugRun();

      if (trackLDMIO.getAllGpsPoints().size() > 0) {
        View view = globeMapPanel.wwd.getView();
        view.goTo(new Position(translateToGlobePosition(trackLDMIO.getLastGpsPoint()), 0), 4000);
      }

      slider.setMaximum(
          (trackLDMIO.getAllGpsPoints() == null) ? 0 : trackLDMIO.getAllGpsPoints().size());
      setTitle("testloc.world + " + newTrackFile);
      return true;
    }
    protected boolean isNavSectorVisible(
        DrawContext dc, double minDistanceSquared, double maxDistanceSquared) {
      if (!navSector.intersects(dc.getVisibleSector())) return false;

      View view = dc.getView();
      Position eyePos = view.getEyePosition();
      if (eyePos == null) return false;

      // check for eyePos over globe
      if (Double.isNaN(eyePos.getLatitude().getDegrees())
          || Double.isNaN(eyePos.getLongitude().getDegrees())) return false;

      Angle lat =
          clampAngle(eyePos.getLatitude(), navSector.getMinLatitude(), navSector.getMaxLatitude());
      Angle lon =
          clampAngle(
              eyePos.getLongitude(), navSector.getMinLongitude(), navSector.getMaxLongitude());
      Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
      double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
      //noinspection RedundantIfStatement
      if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

      return true;
    }
Exemple #24
0
 public Double getCurrentAltitude() {
   View view = this.getWWd().getView();
   return view != null ? view.getEyePosition().getElevation() : null;
 }