protected void showAnnotationPanel(String annoText) {
    String text = this.splitLines(annoText);

    AnnotationAttributes attrs = this.getAnnotationPanelAttributes(text);
    int yOffset =
        Math.min(this.controller.getWWPanel().getSize().height - attrs.getSize().height, 250);
    Point location = new Point(10 + attrs.getSize().width / 2, yOffset);

    if (this.annotationPanel != null)
      this.annotationPanel.setAttributes(this.getAnnotationPanelAttributes(text));
    else
      this.annotationPanel =
          new ScreenAnnotation(annoText, location, getAnnotationPanelAttributes(text));

    this.annotationPanel.setScreenPoint(location);
    this.annotationPanel.setText(text);

    if (this.annotationLayer == null) {
      this.annotationLayer = new AnnotationLayer();
      this.annotationLayer.setPickEnabled(false);
    }

    this.annotationLayer.removeAllAnnotations();
    this.annotationLayer.addAnnotation(this.annotationPanel);
    if (!this.controller.getActiveLayers().contains(this.annotationLayer))
      this.controller.addInternalLayer(this.annotationLayer);
  }
  /**
   * @param placeNameServiceSet the set of PlaceNameService objects that PlaceNameLayer will render.
   * @throws IllegalArgumentException if {@link
   *     gov.nasa.worldwind.layers.placename.PlaceNameServiceSet} is null
   */
  public PlaceNameLayer(PlaceNameServiceSet placeNameServiceSet) {
    if (placeNameServiceSet == null) {
      String message = Logging.getMessage("nullValue.PlaceNameServiceSetIsNull");
      Logging.logger().fine(message);
      throw new IllegalArgumentException(message);
    }

    //
    this.placeNameServiceSet = placeNameServiceSet.deepCopy();
    for (int i = 0; i < this.placeNameServiceSet.getServiceCount(); i++) {
      // todo do this for long as well and pick min
      int calc1 =
          (int)
              (PlaceNameService.TILING_SECTOR.getDeltaLatDegrees()
                  / this.placeNameServiceSet
                      .getService(i)
                      .getTileDelta()
                      .getLatitude()
                      .getDegrees());
      int numLevels = (int) Math.log(calc1);
      navTiles.add(
          new NavigationTile(
              this.placeNameServiceSet.getService(i),
              PlaceNameService.TILING_SECTOR,
              numLevels,
              "top"));
    }

    if (!WorldWind.getMemoryCacheSet().containsCache(Tile.class.getName())) {
      long size = Configuration.getLongValue(AVKey.PLACENAME_LAYER_CACHE_SIZE, 2000000L);
      MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size);
      cache.setName("Placename Tiles");
      WorldWind.getMemoryCacheSet().addCache(Tile.class.getName(), cache);
    }
  }
  /**
   * Determine the panel size needed to display the full annotation.
   *
   * @param annoText the annotation text.
   * @return the required panel size.
   */
  protected Dimension computePanelSize(String annoText) {
    Dimension lengths = this.computeLengths(annoText);

    // The numbers used below are the average width of a character and average height of a line in
    // Arial-Plain-12.
    int width = 7 * Math.min(lengths.width, this.maxLineLength);
    int height = lengths.height * 17;

    return new Dimension(width, height);
  }
  /**
   * Format a terrain height value acording to the current configuration and append a new-line
   * character.
   *
   * <p>The value is formatted using the current {@link #LABEL_TERRAIN_HEIGHT}, {@link
   * #FORMAT_TERRAIN_HEIGHT} and length units symbol. The default terrain height format is " (ve
   * %3.1f): %,6d %s", where the %3.1f specifier stands for the vertical exaggeration, the %,6d
   * specifer stands for the terrain height, and the %s specifier stands for the units symbol.
   *
   * <p>Note: While the <code>FORMAT_TERRAIN_HEIGHT</code> string may be specified by the
   * application, the terrain height components are always passed to the internal formatter in the
   * order: vertical exaggeration, terrain height, units symbol.
   *
   * @param metersElevation the terrain height in meters.
   * @param verticalExaggeration the vertical exaggeration to apply to the terrain height.
   * @return the formatted terrain height ending with a new-line character.
   */
  public String terrainHeight(double metersElevation, double verticalExaggeration) {
    double multiplier;
    String symbol;

    if (this.getLengthUnitsSystem().equals(UnitsFormat.METRIC_SYSTEM)) {
      multiplier = 1d;
      symbol = UnitsFormat.SYMBOL_METERS;
    } else {
      multiplier = WWMath.METERS_TO_FEET;
      symbol = UnitsFormat.SYMBOL_FEET;
    }

    return String.format(
        this.getLabel(LABEL_TERRAIN_HEIGHT) + " (ve %3.1f): %,6d %s",
        verticalExaggeration,
        (int) Math.round((metersElevation / verticalExaggeration) * multiplier),
        symbol);
  }
 /**
  * Format an eye altitude according to the current eye altitude format.
  *
  * <p>The value is formatted using the current {@link #LABEL_EYE_ALTITUDE}, {@link
  * #FORMAT_EYE_ALTITUDE} and length format.
  *
  * @param metersAltitude the eye altitude to format, in meters.
  * @return a string containing the formatted eye altitude.
  */
 public String eyeAltitude(double metersAltitude) {
   return String.format(
       this.getLabel(LABEL_EYE_ALTITUDE) + this.getFormat(FORMAT_EYE_ALTITUDE),
       (int) Math.round(metersAltitude * this.getLengthUnitsMultiplier()),
       this.getLengthUnitsSymbol());
 }
