⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 surfaceicon.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package gov.nasa.worldwind.render;

import com.sun.opengl.util.texture.TextureCoords;
import gov.nasa.worldwind.Movable;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.Globe;
import gov.nasa.worldwind.util.Logging;

import javax.media.opengl.GL;
import java.awt.*;
import java.awt.geom.*;
import java.util.Arrays;

/**
 * Renders an icon image over the terrain surface.
 *
 * @author Patrick Murris
 * @version $Id: SurfaceIcon.java 10409 2009-04-22 18:36:06Z patrickmurris $
 */
public class SurfaceIcon extends AbstractSurfaceRenderable implements Movable
{
    private Object imageSource;
    private LatLon location;
    private Vec4 locationOffset;                    // Pixels
    private double scale = 1d;
    private Angle heading;
    private Color color = Color.WHITE;
    private double maxSize = Double.MAX_VALUE;      // Meter
    private double minSize = .1;                    // Meter

    protected WWTexture texture;
    protected int imageWidth = 32;
    protected int imageHeight = 32;

    public SurfaceIcon(Object imageSource, LatLon location)
    {
        this.setImageSource(imageSource);
        this.setLocation(location);
    }

    /**
     * Get the icon reference location on the globe.
     *
     * @return the icon reference location on the globe.
     */
    public LatLon getLocation()
    {
        return this.location;
    }

    /**
     * Set the icon reference location on the globe.
     *
     * @param location the icon reference location on the globe.
     */
    public void setLocation(LatLon location)
    {
        if (location == null)
        {
            String message = Logging.getMessage("nullValue.LatLonIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        this.location = location;
    }

    /**
     * Get the icon displacement in pixels relative to the reference location.  Can be <code>null</code>.
     * <p>
     * When <code>null</code> the icon will be drawn with it's image center on top of it's refence location -
     * see {@link #setLocation(LatLon)}. Otherwise the icon will be shifted of a distance equivalent to the number
     * of pixels specified as <code>x</code> and <code>y</code> offset values. Positive values will move the icon
     * to the right for <code>x</code> and up for <code>y</code>. Negative values will have the opposite effect.
     *
     * @return the icon displacement in pixels relative to the reference location.
     */
    public Vec4 getLocationOffset()
    {
        return this.locationOffset;
    }

    /**
     * Set the icon displacement in pixels relative to the reference location. Can be <code>null</code>.
     * <p>
     * When <code>null</code> the icon will be drawn with it's image center on top of it's refence location -
     * see {@link #setLocation(LatLon)}. Otherwise the icon will be shifted of a distance equivalent to the number
     * of pixels specified as <code>x</code> and <code>y</code> offset values. Positive values will move the icon
     * to the right for <code>x</code> and up for <code>y</code>. Negative values will have the opposite effect.
     *
     * @param locationOffset the icon displacement in pixels relative to the reference location.
     */
    public void setLocationOffset(Vec4 locationOffset)
    {
        this.locationOffset = locationOffset; // can be null
    }

    /**
     * Get the source for the icon image. Can be a file path to a local image or
     * a {@link java.awt.image.BufferedImage}</code> reference.
     *
     * @return the source for the icon image.
     */
    public Object getImageSource()
    {
        return this.imageSource;
    }

    /**
     * Set the source for the icon image. Can be a file path to a local image or
     * a {@link java.awt.image.BufferedImage}</code> reference.
     *
     * @param imageSource the source for the icon image.
     */
    public void setImageSource(Object imageSource)
    {
        if (imageSource == null)
        {
            String message = Logging.getMessage("nullValue.ImageSourceIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        this.imageSource = imageSource;
        this.texture = null;
    }

    /**
     * Get the current scaling factor applied to the source image.
     * 
     * @return the current scaling factor applied to the source image.
     */
    public double getScale()
    {
        return this.scale;
    }

    /**
     * Set the scaling factor to apply to the source image. A value of <code>1</code> will produce no change,
     * a value greater then <code>1</code> will enlarge the image and a value smaller then <code>1</code> will
     * reduce it.
     *
     * @param scale the scaling factor to apply to the source image.
     */
    public void setScale(double scale)
    {
        this.scale = scale;
    }

    /**
     * Get the current heading {@link Angle}, clockwise from North or <code>null</code>.
     *
     * @return the current heading {@link Angle}, clockwise from North or <code>null</code>.
     */
    public Angle getHeading()
    {
        return this.heading;
    }

    /**
     * Set the heading {@link Angle}, clockwise from North. Setting this value to <code>null</code> will have
     * the icon follow the view heading so as to always face the eye. The icon will rotate around it's reference
     * location.
     *
     * @param heading the heading {@link Angle}, clockwise from North or <code>null</code>.
     */
    public void setHeading(Angle heading)
    {
        this.heading = heading;  // can be null
    }

    /**
     * Get the minimum size in meter the icon image is allowed to be reduced to once applied to the terrain surface.
     * This limit applies to the source image largest dimension.
     * <p>
     * The icon will try to maintain it's apparent size depending on it's distance from the eye and will extend
     * over a rectangular area which largest dimension is bounded by the values provided with
     * {@link #setMinSize(double)} and {@link #setMaxSize(double)}.
     *
     * @return the minimum size of the icon in meter.
     */
    public double getMinSize()
    {
        return this.minSize;
    }

    /**
     * Set the minimum size in meter the icon image is allowed to be reduced to once applied to the terrain surface.
     * This limit applies to the source image largest dimension.
     * <p>
     * The icon will try to maintain it's apparent size depending on it's distance from the eye and will extend
     * over a rectangular area which largest dimension is bounded by the values provided with
     * {@link #setMinSize(double)} and {@link #setMaxSize(double)}.
     *
     * @param sizeInMeter the minimum size of the icon in meter.
     */
    public void setMinSize(double sizeInMeter)
    {
        this.minSize = sizeInMeter;
    }

    /**
     * Get the maximum size in meter the icon image is allowed to be enlarged to once applied to the terrain surface.
     * This limit applies to the source image largest dimension.
     * <p>
     * The icon will try to maintain it's apparent size depending on it's distance from the eye and will extend
     * over a rectangular area which largest dimension is bounded by the values provided with
     * {@link #setMinSize(double)} and {@link #setMaxSize(double)}.
     *
     * @return the maximum size of the icon in meter.
     */
    public double getMaxSize()
    {
        return this.maxSize;
    }

    /**
     * Get the maximum size in meter the icon image is allowed to be enlarged to once applied to the terrain surface.
     * This limit applies to the source image largest dimension.
     * <p>
     * The icon will try to maintain it's apparent size depending on it's distance from the eye and will extend
     * over a rectangular area which largest dimension is bounded by the values provided with
     * {@link #setMinSize(double)} and {@link #setMaxSize(double)}.
     *
     * @param sizeInMeter the maximum size of the icon in meter.
     */
    public void setMaxSize(double sizeInMeter)
    {
        this.maxSize = sizeInMeter;
    }

    /**
     * Get the {@link Color} the source image is combined with.
     *
     * @return the {@link Color} the source image is combined with.
     */
    public Color getColor()
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -