コード例 #1
0
  /**
   * 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);
  }
コード例 #2
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;
  }