Exemplo n.º 6
0
  protected void doDrawOnTo(BufferedImageRaster canvas) {
    Sector sector = this.getSector();
    if (null == sector) {
      String message = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (!sector.intersects(canvas.getSector())) {
      return;
    }

    java.awt.Graphics2D g2d = null;
    java.awt.Shape prevClip = null;
    java.awt.Composite prevComposite = null;
    java.lang.Object prevInterpolation = null, prevAntialiasing = null;

    try {
      int canvasWidth = canvas.getWidth();
      int canvasHeight = canvas.getHeight();

      // Apply the transform that correctly maps the image onto the canvas.
      java.awt.geom.AffineTransform transform =
          this.computeSourceToDestTransform(
              this.getWidth(),
              this.getHeight(),
              this.getSector(),
              canvasWidth,
              canvasHeight,
              canvas.getSector());

      AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
      Rectangle2D rect = op.getBounds2D(this.getBufferedImage());

      int clipWidth =
          (int) Math.ceil((rect.getMaxX() >= canvasWidth) ? canvasWidth : rect.getMaxX());
      int clipHeight =
          (int) Math.ceil((rect.getMaxY() >= canvasHeight) ? canvasHeight : rect.getMaxY());

      if (clipWidth <= 0 || clipHeight <= 0) {
        return;
      }

      g2d = canvas.getGraphics();

      prevClip = g2d.getClip();
      prevComposite = g2d.getComposite();
      prevInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
      prevAntialiasing = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);

      // Set the alpha composite for appropriate alpha blending.
      g2d.setComposite(java.awt.AlphaComposite.SrcOver);
      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g2d.drawImage(this.getBufferedImage(), transform, null);
    }
    //        catch (java.awt.image.ImagingOpException ioe)
    //        {
    //            // If we catch a ImagingOpException, then the transformed image has a width or
    // height of 0.
    //            // This indicates that there is no intersection between the source image and the
    // canvas,
    //            // or the intersection is smaller than one pixel.
    //        }
    //        catch (java.awt.image.RasterFormatException rfe)
    //        {
    //            // If we catch a RasterFormatException, then the transformed image has a width or
    // height of 0.
    //            // This indicates that there is no intersection between the source image and the
    // canvas,
    //            // or the intersection is smaller than one pixel.
    //        }
    catch (Throwable t) {
      String reason = WWUtil.extractExceptionReason(t);
      Logging.logger().log(java.util.logging.Level.SEVERE, reason, t);
    } finally {
      // Restore the previous clip, composite, and transform.
      try {
        if (null != g2d) {
          if (null != prevClip) g2d.setClip(prevClip);

          if (null != prevComposite) g2d.setComposite(prevComposite);

          if (null != prevInterpolation)
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, prevInterpolation);

          if (null != prevAntialiasing)
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, prevAntialiasing);
        }
      } catch (Throwable t) {
        Logging.logger().log(java.util.logging.Level.FINEST, WWUtil.extractExceptionReason(t), t);
      }
    }
  }