public OMGraphicList prepare() {
    if (layer != null) {
      // setBuffer(null);
      Projection proj = layer.getProjection();
      if (layer.isProjectionOK(proj)) {
        // set the offsets depending on how much the image moves
        Point2D ul = proj.getUpperLeft();
        if (oldUL != null
            && !oldUL.equals(ul)
            && oldScale == proj.getScale()
            && proj.getClass().equals(oldProjType)) {
          Point2D currentPoint = proj.forward(ul);
          Point2D oldPoint = proj.forward(oldUL);

          offset.setLocation(
              oldPoint.getX() - currentPoint.getX(), oldPoint.getY() - currentPoint.getY());

          layer.repaint();
        }

        oldUL = ul;
        oldProjType = ((Proj) proj).getClass();
        oldScale = proj.getScale();

        OMGraphicList list = layer.prepare();
        setBuffer(createAndPaintImageBuffer(list));

        return list;
      } else {
        logger.warning("NULL projection, can't do anything.");
      }
    } else {
      logger.warning("NULL layer, can't do anything.");
    }
    return null;
  }
  /**
   * 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);
  }
Esempio n. 3
0
  /**
   * Prepare the spline for rendering.
   *
   * @see com.bbn.openmap.omGraphics.OMGeometry#generate(Projection)
   * @param proj Projection
   * @return true if generate was successful
   */
  public boolean generate(Projection proj) {

    setNeedToRegenerate(true);

    if (proj == null) {
      Debug.message("omspline", "OMSpline: null projection in generate!");
      return false;
    }

    NatCubicSpline spline = isGeometryClosed() ? natCubicClosed : natCubic;
    // HACK : should use something else than nsegs
    spline.setSteps(nsegs);

    float[][] splinePoints;

    switch (renderType) {
      case RENDERTYPE_XY:
        if (xs == null) {
          Debug.message("omspline", "OMSpline x/y rendertype null coordinates");
          setNeedToRegenerate(true);
          return false;
        }

        splinePoints = spline.calc(xs, ys);
        xpoints = new float[1][0];
        xpoints[0] = splinePoints[0];
        ypoints = new float[1][0];
        ypoints[0] = splinePoints[1];

        break;

      case RENDERTYPE_OFFSET:
        if (xs == null) {
          Debug.message("omspline", "OMSpline offset rendertype null coordinates");
          setNeedToRegenerate(true);
          return false;
        }

        int npts = xs.length;
        float[] _x = new float[npts];
        float[] _y = new float[npts];

        // forward project the radian point
        Point origin = new Point();
        if (proj instanceof GeoProj) {
          ((GeoProj) proj).forward(lat, lon, origin, true); // radians
        } else {
          proj.forward(Math.toDegrees(lat), Math.toDegrees(lon), origin);
        }

        if (coordMode == COORDMODE_ORIGIN) {
          for (int i = 0; i < npts; i++) {
            _x[i] = (float) (xs[i] + origin.getX());
            _y[i] = (float) (ys[i] + origin.getY());
          }
        } else { // CModePrevious offset deltas
          _x[0] = xs[0] + origin.x;
          _y[0] = ys[0] + origin.y;

          for (int i = 1; i < npts; i++) {
            _x[i] = xs[i] + _x[i - 1];
            _y[i] = ys[i] + _y[i - 1];
          }
        }

        splinePoints = spline.calc(_x, _y);

        xpoints = new float[1][0];
        xpoints[0] = splinePoints[0];
        ypoints = new float[1][0];
        ypoints[0] = splinePoints[1];

        break;

      case RENDERTYPE_LATLON:
        if (rawllpts == null) {
          Debug.message("omspline", "OMSpline latlon rendertype null coordinates");
          setNeedToRegenerate(true);
          return false;
        }

        // spline creation ; precision 1e-8 rad = 0.002"
        double[] splinellpts = spline.calc(rawllpts, 1e-8f);

        // polygon/polyline project the polygon/polyline.
        // Vertices should already be in radians.
        ArrayList<float[]> vector;
        if (proj instanceof GeoProj) {
          vector = ((GeoProj) proj).forwardPoly(splinellpts, lineType, nsegs, isPolygon);
        } else {
          vector = proj.forwardPoly(rawllpts, isPolygon);
        }
        int size = vector.size();

        xpoints = new float[(int) (size / 2)][0];
        ypoints = new float[xpoints.length][0];

        for (int i = 0, j = 0; i < size; i += 2, j++) {
          xpoints[j] = vector.get(i);
          ypoints[j] = vector.get(i + 1);
        }

        if (!doShapes && size > 1) {
          setNeedToRegenerate(false);
          initLabelingDuringGenerate();
          setLabelLocation(xpoints[0], ypoints[0]);
          return true;
        }

        break;

      case RENDERTYPE_UNKNOWN:
        Debug.error("OMSpline.generate: invalid RenderType");
        return false;
    }

    setNeedToRegenerate(false);
    setShape(createShape());
    setLabelLocation(getShape(), proj);
    return true;
  }
Esempio n. 4
0
  /**
   * Since the image doesn't necessarily need to be regenerated when it is merely moved, raster
   * objects have this function, called from generate() and when a placement attribute is changed.
   *
   * @return true if enough information is in the object for proper placement.
   * @param proj projection of window.
   */
  protected boolean position(Projection proj) {

    if (proj == null) {
      logger.fine("OMRasterObject: null projection in position!");
      return false;
    }

    projWidth = proj.getWidth();
    projHeight = proj.getHeight();

    switch (renderType) {
      case RENDERTYPE_LATLON:
        if (!proj.isPlotable(lat, lon)) {
          if (DEBUG) {
            logger.fine("OMRasterObject: point is not plotable!");
          }
          setNeedToReposition(true); // so we don't render it!
          return false;
        }
        point1 = (Point) proj.forward(lat, lon, new Point());
        break;
      case RENDERTYPE_XY:
        point1 = new Point(x, y);
        break;
      case RENDERTYPE_OFFSET:
        if (!proj.isPlotable(lat, lon)) {
          if (DEBUG) {
            logger.fine("OMRasterObject: point is not plotable!");
          }
          setNeedToReposition(true); // so we don't render it!
          return false;
        }
        point1 = (Point) proj.forward(lat, lon, new Point());
        point1.x += x;
        point1.y += y;
        break;
      case RENDERTYPE_UNKNOWN:
        if (DEBUG) {
          logger.fine("OMRasterObject.position(): ignoring unknown rendertype, wingin' it");
        }
        if (lat == 0 && lon == 0) {
          if (x == 0 && y == 0) {
            if (DEBUG) {
              logger.fine(
                  "OMRasterObject.position(): Not enough info in object to place it reasonably.");
            }
            point1 = new Point(-width, -height);
            point2 = new Point(0, 0);
            return false;
          } else {
            point1 = new Point(x, y);
          }

        } else {
          if (!proj.isPlotable(lat, lon)) {
            logger.fine("OMRasterObject: point is not plotable!");
            return false;
          }
          point1 = (Point) proj.forward(lat, lon, new Point());
        }
        break;
    }

    point2 = new Point(0, 0);
    point2.x = point1.x + width;
    point2.y = point1.y + height;
    setNeedToReposition(false);
    return true;
  }