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

📄 iconrenderer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2006 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.render;import com.sun.opengl.util.texture.*;import gov.nasa.worldwind.Locatable;import gov.nasa.worldwind.exception.WWRuntimeException;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.layers.Layer;import gov.nasa.worldwind.pick.PickSupport;import gov.nasa.worldwind.terrain.SectorGeometryList;import gov.nasa.worldwind.util.Logging;import javax.media.opengl.GL;import java.awt.*;import java.awt.image.*;import java.util.Iterator;import java.util.logging.Level;/** * @author tag * @version $Id: IconRenderer.java 10925 2009-05-06 22:22:50Z dcollins $ */public class IconRenderer{    private Pedestal pedestal;    private PickSupport pickSupport = new PickSupport();    private boolean horizonClippingEnabled = false;    private boolean viewClippingEnabled = false;    private boolean alwaysUseAbsoluteElevation = false;    public IconRenderer()    {    }    public Pedestal getPedestal()    {        return pedestal;    }    public void setPedestal(Pedestal pedestal)    {        this.pedestal = pedestal;    }    /**     * Indicates whether horizon clipping is performed.     *     * @return <code>true</code> if horizon clipping is performed, otherwise <code>false</code>.     *     * @see #setHorizonClippingEnabled(boolean)     */    public boolean isHorizonClippingEnabled()    {        return horizonClippingEnabled;    }    /**     * Indicates whether to render icons beyond the horizon. If view culling is enabled, the icon is also tested for     * view volume inclusion. The default is <code>false</code>, horizon clipping is not performed.     *     * @param horizonClippingEnabled <code>true</code> if horizon clipping should be performed, otherwise     *                               <code>false</code>.     *     * @see #setViewClippingEnabled(boolean)     */    public void setHorizonClippingEnabled(boolean horizonClippingEnabled)    {        this.horizonClippingEnabled = horizonClippingEnabled;    }    /**     * Indicates whether view volume clipping is performed.     *     * @return <code>true</code> if view volume clipping is performed, otherwise <code>false</code>.     *     * @see #setViewClippingEnabled(boolean)     */    public boolean isViewClippingEnabled()    {        return viewClippingEnabled;    }    /**     * Indicates whether to render icons outside the view volume. This is primarily to control icon visibility beyond     * the far view clipping plane. Some important use cases demand that clipping not be performed. If horizon clipping     * is enabled, the icon is also tested for horizon clipping. The default is <code>false</code>, view volume clipping     * is not performed.     *     * @param viewClippingEnabled <code>true</code> if view clipping should be performed, otherwise <code>false</code>.     *     * @see #setHorizonClippingEnabled(boolean)     */    public void setViewClippingEnabled(boolean viewClippingEnabled)    {        this.viewClippingEnabled = viewClippingEnabled;    }    private static boolean isIconValid(WWIcon icon, boolean checkPosition)    {        if (icon == null || icon.getImageSource() == null)            return false;        //noinspection RedundantIfStatement        if (checkPosition && icon.getPosition() == null)            return false;        return true;    }    /**     * Indicates whether an icon's elevation is treated as an offset from the terrain or an absolute elevation above sea     * level.     *     * @return <code>true</code> if icon elevations are treated as absolute, <code>false</code> if they're treated as     *         offsets from the terrain.     */    public boolean isAlwaysUseAbsoluteElevation()    {        return alwaysUseAbsoluteElevation;    }    /**     * Normally, an icon's elevation is treated as an offset from the terrain when it is less than the globe's maximum     * elevation. Setting #setAlwaysUseAbsoluteElevation to <code>true</code> causes the elevation to be treated as an     * absolute elevation above sea level.     *     * @param alwaysUseAbsoluteElevation <code>true</code> to treat icon elevations as absolute, <code>false</code> to     *                                   treat them as offsets from the terrain.     */    public void setAlwaysUseAbsoluteElevation(boolean alwaysUseAbsoluteElevation)    {        this.alwaysUseAbsoluteElevation = alwaysUseAbsoluteElevation;    }    @SuppressWarnings({"UnusedDeclaration"})    public void pick(DrawContext dc, Iterable<WWIcon> icons, java.awt.Point pickPoint, Layer layer)    {        this.drawMany(dc, icons, layer);    }    @SuppressWarnings({"UnusedDeclaration"})    /**     * @deprecated     */    public void pick(DrawContext dc, WWIcon icon, Vec4 iconPoint, java.awt.Point pickPoint, Layer layer) // TODO: Remove    {        if (!isIconValid(icon, false))            return;        //noinspection deprecation        this.drawOne(dc, icon, iconPoint, layer);    }    public void render(DrawContext dc, Iterable<WWIcon> icons)    {        this.drawMany(dc, icons, null);    }    public void render(DrawContext dc, WWIcon icon, Vec4 iconPoint)    {        if (!isIconValid(icon, false))            return;        //noinspection deprecation        this.drawOne(dc, icon, iconPoint, null);    }    private void drawMany(DrawContext dc, Iterable<WWIcon> icons, Layer layer)    {        if (dc == null)        {            String msg = Logging.getMessage("nullValue.DrawContextIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (dc.getVisibleSector() == null)            return;        SectorGeometryList geos = dc.getSurfaceGeometry();        //noinspection RedundantIfStatement        if (geos == null)            return;        if (icons == null)        {            String msg = Logging.getMessage("nullValue.IconIterator");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        Iterator<WWIcon> iterator = icons.iterator();        if (!iterator.hasNext())            return;        double horizon = dc.getView().computeHorizonDistance();        while (iterator.hasNext())        {            WWIcon icon = iterator.next();            if (!isIconValid(icon, true))                continue;            if (!icon.isVisible())                continue;            // Determine Cartesian position from the surface geometry if the icon is near the surface,            // otherwise draw it from the globe.            Position pos = icon.getPosition();            Vec4 iconPoint = null;            if (pos.getElevation() < dc.getGlobe().getMaxElevation() && !this.isAlwaysUseAbsoluteElevation())                iconPoint = dc.getSurfaceGeometry().getSurfacePoint(icon.getPosition());            if (iconPoint == null)                iconPoint = dc.getGlobe().computePointFromPosition(icon.getPosition());            double eyeDistance = icon.isAlwaysOnTop() ? 0 : dc.getView().getEyePoint().distanceTo3(iconPoint);            if (this.isHorizonClippingEnabled() && eyeDistance > horizon)                continue; // don't render horizon-clipped icons            // If enabled, eliminate icons outside the view volume. Primarily used to control icon visibility beyond            // the view volume's far clipping plane.            if (this.isViewClippingEnabled() && !dc.getView().getFrustumInModelCoordinates().contains(iconPoint))                continue;            // The icons aren't drawn here, but added to the ordered queue to be drawn back-to-front.            dc.addOrderedRenderable(new OrderedIcon(icon, iconPoint, layer, eyeDistance, horizon));            if (icon.isShowToolTip())                this.addToolTip(dc, icon, iconPoint);        }    }    /** @deprecated  */    @SuppressWarnings({"JavaDoc"})    private void drawOne(DrawContext dc, WWIcon icon, Vec4 iconPoint, Layer layer) // TODO: Remove method    {        if (dc == null)        {            String msg = Logging.getMessage("nullValue.DrawContextIsNull");            Logging.logger().severe(msg);            throw new IllegalArgumentException(msg);        }        if (dc.getVisibleSector() == null)            return;        SectorGeometryList geos = dc.getSurfaceGeometry();        //noinspection RedundantIfStatement        if (geos == null)            return;        if (!icon.isVisible())            return;        if (iconPoint == null)        {            Angle lat = icon.getPosition().getLatitude();            Angle lon = icon.getPosition().getLongitude();            if (!dc.getVisibleSector().contains(lat, lon))                return;            iconPoint = dc.getSurfaceGeometry().getSurfacePoint(lat, lon, icon.getPosition().getElevation());            if (iconPoint == null)                return;        }        double horizon = dc.getView().computeHorizonDistance();        double eyeDistance = icon.isAlwaysOnTop() ? 0 : dc.getView().getEyePoint().distanceTo3(iconPoint);        if (this.isHorizonClippingEnabled() && eyeDistance > horizon)            return; // don't render horizon-clipped icons        // If enabled, eliminate icons outside the view volume. Primarily used to control icon visibility beyond        // the view volume's far clipping plane.        if (this.isViewClippingEnabled() && !dc.getView().getFrustumInModelCoordinates().contains(iconPoint))            return;        // The icon isn't drawn here, but added to the ordered queue to be drawn back-to-front.        dc.addOrderedRenderable(new OrderedIcon(icon, iconPoint, layer, eyeDistance, horizon));        if (icon.isShowToolTip())            this.addToolTip(dc, icon, iconPoint);    }    private void addToolTip(DrawContext dc, WWIcon icon, Vec4 iconPoint)    {        if (icon.getToolTipFont() == null && icon.getToolTipText() == null)            return;        final Vec4 screenPoint = dc.getView().project(iconPoint);        if (screenPoint == null)            return;        OrderedText tip = new OrderedText(icon.getToolTipText(), icon.getToolTipFont(), screenPoint,            icon.getToolTipTextColor(), 0d);        dc.addOrderedRenderable(tip);    }    private class OrderedText implements OrderedRenderable    {        Font font;        String text;        Vec4 point;        double eyeDistance;        java.awt.Point pickPoint;        Layer layer;        java.awt.Color color;        OrderedText(String text, Font font, Vec4 point, java.awt.Color color, double eyeDistance)        {            this.text = text;            this.font = font;            this.point = point;            this.eyeDistance = eyeDistance;            this.color = color;        }        OrderedText(String text, Font font, Vec4 point, java.awt.Point pickPoint, Layer layer, double eyeDistance)        {            this.text = text;            this.font = font;            this.point = point;            this.eyeDistance = eyeDistance;            this.pickPoint = pickPoint;            this.layer = layer;        }        public double getDistanceFromEye()        {            return this.eyeDistance;        }        public void render(DrawContext dc)        {            ToolTipRenderer toolTipRenderer = this.getToolTipRenderer(dc);            toolTipRenderer.render(dc, this.text, (int) this.point.x, (int) this.point.y);        }        public void pick(DrawContext dc, java.awt.Point pickPoint)        {        }        @SuppressWarnings({"UnusedDeclaration"})        protected ToolTipRenderer getToolTipRenderer(DrawContext dc)        {            ToolTipRenderer tr = (this.font != null) ? new ToolTipRenderer(this.font) : new ToolTipRenderer();            if (this.color != null)            {                tr.setTextColor(this.color);                tr.setOutlineColor(this.color);                tr.setInteriorColor(ToolTipRenderer.getContrastingColor(this.color));            }            else            {                tr.setUseSystemLookAndFeel(true);            }            return tr;        }    }    private class OrderedIcon implements OrderedRenderable, Locatable    {        WWIcon icon;        Vec4 point;        double eyeDistance;        double horizonDistance;        Layer layer;        OrderedIcon(WWIcon icon, Vec4 point, double eyeDistance, double horizonDistance)        {            this.icon = icon;            this.point = point;            this.eyeDistance = eyeDistance;            this.horizonDistance = horizonDistance;        }

⌨️ 快捷键说明

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