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

📄 dtedframecachehandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/dataAccess/dted/DTEDFrameCacheHandler.java,v $// $RCSfile: DTEDFrameCacheHandler.java,v $// $Revision: 1.2.2.3 $// $Date: 2006/01/13 22:04:20 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.dataAccess.dted;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.Component;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.ArrayList;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.layer.util.cacheHandler.CacheHandler;import com.bbn.openmap.layer.util.cacheHandler.CacheObject;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMGrid;import com.bbn.openmap.omGraphics.grid.GeneratorLoader;import com.bbn.openmap.omGraphics.grid.OMGridGenerator;import com.bbn.openmap.omGraphics.grid.SinkGenerator;import com.bbn.openmap.proj.EqualArc;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The DTEDFrameCacheHandler is a cache for objects being rendered on * the map as a result of reading in DTED data. It communicates with a * DTEDFrameCache to get OMGrid data from the actual DTED data files, * and then sets OMGridGenerators on those OMGrids to create * representations of the DTED. * <P> *  * The DTEDFrameCacheHandler uses GeneratorLoaders to create * OMGridGenerators for its OMGrids. The GeneratorLoaders provide a * GUI for controlling those OMGridGenerator parameters. The list of * GeneratorLoaders can be set via Properties. In general, properties * being set for a DTEDFrameCacheHandler: * <P> *  * <pre> *    *    *    markerName.generators=greys colors *    markerName.greys.class=com.bbn.openmap.omGraphics.grid.SlopeGeneratorLoader *    markerName.greys.prettyName=Slope Shading *    markerName.greys.colorsClass=com.bbn.openmap.omGraphics.grid.GreyscaleSlopeColors *    markerName.colors.class=com.bbn.openmap.omGraphics.grid.SlopeGeneratorLoader *    markerName.colors.prettyName=Elevation Shading *    markerName.colors.colorsClass=com.bbn.openmap.omGraphics.grid.ColoredShadingColors *    *     * </pre> *  * The only properties that are required for the DTEDFrameCacheHandler * are the generators property, and then the .class properties for the * generator loader class names. All of the other generator loader * properties are sent to the generator loader for interpretation. * <p> *  * The markerName is generally provided by the parent component of the * DTEDFrameCacheHandler, like the DTEDFrameCacheLayer. */public class DTEDFrameCacheHandler extends CacheHandler implements        DTEDConstants, PropertyConsumer, PropertyChangeListener {    public final static String GeneratorLoadersProperty = "generators";    /** The real frame cache. */    protected DTEDFrameCache frameCache;    // Setting up the screen...    protected double frameUp, frameDown, frameLeft, frameRight;    // Returning the images...    protected boolean firstImageReturned = true;    protected double frameLon = 0.0;    protected double frameLat = 0.0;    protected boolean newframe = false;    protected int dtedLevel = LEVEL_0;    /**     * The active GeneratorLoader providing OMGridGenerators to the     * OMGrids.     */    protected GeneratorLoader activeGeneratorLoader = null;    /**     * The list of GeneratorLoaders.     */    protected ArrayList generatorLoaders = new ArrayList();    /**     * The DTEDFrameCache must be set at some point.     */    protected DTEDFrameCacheHandler() {        this(null);    }    /**     * Create a handler for the DTEDFrameCache.     */    public DTEDFrameCacheHandler(DTEDFrameCache dfc) {        setFrameCache(dfc);    }    /**     * Set the DTEDFrameCache.     */    public void setFrameCache(DTEDFrameCache dfc) {        frameCache = dfc;    }    /**     * Get the DTEDFrameCache.     */    public DTEDFrameCache getFrameCache() {        return frameCache;    }    /**     * Get an elevation at a point. Always uses the cache to load the     * frame and get the data. DTED data is in meters.     */    public int getElevation(float lat, float lon) {        if (frameCache != null) {            return frameCache.getElevation(lat, lon);        } else {            return DTEDFrameCache.NO_DATA;        }    }    /**     * Set the DTED level to get from the DTEDFrameCache.     */    public void setDtedLevel(int level) {        dtedLevel = level;    }    /**     * Get the DTED level being retrieved from the DTEDFrameCache.     */    public int getDtedLevel() {        return dtedLevel;    }    /**     * Set the active GeneratorLoader based on a pretty name from one     * of the loaders.     */    public void setActiveGeneratorLoader(String active) {        for (Iterator it = generatorLoaders.iterator(); it.hasNext();) {            GeneratorLoader gl = (GeneratorLoader) it.next();            if (active.equals(gl.getPrettyName())                    && gl != activeGeneratorLoader) {                activeGeneratorLoader = gl;                clear();            }        }    }    /**     * Get a new OMGridGenerator from the active GeneratorLoader.     */    public OMGridGenerator getGenerator() {        if (activeGeneratorLoader != null) {            return activeGeneratorLoader.getGenerator();        } else {            return new SinkGenerator();        }    }    /**     * GUI Panel holding the GeneratorLoader GUIs.     */    final JPanel cards = new JPanel(new CardLayout());    /**     * Get the GUI for the GeneratorLoaders.     */    public Component getGUI() {        JPanel pane = new JPanel(new BorderLayout());        int numLoaders = generatorLoaders.size();        String comboBoxItems[] = new String[numLoaders];        int count = 0;        for (Iterator it = generatorLoaders.iterator(); it.hasNext();) {            GeneratorLoader gl = (GeneratorLoader) it.next();            String prettyName = gl.getPrettyName();            comboBoxItems[count++] = prettyName;            Component glGui = gl.getGUI();            if (glGui == null) {                glGui = new JLabel("No options available.");            }            cards.add(glGui, prettyName);        }        JComboBox cb = new JComboBox(comboBoxItems);        cb.setEditable(false);        cb.addItemListener(new ItemListener() {            public void itemStateChanged(ItemEvent evt) {                CardLayout cl = (CardLayout) (cards.getLayout());                String active = (String) evt.getItem();                cl.show(cards, active);                setActiveGeneratorLoader(active);            }        });        // Put the JComboBox in a JPanel to get a nicer look.        JPanel comboBoxPane = new JPanel(); // use FlowLayout        comboBoxPane.add(cb);        pane.add(comboBoxPane, BorderLayout.NORTH);        pane.add(cards, BorderLayout.CENTER);        return pane;    }    /**     * The call to the cache that lets you choose what kind of     * information is returned. This function also figures out what     * part of the earth is covered on the screen, and creates     * auxillary cache handlers as needed.     *      * @param proj The projection of the screen (CADRG).     * @return List of rasters to display.     */    public OMGraphicList getRectangle(EqualArc proj) {        float[] lat = new float[3];        float[] lon = new float[3];        // This next bit of mumbo jumbo is to handle the equator and        // dateline: Worst case, crossing both, treat each area        // separately, so it is the same as handling four requests for        // data - above and below the equator, and left and right of        // the dateline. Normal case, there is only one box. Two        // boxes if crossing only one of the boundaries.        int xa = 2;        int ya = 2;        int lat_minus = 2;        int lon_minus = 2;        // Set up checks for equator and dateline        LatLonPoint ll1 = proj.getUpperLeft();        LatLonPoint ll2 = proj.getLowerRight();        lat[0] = ll1.getLatitude();        lon[0] = ll1.getLongitude();        lat[1] = ll2.getLatitude();        lon[1] = ll2.getLongitude();        lat[2] = ll2.getLatitude();        lon[2] = ll2.getLongitude();        if (lon[0] > 0 && lon[2] < 0) {            lon[1] = -179.999f; // put a little breather on the            // dateline            lon_minus = 1;        }        if (lat[0] > 0 && lat[2] < 0) {            lat[1] = -0.0001f; // put a little breather on the equator            lat_minus = 1;        }        if (Debug.debugging("dteddetail")) {            Debug.output("For :");            Debug.output("lat[0] " + lat[0]);            Debug.output("lon[0] " + lon[0]);            Debug.output("lat[1] " + lat[1]);            Debug.output("lon[1] " + lon[1]);            Debug.output("lat[2] " + lat[2]);            Debug.output("lon[2] " + lon[2]);            Debug.output("lat_minus = " + lat_minus);            Debug.output("lon_minus = " + lon_minus);        }        /*         * Look at all the paths if needed. Worst case, there are four         * boxes on the screen. Best case, there is one. The things         * that create boxes and dictates how large they are are the         * equator and the dateline. When the screen straddles one or         * both of these lat/lon lines, lon_minus and lat_minus get         * adjusted, causing two or four different calls to the         * tochandler to get the data above/below the equator, and         * left/right of the dateline. Plus, each path gets checked         * until the required boxes are filled.         */        if (Debug.debugging("dted")) {            Debug.output("--- DTEDFrameCacheHandler: getting images: ---");        }        setProjection(proj,                lat[ya - lat_minus],                lon[xa - lon_minus],                lat[ya],                lon[xa]);        OMGraphicList list = loadListFromHandler(null);        // Dateline split        if (lon_minus == 1) {            setProjection(proj, lat[ya - lat_minus], lon[0], lat[ya], -1f                    * lon[1]); // -1 to make it 180            list = loadListFromHandler(list);        }        // Equator Split        if (lat_minus == 1) {            setProjection(proj, lat[0], lon[xa - lon_minus], -1f * lat[1], // flip                    // breather                    lon[xa]);            list = loadListFromHandler(list);        }        // Both!!        if (lon_minus == 1 && lat_minus == 1) {            setProjection(proj, lat[0], lon[0], -1f * lat[1],// flip                    // breather                    -1f * lon[1]);// -1 to make it 180, not -180            list = loadListFromHandler(list);        }        if (Debug.debugging("dted")) {            Debug.output("--- DTEDFrameCacheHandler: finished getting images ---");        }        return list;    }    /**     * Method that pings the cache for images based on the projection     * that has been set on it. If the cache returns null from     * getNextImage(), it's done. Method creates and returns a     * graphics list if the one passed in is null, otherwise it

⌨️ 快捷键说明

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