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

📄 etopolayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************//// <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/layer/etopo/ETOPOLayer.java,v $// $RCSfile: ETOPOLayer.java,v $// $Revision: 1.5.2.3 $// $Date: 2004/10/14 18:27:06 $// $Author: dietrick $//// **********************************************************************package com.bbn.openmap.layer.etopo;/*  Java Core  */import java.awt.Component;import java.awt.Point;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.FileNotFoundException;import java.io.IOException;/*  OpenMap  */import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.io.BinaryBufferedFile;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.layer.policy.ListResetPCPolicy;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMRaster;import com.bbn.openmap.proj.CADRG;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSlider;import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;/** * ETOPOLayer extends Layer to provide rendering of the ETOPO5 world * elevation data set. The ETOPO5 data consists of terrain altitude * and ocean depth measurements at 5 minute intervals for the entire * globe. Rendering is allowed in any projection that implements the * inverse(int,int) method. Two types of rendering are provided: * grayscale slope-shaded and colored slope-shaded. * <p> * The distribution consists of the following: * <ul> * <li>1. ETOPOLayer.java</li> * <li>2. ETOPO5 (5 minute spacing data set, 4320x2160 shorts, ~18MB) * </li> * <li>3. ETOPO10 (10 minute spacing data set, sampled from ETOPO5, * ~4.6MB)</li> * <li>4. ETOPO15 (15 minute spacing data set, sampled from ETOPO5, * ~2MB)</li> * <li>5. ETOPOLayer.properties (example properties for * openmap.properties)</li> * </ul> * <p> * The sampled ETOPO data sets are provided to speed up the loading of * data to compute the slope shading. The algorithm inverse projects * the x/y screen coords (for the entire projection screen space) to * get the corresponding lat/lon coords then samples the database to * get altitude/depth and slope values. While this method is slower * than the forward projection method, it does provide a more * attractive screen presentation and will support all projections * (not just the equidistant cylindrical). A palette provides the * ability to choose between the 5,10, or 15 minute resolutions, as * well as color or grayscale selection, transparency, and slope * contrast. * <p> * The ETOPOLayer also relies on properties to set its variables, such * as the etopo frame paths (there can be several at a time), the * opaqueness of the frame images, number of colors to use, and some * other display variables. The ETOPOLayer properties look something * like this: * <P> *  * #------------------------------ <BR># Properties for ETOPOLayer * <BR> * #------------------------------ <BR># This property should reflect * the paths to the etopo directory <BR> * etopo.path=c:/openmap/share <BR> * <BR># Number between 0-255: 0 is transparent, 255 is opaque <BR> * etopo.opaque=255 <BR> * <BR># Number of colors to use on the maps - 16, 32, 216 <BR> * etopo.number.colors=216 <BR> * <BR># Type of display for the data <BR># 0 = grayscale slope * shading <BR># 1 = colored slope shading <BR> * etopo.view.type=1 <BR> * <BR># Contrast setting, 1-5 <BR> * etopo.contrast=3 <BR> * <BR># lat/lon spacing in minutes <BR># must be 5, 10, or 15 <BR> * etopo.minute.spacing=10 <BR> * <BR> * #------------------------------------- <BR># End of properties for * ETOPOLayer <BR> * #------------------------------------- <BR> *   */public class ETOPOLayer extends OMGraphicHandlerLayer implements ActionListener {    /** Gray scale slope shading, sun from the Northwest. */    public static final int SLOPESHADING = 0;    /**     * Colorized slope shading. Color basnds are based on elevation,     * and are accented by shaded indications.     */    public static final int COLOREDSHADING = 1;    /** Default contrast setting for slope shading. */    public static final int DEFAULT_SLOPE_ADJUST = 3;    /** Default minute spacing */    public static final int DEFAULT_MINUTE_SPACING = 10;    /** for colorizing */    public final static int DEFAULT_OPAQUENESS = 255;    /**     * The paths to the ETOPO directory, telling where the data is.     */    protected String path;    /** The etopo elevation data */    protected short[] dataBuffer = null;    protected int bufferWidth;    protected int bufferHeight;    /** The current resolution (in minutes) */    protected int minuteSpacing;    /** ETOPO elevation files */    protected final static String[] etopoFileNames = { "/ETOPO2", "/ETOPO5",            "/ETOPO10", "/ETOPO15" }; //ep-g    /** dimensions of the ETOPO files (don't mess with these!) */    protected final static int[] etopoWidths = { 10800, 4320, 2160, 1440 };//ep-g    protected final static int[] etopoHeights = { 5400, 2160, 1080, 720 }; //ep-g    /**     * Spacings (in meters) between adjacent lon points at the     * equater. The values here were aesthetically defined (they are     * not the actual spacings)     */    protected final static double[] etopoSpacings = { 1800., 3500., 7000.,            10500. }; //ep-g    /**     * The display type for the etopo images. Slope shading is     * grayscale terrain modeling with highlights and shading, with     * the 'sun' being in the NorthWest. Colored Elevation shading is     * the same thing, except colors are added to indicate the     * elevation. Band shading colors the pixels according to a range     * of elevations.     */    protected int viewType;    /** The elevation range to use for each color in band shading. */    protected int bandHeight;    /** A contrast adjustment, for slope shading (1-5). */    protected int slopeAdjust;    /** transparency control */    protected int opaqueness;    /** property suffixes */    public static final String ETOPOPathProperty = "path";    public static final String OpaquenessProperty = "opaque";    public static final String ETOPOViewTypeProperty = "view.type";    public static final String ETOPOSlopeAdjustProperty = "contrast";    public static final String ETOPOMinuteSpacingProperty = "minute.spacing";    /**     * Holds the slope values, updated when the resolution changes or     * the slope adjustment (contrast) is changed. Slope values are     * scaled between -127 to 127.     */    protected byte[] slopeMap = null;    /** elevation bands */    protected static final int[] elevLimit = { -11000, -9000, -7000, -5000,            -3000, -1500, 0, 250, 500, 750, 1000, 2000, 3500, 5000 };    /** number of elevation bands */    protected static final int elevLimitCnt = 14;    /** elevation band colors (one for each elevation band) */    protected static final int[] redElev = { 0, 0, 4, 20, 124, 130, 135, 117,            252, 253, 229, 244, 252, 132 };    protected static final int[] greenElev = { 2, 12, 51, 159, 235, 255, 235,            255, 236, 162, 115, 50, 20, 132 };    protected static final int[] blueElev = { 76, 145, 242, 249, 252, 255, 110,            58, 29, 35, 5, 14, 46, 132 };    /** for slope shading colors, indexed by elevation band then slope */    protected static Color[][] slopeColors = null;    /* flag to recompute slope map */    protected boolean slopeReset = true;    /* flag to load new elevation file */    protected boolean spacingReset = true;    /**     * The default constructor for the Layer. All of the attributes     * are set to their default values.     */    public ETOPOLayer() {        this(null);    }    /**     * The default constructor for the Layer. All of the attributes     * are set to their default values.     *      * @param pathToETOPODir path to the directory holding the ETOPO     *        data     */    public ETOPOLayer(String pathToETOPODir) {        setName("ETOPO");        setDefaultValues();        path = pathToETOPODir;        setProjectionChangePolicy(new ListResetPCPolicy(this));    }    public void setPath(String pathToETOPODir) {        path = pathToETOPODir;    }    protected void setDefaultValues() {        // defaults        path = null;        dataBuffer = null;        opaqueness = DEFAULT_OPAQUENESS;        slopeAdjust = DEFAULT_SLOPE_ADJUST;        viewType = COLOREDSHADING;        minuteSpacing = DEFAULT_MINUTE_SPACING;    }    /* returns the color lookup index based on elevation */    protected int getElevIndex(short el) {        for (int i = 0; i < elevLimitCnt - 1; i++)            if (el < elevLimit[i + 1])                return i;        return elevLimitCnt - 1;    }    /* returns a color based on slope and elevation */    protected Color getColor(short elevation, byte slopeVal) {        // build first time        if (slopeColors == null) {            // allocate storage for elevation bands, 8 slope bands            slopeColors = new Color[elevLimitCnt][8];            // process each elevation band            for (int i = 0; i < elevLimitCnt; i++) {                // get base color (0 slope color)                Color base = new Color(redElev[i], greenElev[i], blueElev[i]);                // call the "brighter" method on the base color for                // positive slope                for (int j = 4; j < 8; j++) {                    // set                    if (j == 4)                        slopeColors[i][j] = base;                    else                        slopeColors[i][j] = slopeColors[i][j - 1].brighter();                }

⌨️ 快捷键说明

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