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

📄 rpfcachehandler.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/rpf/RpfCacheHandler.java,v $// $RCSfile: RpfCacheHandler.java,v $// $Revision: 1.6.2.2 $// $Date: 2005/08/09 21:17:56 $// $Author: dietrick $//// **********************************************************************/** *  Modifications : * *  1. Changed getSubframeFromOtherTOC(): changed offsets and prevent caching *     from other TOCs *//* * Some of the ideas for this code is based on source code provided by * The MITRE Corporation, through the browse application source code. * Many thanks to Nancy Markuson who provided BBN with the software, * and Theron Tock, who wrote the software, and to Daniel Scholten, * who revised it - (c) 1994 The MITRE Corporation for those parts, * and used/distributed with permission.  Namely, the subframe caching * mechanism is the part that has been modified. */package com.bbn.openmap.layer.rpf;import java.awt.Point;import java.util.Vector;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.omGraphics.OMRasterObject;import com.bbn.openmap.proj.CADRG;import com.bbn.openmap.util.Debug;/** * The RpfCacheHandler handles everything to do with the decompressed * subframes, which is what gets put up on the screen. It interfaces * with the RpfFrameProvider to get the information about the data. It * also is usually handled by the RpfCacheManager. */public class RpfCacheHandler {    /* Lowered from 128 - used too much memory */    public final static int SUBFRAME_CACHE_SIZE = 20;    /* # CHUM descriptor string */    public final static int MAX_NUM_DESC = 20;    /* # CHUM descriptor string */    public final static int MAX_DESC_LEN = 512;    public static final int DEFAULT_SUBFRAMEBUFFER = 5;    /* DKS fix chum description problem : */    /** subframe status constant. */    public final static int NOT_CACHED = -1;    /** subframe status constant. */    public final static int NOT_PRESENT = -2;    /** Subframe scaling for map scales that don't match chart scale. */    protected int scalingHeight = RpfSubframe.PIXEL_EDGE_SIZE;    /** Subframe scaling for map scales that don't match chart scale. */    protected int scalingWidth = RpfSubframe.PIXEL_EDGE_SIZE;    /** The subframe cache. */    protected SubframeCache cache;    /**     * The current description of the TOC entry that currently     * applies.     */    protected Vector coverageBoxes;    /**     * The array of indexes for subframes contained in the     * RpfTocEntry.     */    protected int[][] subframeIndex;    /**     * The array of version markers for subframes contained in the     * RpfTocEntry.     */    protected int[][] subframeVersion;    /** The size of the subframe cache. */    protected int subframeCacheSize;    /**     * Description of how the frames should be constructed and     * displayed.     */    protected RpfViewAttributes viewAttributes;    /** The place to look for for image data. */    protected RpfFrameProvider frameProvider;    /** The upper left subframe index on screen. */    protected Point start = new Point();    /** The lower right subframe index on screen. */    protected Point end = new Point();    /**     * A flag to let the cache manager know that the subframes needed     * for the map make sense.     */    protected boolean goodData = false;    /**     * The subframe cache is mapped by a 2D matrix based on the number     * of subframes that will fit in the RpfCoverageBox area. The     * subframeBuffer is used to put additional subframe entries in     * the matrix, so that subframes retrieved outside of the     * RpfCoverageBox area can still be cached. The subframeBuffer     * refers to the number of subframes added on each side of the     * matrix.     */    protected int subframeBuffer = DEFAULT_SUBFRAMEBUFFER;    /**     * Used in setCache to see if new coverage is needed with a     * projection change.     */    private float lastScaleDifference = -1f;    protected boolean DEBUG_RPF = false;    protected boolean DEBUG_RPFDETAIL = false;    /** The entire subframe cache */    static public class SubframeCache {        RpfSubframe[] subframe;        int LRU_head, LRU_tail;        public SubframeCache(int numSubframes) {            subframe = new RpfSubframe[numSubframes];        }    }    /**     * Constructor for a main cache, with the full size cache.     */    public RpfCacheHandler(RpfFrameProvider provider, RpfViewAttributes rva) {        this(provider, rva, SUBFRAME_CACHE_SIZE);    }    /**     * Constructor for an auxiliary cache, with a settable cache size.     */    public RpfCacheHandler(RpfFrameProvider provider, RpfViewAttributes rva,            int subframe_cache_size) {        DEBUG_RPF = Debug.debugging("rpf");        DEBUG_RPFDETAIL = Debug.debugging("rpfdetail");        frameProvider = provider;        viewAttributes = rva;        updateViewAttributes();        subframeCacheSize = subframe_cache_size;        initCache(true); // subframe cache, and it's new        if (DEBUG_RPF) {            Debug.output("RpfCacheHandler: Created with cache size of "                    + subframeCacheSize);        }    }    //      public void finalize() {    //      Debug.message("gc", "RpfCacheHandler: getting GC'd");    //      }    /**     * Set the view attributes for the layer. The frame provider view     * attributes are updated, and the cache is cleared.     *      * @param rva the RpfViewAttributes used for the layer.     */    public void setViewAttributes(RpfViewAttributes rva) {        viewAttributes = rva;        updateViewAttributes();        clearCache();    }    /**     * Get the view attributes or the layer.     *      * @return RpfViewAttributes.     */    public RpfViewAttributes getViewAttributes() {        return viewAttributes;    }    /**     * Set the RpfFrameProvider for the layer. Clears out the cache,     * and the frame provider gets the RpfViewAttributes held by the     * layer.     *      * @param fp the frame provider.     */    public void setFrameProvider(RpfFrameProvider fp) {        frameProvider = fp;        if (frameProvider != null) {            frameProvider.setViewAttributes(viewAttributes);        }        clearCache();    }    /**     * Return RpfFrameProvider used by the layer.     */    public RpfFrameProvider getFrameProvider() {        return frameProvider;    }    /**     * This only needs to be called if the frame provider is not     * local. In that case, updates to the view attributes object will     * not be reflected on the server side. This will update the     * parameters.     */    public void updateViewAttributes() {        if (frameProvider != null) {            frameProvider.setViewAttributes(viewAttributes);        }    }    /**     * Returns the Vector containing RpfCoverageBoxes that was     * returned from the RpfFrameProvider as a result of the last     * setCache call. These provide rudimentary knowledge about what     * is being displayed.     *      * @return Vector of RpfCoverageBoxes.     */    public Vector getCoverageBoxes() {        return coverageBoxes;    }    /**     * Called to prepare the cache for subframes that will fit into     * the next request. The subframe entry from the TOC is known and     * tracked, and if it changes, the frame cache gets tossed and     * recreated via setScreenSubframes.     *      * @param ullat NW latitude.     * @param ullon NW longitude.     * @param lrlat SE latitude.     * @param lrlon SE longitude     * @param proj CADRG projection to use for zone decisions.     */    public void setCache(float ullat, float ullon, float lrlat, float lrlon,                         CADRG proj) {        boolean needNewCoverage = true;        String oldID = null;        RpfCoverageBox currentBox = null;        int i;        // Right now, we're just going to deal with the first coverage        // box back in the pile. Maybe later, we can scale other        // chart scale and merger coverages to fill holes. Not enough        // time now, though.        if (coverageBoxes != null && coverageBoxes.size() != 0) {            currentBox = (RpfCoverageBox) coverageBoxes.elementAt(0);            oldID = currentBox.getID();            float currentPercentCoverage = currentBox.getPercentCoverage();            if (DEBUG_RPF) {                Debug.output("RpfCachehandler: checking current coverage before re-query:");            }            float currentScaleDifference = RpfFrameCacheHandler.scaleDifference(proj,                    currentBox);            if (currentPercentCoverage <= currentBox.setPercentCoverage(ullat,                    ullon,                    lrlat,                    lrlon,                    start,                    end)                    && lastScaleDifference == currentScaleDifference) {                needNewCoverage = false;                goodData = true;                lastScaleDifference = currentScaleDifference;                if (DEBUG_RPF) {                    Debug.output("RpfCachehandler: reusing Coverage");                }            }        }        // If the scale changes, of if the percent coverage        // diminishes, check to see if there is something better.        if (needNewCoverage) {            if (DEBUG_RPF) {                Debug.output("RpfCacheHandler: Need new Coverage.");            }            if (frameProvider != null) {                coverageBoxes = frameProvider.getCoverage(ullat,                        ullon,                        lrlat,                        lrlon,                        proj);            } else {                coverageBoxes = null;            }            // See if anything came back...            if (coverageBoxes == null || coverageBoxes.size() == 0) {                // Guess not.                goodData = false;                return;

⌨️ 快捷键说明

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