Ejemplo n.º 1
0
  /**
   * Draw labels for picking.
   *
   * @param dc Current draw context.
   * @param pickSupport the PickSupport instance to be used.
   */
  protected void doPick(DrawContext dc, PickSupport pickSupport) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    boolean matrixPushed = false;
    try {
      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      for (int i = 0; i < this.lines.length; i++) {
        Rectangle2D bounds = this.lineBounds[i];
        double width = bounds.getWidth();
        double height = bounds.getHeight();

        x = this.screenPoint.x;
        if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0);
        else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width;
        y -= this.lineHeight;

        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false);
        pickSupport.addPickableObject(po);

        // Draw line rectangle
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());

        try {
          gl.glBegin(GL.GL_POLYGON);
          gl.glVertex3d(x, y, 0);
          gl.glVertex3d(x + width - 1, y, 0);
          gl.glVertex3d(x + width - 1, y + height - 1, 0);
          gl.glVertex3d(x, y + height - 1, 0);
          gl.glVertex3d(x, y, 0);
        } finally {
          gl.glEnd();
        }

        y -= this.lineSpacing;
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
Ejemplo n.º 2
0
  protected Angle computeIconRadius(DrawContext dc, double regionPixelSize, Sector drawSector) {
    double minCosLat =
        Math.min(drawSector.getMinLatitude().cos(), drawSector.getMaxLatitude().cos());
    if (minCosLat < 0.001) return Angle.POS180;

    Rectangle2D iconDimension = this.computeDrawDimension(regionPixelSize); // Meter
    double dLat = iconDimension.getHeight() / dc.getGlobe().getRadius();
    double dLon = iconDimension.getWidth() / dc.getGlobe().getRadius() / minCosLat;
    return Angle.fromRadians(Math.sqrt(dLat * dLat + dLon * dLon) / 2);
  }
Ejemplo n.º 3
0
  protected List<Sector> computeSectors(DrawContext dc) {
    if (this.locations == null || !this.locations.iterator().hasNext()) return null;

    // Compute all locations bounding sector, then add some padding for the icon half diagonal
    // extent
    Sector sector = Sector.boundingSector(this.locations);
    // Compute padding
    double minCosLat = Math.min(sector.getMinLatitude().cos(), sector.getMaxLatitude().cos());
    minCosLat = Math.max(minCosLat, .01); // avoids division by zero at the poles
    Rectangle2D iconDimension = this.computeDrawDimension(dc, sector.getCentroid());
    double diagonalLength =
        Math.sqrt(
            iconDimension.getWidth() * iconDimension.getWidth()
                + iconDimension.getHeight() * iconDimension.getHeight());
    double padLatRadians = diagonalLength / 2 / dc.getGlobe().getRadius();
    double padLonRadians = diagonalLength / 2 / dc.getGlobe().getRadius() / minCosLat;
    // Apply padding to sector
    Angle minLat = sector.getMinLatitude().subtractRadians(padLatRadians);
    Angle maxLat = sector.getMaxLatitude().addRadians(padLatRadians);
    Angle minLon = sector.getMinLongitude().subtractRadians(padLonRadians);
    Angle maxLon = sector.getMaxLongitude().addRadians(padLatRadians);

    return this.computeNormalizedSectors(new Sector(minLat, maxLat, minLon, maxLon));
  }