@SuppressWarnings("rawtypes")
  public void createText(
      final CoverageTable c,
      final TextTable texttable,
      final Vector textvec,
      final float latitude,
      final float longitude,
      final String text,
      final String featureType) {
    counter++;

    // get the colour
    final java.awt.Color res = getColor(featureType);

    // set the colour
    _myCanvas.setColor(res);

    // find the screen location
    _workingLocation.setLat(latitude);
    _workingLocation.setLong(longitude);
    final java.awt.Point pt = _myCanvas.toScreen(_workingLocation);

    // and plot it
    _myCanvas.drawText(text, pt.x, pt.y);
  }
  @SuppressWarnings("rawtypes")
  public void createText(
      final CoverageTable c,
      final TextTable texttable,
      final Vector textvec,
      final float latitude,
      final float longitude,
      final String text) {

    // is the current painter interested in text?
    if (_drawText != null) {
      final boolean res = _drawText.booleanValue();
      if (!res) return;
    } else {
      // hey the client hasn't set a preference, so lets just paint anyway
    }

    // set the colour
    _myCanvas.setColor(getColor(null));

    // find the screen location
    _workingLocation.setLat(latitude);
    _workingLocation.setLong(longitude);

    counter++;

    // convert to screen coordinates
    final java.awt.Point pt = _myCanvas.toScreen(_workingLocation);

    // and plot it
    _myCanvas.drawText(text, pt.x, pt.y);
  }
  /**
   * look through the list of coordinate, and see if any are contained within the currently visible
   * area
   */
  private boolean isVisible(
      final LatLonPoint tl, final LatLonPoint br, final CoordFloatString coords) {
    boolean res = false;
    final MWC.GenericData.WorldLocation _tl =
        new MWC.GenericData.WorldLocation(tl.getLatitude(), tl.getLongitude(), 0);
    final MWC.GenericData.WorldLocation _br =
        new MWC.GenericData.WorldLocation(br.getLatitude(), br.getLongitude(), 0);
    final MWC.GenericData.WorldArea area = new MWC.GenericData.WorldArea(_tl, _br);
    area.normalise();

    for (int i = 0; i < coords.maxIndex(); i++) {
      final float x = coords.getXasFloat(i);
      final float y = coords.getYasFloat(i);

      _workingLocation.setLat(y);
      _workingLocation.setLong(x);

      if (area.contains(_workingLocation)) {
        res = true;
        continue;
      }
    }

    return res;
  }
  /** method to convert multiple polylines into a single area */
  @SuppressWarnings("rawtypes")
  private java.awt.Polygon extendArea(
      final Vector ipts,
      final int totalSize,
      final LatLonPoint ll1,
      final LatLonPoint ll2,
      final float dpplat,
      final float dpplon,
      final boolean doAntarcticaWorkaround,
      final MWC.Algorithms.PlainProjection proj) {
    Polygon res = null;

    int i, j;
    final int size = ipts.size();
    int npts = 0;

    // create the output arrays
    final int[] xlpts = new int[totalSize];
    final int[] ylpts = new int[totalSize];

    boolean antarcticaWorkaround = doAntarcticaWorkaround;
    // only do it if we're in the vicinity
    if (antarcticaWorkaround) {
      antarcticaWorkaround = (ll2.getLatitude() < -62f);
    }

    // step through the areas we've been provided
    for (j = 0; j < size; j++) {
      final CoordFloatString cfs = (CoordFloatString) ipts.elementAt(j);
      int cfscnt = cfs.tcount;
      final int cfssz = cfs.tsize;
      final float cfsvals[] = cfs.vals;
      // see if this line is going clockwise or anti-clockwise
      if (cfscnt > 0) { // normal
        for (i = 0; i < cfscnt; i++) {
          _workingLocation.setLat(cfsvals[i * cfssz + 1]);
          _workingLocation.setLong(cfsvals[i * cfssz]);
          final java.awt.Point pt = proj.toScreen(_workingLocation);
          xlpts[npts] = pt.x;
          ylpts[npts++] = pt.y;
          // res.addPoint(pt.x, pt.y);
        }
      } else { // reverse
        cfscnt *= -1;
        for (i = cfscnt - 1; i >= 0; i--) {
          _workingLocation.setLat(cfsvals[i * cfssz + 1]);
          _workingLocation.setLong(cfsvals[i * cfssz]);
          final java.awt.Point pt = proj.toScreen(_workingLocation);
          xlpts[npts] = pt.x;
          ylpts[npts++] = pt.y;
          // res.addPoint(pt.x, pt.y);
        }
      }
    }

    // pop the data into a polygon (just for tidy storage really)
    res = new java.awt.Polygon(xlpts, ylpts, npts);
    return res;
  }
  /**
   * Edge painter. In this implementation we build the edges up into a polygon which we then plot -
   * this works much more quickly and is an option because we get the edges in the correctly tiled
   * order.
   *
   * @param c parameter for createEdge
   * @param edgevec parameter for createEdge
   * @param ll2 parameter for createEdge
   * @param dpplon parameter for createEdge
   * @param coords list of coordinates which make up this edge
   * @param featureType the type for this feature
   */
  @SuppressWarnings("rawtypes")
  public void createEdge(
      final CoverageTable c,
      final EdgeTable edgetable,
      final Vector edgevec,
      final LatLonPoint ll1,
      final LatLonPoint ll2,
      final float dpplat,
      final float dpplon,
      final CoordFloatString coords,
      final String featureType) {

    // get this feature painter
    final FeaturePainter fp = _currentFeatures.get(featureType);

    // is this feature currently visible?
    if (!fp.getVisible()) return;

    // is this line currently visible?
    if (!isVisible(ll1, ll2, coords)) return;

    // get the colour
    final java.awt.Color res = fp.getColor();

    if (res == null) {
      System.out.println(" not painting!");
      return;
    }

    // set the colour
    _myCanvas.setColor(res);

    // now plot the polygon
    final int len = coords.maxIndex();
    final int[] points = new int[len * 2];

    counter++;

    try {
      for (int i = 0; i < len; i++) {
        final float x = coords.getXasFloat(i);
        final float y = coords.getYasFloat(i);

        _workingLocation.setLat(y);
        _workingLocation.setLong(x);
        final java.awt.Point pt = _myCanvas.toScreen(_workingLocation);

        points[i * 2] = pt.x;
        points[i * 2 + 1] = pt.y;
      }

      // finally plot the polygon
      _myCanvas.drawPolyline(points);
    } catch (final Exception E) {
      E.printStackTrace();
    }
  }
  /**
   * edge plotter for when we're not plotting by features this is really only used for coastlines -
   * which aren't tiled. We can't build up the coastline into a single large polyline, since it
   * jumps around a little!
   */
  @SuppressWarnings("rawtypes")
  public void createEdge(
      final CoverageTable c,
      final EdgeTable edgetable,
      final Vector edgevec,
      final LatLonPoint ll1,
      final LatLonPoint ll2,
      final float dpplat,
      final float dpplon,
      final CoordFloatString coords) {

    // is the current painter interested in text?
    if (_drawLines != null) {
      final boolean res = _drawLines.booleanValue();
      if (!res) return;
    } else {
      // hey the client hasn't set a preference, so lets just paint anyway
    }

    // is this line currently visible?
    if (!isVisible(ll1, ll2, coords)) return;

    // get the colour
    final java.awt.Color res = getColor(null);

    // set the colour
    _myCanvas.setColor(res);

    // now plot the polygon
    final int len = coords.maxIndex();
    java.awt.Point _lastPoint = null;

    // create working location
    try {
      for (int i = 0; i < len; i++) {
        final float x = coords.getXasFloat(i);
        final float y = coords.getYasFloat(i);

        _workingLocation.setLat(y);
        _workingLocation.setLong(x);
        final java.awt.Point pt = _myCanvas.toScreen(_workingLocation);

        // xpoints[i] = pt.x;
        // ypoints[i] = pt.y;
        if (_lastPoint != null) {
          _myCanvas.drawLine(_lastPoint.x, _lastPoint.y, pt.x, pt.y);
        }

        _lastPoint = new java.awt.Point(pt);
      }

      // finally plot the polygon
      // _myCanvas.drawPolygon(xpoints, ypoints, len);
    } catch (final Exception E) {
      E.printStackTrace();
    }
  }
Beispiel #7
0
    @Override
    public final void setUp() {
      // set the earth model we are expecting
      MWC.GenericData.WorldLocation.setModel(new MWC.Algorithms.EarthModels.FlatEarth());

      w1 = new WorldLocation(12.3, 12.4, 12.5);
      w2 = new WorldLocation(12.3, 12.4, 12.5);
      wv1 = new WorldVector(0, 1, 0);
      w4 = new WorldLocation(13.3, 12.4, 12.5);
      w5 = new WorldLocation(12.225, 12.275, 12.5);
    }