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

📄 areahandler.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/shape/areas/AreaHandler.java,v $// $RCSfile: AreaHandler.java,v $// $Revision: 1.4.2.4 $// $Date: 2005/08/12 20:59:37 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.shape.areas;import java.awt.Color;import java.io.InputStream;import java.net.URL;import java.util.Hashtable;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import com.bbn.openmap.MoreMath;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.dataAccess.shape.DbfTableModel;import com.bbn.openmap.dataAccess.shape.input.DbfInputStream;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.shape.CSVShapeInfoFile;import com.bbn.openmap.layer.shape.ESRIRecord;import com.bbn.openmap.layer.shape.ShapeLayer;import com.bbn.openmap.layer.shape.SpatialIndex;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMGeometryList;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * An object to organize graphics in a shapefile and their * corresponding attributes in OpenMap. A properties object can * determine how areas/graphics are to be colored, or you can grab the * graphics directly and color them yourself. It's called AreaHandler * because it was originally intended to be a management tool for * political boundary areas, but it should work for all shapefiles, * really. This object uses a CSV file created from the DBF file that * usually accompanies the shapefile. Also, this class does inflict a * startup burden on the map. Because all the organizational effort * occurs in setProperties(), it occurs even if the handler isn't used * in an active Layer. * <P> * Here is a sample of what this thing is looking for by way of * properties: * <P> *  * <pre> *      *       *       layer.class=com.bbn.openmap.layer.shape.areas.AreaShapeLayer *       layer.prettyName=Layer Name *       layer.shapeFile=/usr/local/data/shape/shapefile.shp *       layer.spatialIndex=/usr/local/data/shape/shapefile.ssx *       *       # Now, provide a data file that says what the shapes in the .shp *       # file are.  You can use the DBF file: *       layer.dbfFile=/usr/local/data/shape/shapefile.dbf *       # OR a csv file, created yourself or from the .dbf file.  There *       # should be the same number of entries in the .csv file that are in *       # the .shp file. *       layer.csvFile=/usr/local/data/shape/shapefile.csv *       # An attribute to tell the AreaHandler to skip over the first row *       # of the csv file if it contains descriptive column header names. *       layer.csvFileHasHeader=true *       *       # Default DrawingAttributes properties for everything not defined *       # specifically: *       layer.lineColor=ff000000 *       layer.fillColor=ffff00ff *       *       # Now add any other attributes accepted by the DrawingAttributes *       # object, with the prefix as stated above, i.e. layer.lineColor) *       # *       # The first column index is 0, not 1. *       # *       # The key index specifies which column in the csv file contains *       # unique area names that are listed in the areas list here in the *       # properties.  In this case, it's the column that contains MA in one *       # of its rows. *       layer.keyIndex=4 *       *       # The name index is the column in the csv file that contains what *       # should be displayed in the application when a shape is chosen - the *       # object's proper name. *       layer.nameIndex=4 *       layer.areas=MA RI *       layer.areas.MA.fillColor=ffff0000 *       layer.areas.MA.lineColor=ff00ff00 *       layer.areas.RI.fillColor=ffff0000 *       layer.areas.RI.lineColor=ff00ff00 *        *       * </pre> *  * <P> */public class AreaHandler implements PropertyConsumer {    /**     * The known political areas, based on the list of OMGraphics each     * entry contains.     */    protected Hashtable politicalAreas;    /** The property that lists special colored areas. */    public static final String areasProperty = "areas";    /**     * A property that sets an image URL to use for point objects.     * Only one image for all point objects.     */    public static final String pointImageURLProperty = "pointImageURL";    /**     * The property that specifies an index location for the area     * search key for a shape graphic in the database file. Default is     * 1. The contents of this column should match the area key used     * to specify the drawingattributes of that particular object as     * listed in these properties.     */    public static final String keyIndexProperty = "keyIndex";    /**     * The property that specifies an index location for the area name     * for a shape graphic in the database file. Default is 0.     */    public static final String nameIndexProperty = "nameIndex";    /**     * The resource name, URL or file name of the serialized graphics     * file.     */    public static final String CacheFileProperty = "cacheFile";    /**     * The name of the property that holds the name of the CSV file     * with the area attributes, like the name and the abbreviation     * (or search Key).     */    public final static String csvFileProperty = "csvFile";    /** Set if the CSVFile has a header record. Default is true. */    public final static String csvHeaderProperty = "csvFileHasHeader";    /**     * The name of the property that holds the name of the DBF file     * with the area attributes, like the name and the abbreviation     * (or search Key).     */    public final static String dbfFileProperty = "dbfFile";    /**     * The list of areas that have special coloring needs. Used to     * write the properties back out.     */    protected Vector areasItems = new Vector();    /**     * The index of the column that holds the name of the area. This     * name will be used for display in the GUI for a particular map     * object.     */    protected int nameIndex = 0;    /**     * The index of the column that holds the search key of the area.     * This is the field that is the key to use for the Hashtable     * holding all the area descriptions, and should be unique for     * each named area.     */    protected int keyIndex = 1;    /** The URL location of the cached graphics file. */    protected URL cacheURL = null;    /** The graphics list */    protected OMGraphicList omgraphics = null;    /**     * Default draw parameters of the graphics that don't have     * something specific set for it.     */    protected DrawingAttributes drawingAttributes;    /** The location of the CSV attribute file. */    protected CSVShapeInfoFile infoFile = null;    /** The DBF attribute file table model. */    protected DbfTableModel dbfModel = null;    /**     * Flag that specifies that the first line consists of header     * information, and should not be mapped to a graphic.     */    protected boolean csvHasHeader = true;    protected Properties originalProperties = null;    protected String originalPrefix = null;    protected SpatialIndex spatialIndex = null;    // public AreaHandler() {}    /**     * Construct an AreaHandler. Needs an external SpatialIndex, and     * default DrawingAttributes.     */    public AreaHandler(SpatialIndex si, DrawingAttributes da) {        setDrawingAttributes(da);        setSpatialIndex(si);    }    public void setDrawingAttributes(DrawingAttributes da) {        drawingAttributes = da;    }    public DrawingAttributes getDrawingAttributes() {        return drawingAttributes;    }    public void setSpatialIndex(SpatialIndex si) {        spatialIndex = si;    }    public SpatialIndex getSpatialIndex() {        return spatialIndex;    }    public void setProperties(Properties props) {        setProperties(null, props);    }    /**     * Initializes this object from the given properties     *      * @param props the <code>Properties</code> holding settings for     *        this object     */    public void setProperties(String prefix, Properties props) {        if (Debug.debugging("areas")) {            Debug.output("AreaHandler: setting properties");        }        setPropertyPrefix(prefix);        originalProperties = props;        // These will get initialized when someone asks for it.        // Otherwise, it delays the startup of the map.        politicalAreas = null;    }    /** PropertyConsumer method. */    public Properties getProperties(Properties props) {        if (props == null) {            props = new Properties();        }        return props;    }    /** PropertyConsumer method. */    public Properties getPropertyInfo(Properties props) {        if (props == null) {            props = new Properties();        }        return props;    }    /** PropertyConsumer method. */    public void setPropertyPrefix(String pre) {        originalPrefix = pre;    }    /** PropertyConsumer method. */    public String getPropertyPrefix() {        return originalPrefix;    }    /**     * Go through the properties, loading the shapefile, information     * file and attributes files, and resolve how everything should be     * drawn. Might take awhile if the files are large. Called from     * getRectangle, which is called when the AreaShapeLayer is added     * to the map.     *      * @param prefix property file entry header name     * @param props the properties to look through.     */    public void initialize(String prefix, Properties props) {        if (props == null) {            Debug.error("AreaHandler: initialize received bad input:\n\tprefix: "                    + prefix                    + "\n\tproperties: "                    + (props == null ? "null" : "OK"));            politicalAreas = null;            return;        }        prefix = PropUtils.getScopedPropertyPrefix(prefix);        politicalAreas = new Hashtable();        // OK, Get the graphics. We are not expecting that all the        // graphics in the file are not too much to handle. Also, we        // test for the serialized graphics file first, and if it        // isn't designated, then look for a shapefile and spatial        // index file to create an OMGraphicsList.        String cacheFile = props.getProperty(prefix + CacheFileProperty);        // First find the resource, if not, then try as a file-URL...        try {            cacheURL = PropUtils.getResourceOrFileOrURL(this, cacheFile);            if (cacheURL != null) {                omgraphics = readCachedGraphics(cacheURL);            } else {                // We'll use the spatial index set from the                // ShapeLayer.                // Now, get the attribute file                String dbfFile = props.getProperty(prefix + dbfFileProperty);                URL dbfFileURL = null;                if (dbfFile != null) {                    dbfFileURL = PropUtils.getResourceOrFileOrURL(this, dbfFile);                }                if (dbfFileURL != null) {                    InputStream is = dbfFileURL.openStream();                    dbfModel = new DbfTableModel(new DbfInputStream(is));                }                if (dbfModel == null) {                    String csvFile = props.getProperty(prefix + csvFileProperty);                    URL infofileURL = null;                    if (csvFile != null) {                        infofileURL = PropUtils.getResourceOrFileOrURL(this,                                csvFile);                    }                    // Read them in.                    if (infofileURL != null) {                        infoFile = new CSVShapeInfoFile(csvFile);                        infoFile.setHeadersExist(PropUtils.booleanFromProperties(props,                                prefix + csvHeaderProperty,                                true));                        infoFile.loadData(true);                    }                }            }        } catch (java.net.MalformedURLException murle) {            omgraphics = new OMGraphicList();        } catch (java.io.IOException ioe) {            omgraphics = new OMGraphicList();        } catch (Exception exc) {            omgraphics = new OMGraphicList();

⌨️ 快捷键说明

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