Esempio n. 1
0
  public boolean generate(Projection proj) {
    if (renderType == RENDERTYPE_XY || renderType == RENDERTYPE_OFFSET) {
      return super.generate(proj); // generate using circle's generate
    }
    // RENDERTYPE_LATLON should go in here
    setShape(null);

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

    if (rawllpts == null) {
      rawllpts = createLatLonPoints();
    }

    ArrayList vector = null;

    // polygon/polyline project the polygon/polyline.
    // Vertices should already be in radians.
    vector = proj.forwardPoly(rawllpts, getLineType(), -1, true);
    int size = vector.size();

    // We could call create shape, but this is more efficient.
    int i, j;
    for (i = 0, j = 0; i < size; i += 2, j++) {
      GeneralPath gp = createShape((int[]) vector.get(i), (int[]) vector.get(i + 1), true);

      if (shape == null) {
        setShape(gp);
      } else {
        ((GeneralPath) shape).append(gp, false);
      }
    }

    setNeedToRegenerate(false);
    return true;
  }
Esempio n. 2
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;
  }