Example #1
0
  public void actionPerformed(ActionEvent ae) {
    if (map != null) {
      Proj proj = (Proj) map.getProjection();
      DataBounds bounds = provider.getDataBounds();

      if (bounds != null) {
        java.awt.geom.Point2D center = bounds.getCenter();
        if (center != null) {
          proj.setCenter((float) center.getY(), (float) center.getX());
          LatLonPoint llp1 = new LatLonPoint(bounds.getMax().getY(), bounds.getMin().getX());

          LatLonPoint llp2 = new LatLonPoint(bounds.getMin().getY(), bounds.getMax().getX());

          // 1.1 buffers the edges for viewing a little, a
          // little zommed out.
          proj.setScale(ProjMath.getScale(llp1, llp2, proj) * 1.1f);
          map.setProjection(proj);
        }
      } else {
        String complaint =
            "Can't move map over data: " + provider.getName() + " isn't ready.  Add to map?";
        if (infoDelegator != null) {
          infoDelegator.displayMessage("Go Over Data", complaint);
        } else {
          Debug.error(complaint);
        }
      }
    }
  }
Example #2
0
  /**
   * Add the projection background color to the base level of the Java 3D map. The MapHandler
   * provides the MapBean and therefore the projection.
   *
   * @param bg The feature to be added to the Sea attribute
   * @param mh The feature to be added to the Sea attribute
   */
  protected void addSea(Group bg, MapHandler mh) {
    MapBean map = (MapBean) mh.get("com.bbn.openmap.MapBean");
    if (map != null) {
      Debug.message("3d", "LayerMapContent: putting down sea.");
      Color seaColor = map.getBackground();

      Projection proj = map.getProjection();

      // Make the background strech a screen around the current
      // map, all directions.
      int width = proj.getWidth();
      int height = proj.getHeight();

      java.awt.geom.GeneralPath background =
          // OMGraphic.createBoxShape(0, 0, width, height);
          OMGraphicAdapter.createBoxShape(-width, -height, width * 3, height * 3);

      addTo(bg, OMGraphicUtil.createShape3D(background, 0, seaColor, true));
    }
  }
  /**
   * Function to add a specific message to the map
   *
   * @param message
   */
  public void setMarker(MsiMessageExtended message) {
    this.message = message;
    this.msiLocation = message.msiMessage.getLocation().getCenter();
    LatLonPoint center = (LatLonPoint) mapBean.getCenter();
    GeoLocation geoCenter = new GeoLocation(center.getLatitude(), center.getLongitude());
    double bearing = Calculator.bearing(geoCenter, msiLocation, Heading.RL);

    Projection projection = mapBean.getProjection();
    Point2D projectedMSI =
        projection.forward(msiLocation.getLatitude(), msiLocation.getLongitude());

    Point2D origin = new Point2D.Double(mapBean.getWidth() * 0.5f, mapBean.getHeight() * 0.5f);
    Line2D direction = new Line2D.Double(origin, projectedMSI);

    double boxWidth = mapBean.getWidth() - IMAGE_SIZE / 2;
    double boxHeight = mapBean.getHeight() - IMAGE_SIZE / 2;
    Line2D topFrame = new Line2D.Double(IMAGE_SIZE / 2, IMAGE_SIZE / 2, boxWidth, IMAGE_SIZE / 2);
    Line2D rightFrame = new Line2D.Double(boxWidth, IMAGE_SIZE / 2, boxWidth, boxHeight);
    Line2D bottomFrame = new Line2D.Double(IMAGE_SIZE / 2, boxHeight, boxWidth, boxHeight);
    Line2D leftFrame = new Line2D.Double(IMAGE_SIZE / 2, IMAGE_SIZE / 2, IMAGE_SIZE / 2, boxHeight);

    boolean intersects = false;

    if (intersects(direction, topFrame)) intersects = true;
    if (intersects(direction, rightFrame)) intersects = true;
    if (intersects(direction, bottomFrame)) intersects = true;
    if (intersects(direction, leftFrame)) intersects = true;

    if (!intersects) return;

    int x = Math.round((float) intersection.getX());
    int y = Math.round((float) intersection.getY());

    directionRaster = new CenterRaster(x, y, directionImage);
    directionRaster.setRotationAngle(Math.toRadians(bearing));

    markerRaster = new CenterRaster(x, y, markerImage);

    add(markerRaster);
    add(directionRaster);
  }
Example #4
0
  public void actionPerformed(ActionEvent ae) {
    Debug.message("saveimage", "SaveAsImageMenuItem: actionPerformed");

    if (mapHandler == null) {
      Debug.output("SaveAsImageMenuItem: mapHandler = null, returning");
      return;
    }

    MapBean mb = (MapBean) mapHandler.get("com.bbn.openmap.MapBean");

    if (mb != null) {
      Debug.message("saveimage", "MapBean found, creating image");
      try {

        while (true) {
          SaveAsImageFileChooser chooser =
              new SaveAsImageFileChooser(mb.getWidth(), mb.getHeight());

          int returnVal = chooser.showSaveDialog(getParent());
          if (returnVal == JFileChooser.APPROVE_OPTION) {
            String filename = chooser.getSelectedFile().getAbsolutePath();
            if (formatter == null) {
              break;
            }

            filename = checkFileName(filename, formatter.getFormatLabel().toLowerCase());
            if (filename == null) {
              // This is the reason for the while
              // loop, the name didn't really pass
              // muster, so we'll try again.
              continue;
            }

            int imageHeight = chooser.getImageHeight();
            int imageWidth = chooser.getImageWidth();

            byte[] imageBytes = formatter.getImageFromMapBean(mb, imageWidth, imageHeight);
            FileOutputStream binFile = new FileOutputStream(filename);
            binFile.write(imageBytes);
            binFile.close();
            if (Debug.debugging("saveimage")) {
              com.bbn.openmap.proj.Projection proj = mb.getProjection();
              Debug.output(
                  "Created image at "
                      + filename
                      + "where projection covers "
                      + proj.getUpperLeft()
                      + " to "
                      + proj.getLowerRight());
            }
            break;
          } else if (returnVal == JFileChooser.CANCEL_OPTION) {
            break;
          }
        }
      } catch (IOException e) {
        Debug.error("SaveAsImageMenuItem: " + e);
      }
    }
    return;
  }