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

📄 shapelayer.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/layer/shape/ShapeLayer.java,v $// $RCSfile: ShapeLayer.java,v $// $Revision: 1.12.2.8 $// $Date: 2005/09/13 14:34:00 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.shape;import java.awt.Component;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.io.InterruptedIOException;import java.net.MalformedURLException;import java.net.URL;import java.util.Properties;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JPanel;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MoreMath;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.DataBounds;import com.bbn.openmap.util.DataBoundsProvider;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * An OpenMap Layer that displays shape files. Note that the * ESRIRecords have been updated so that the OMGraphics that get * created from them are loaded with an Integer object that notes the * number of the record as it was read from the .shp file. This lets * you align the object with the correct attribute data in the .dbf * file. * <p> * <code><pre> *   *    *     *      *      ############################ *      # Properties for a shape layer *      shapeLayer.class=com.bbn.openmap.layer.shape.ShapeLayer *      shapeLayer.prettyName=Name_for_Menu *      shapeLayer.shapeFile=&amp;ltpath to shapefile (.shp)&amp;gt *      shapeLayer.spatialIndex=&amp;ltpath to generated spatial index file (.ssx)&amp;gt *      shapeLayer.lineColor=ff000000 *      shapeLayer.fillColor=ff000000 *      # plus any other properties used by the DrawingAttributes object. *      shapeLayer.pointImageURL=&amp;ltURL for image to use for point objects&amp;gt *      ############################ *       *      *     *    * </pre></code> *  * @author Tom Mitchell <tmitchell@bbn.com> * @version $Revision: 1.12.2.8 $ $Date: 2005/09/13 14:34:00 $ * @see SpatialIndex */public class ShapeLayer extends OMGraphicHandlerLayer implements        ActionListener, DataBoundsProvider {    /** The name of the property that holds the name of the shape file. */    public final static String shapeFileProperty = "shapeFile";    /**     * The name of the property that holds the name of the spatial     * index file.     */    public final static String spatialIndexProperty = "spatialIndex";    /** The URL of an image to use for point objects. */    public final static String pointImageURLProperty = "pointImageURL";    // Note that shadows are really in the eye of the beholder    // The X,Y shadow offset just pushes the resulting picture in the    // direction of the offset and draws it there. By setting the    // fill and line colors, you make it seem shadowy. By drawing    // a layer as a shadow, and then again as a regular layer, you    // get the proper effect.    /** The name of the property that holds the offset of the shadow. */    public final static String shadowXProperty = "shadowX";    public final static String shadowYProperty = "shadowY";    /** * The holders of the shadow offset. ** */    protected int shadowX = 0;    protected int shadowY = 0;    /** The spatial index of the shape file to be rendered. */    protected SpatialIndex spatialIndex;    /**     * The DrawingAttributes object to describe the rendering of     * graphics.     */    protected DrawingAttributes drawingAttributes = (DrawingAttributes) DrawingAttributes.DEFAULT.clone();    // For writing out to properties file later.    String shapeFileName = null;    String spatialIndexFileName = null;    String imageURLString = null;    /**     * Initializes an empty shape layer.     */    public ShapeLayer() {        setProjectionChangePolicy(new com.bbn.openmap.layer.policy.ListResetPCPolicy(this));    }    public ShapeLayer(String shapeFileName) {        this();        spatialIndex = SpatialIndex.locateAndSetShapeData(shapeFileName);    }    public void setSpatialIndex(SpatialIndex si) {        spatialIndex = si;    }    public SpatialIndex getSpatialIndex() {        return spatialIndex;    }    /**     * This method gets called from setProperties.     *      * @param realPrefix This prefix has already been scoped, which     *        means it is an empty string if setProperties was called     *        with a null prefix, or it's a String ending with a     *        period if it was defined with characters.     * @param props Properties containing information about files and     *        the layer.     */    protected void setFileProperties(String realPrefix, Properties props) {        shapeFileName = props.getProperty(realPrefix + shapeFileProperty);        spatialIndexFileName = props.getProperty(realPrefix                + spatialIndexProperty);        if (shapeFileName != null && !shapeFileName.equals("")) {            SpatialIndex spatialIndex;            if (spatialIndexFileName != null                    && !spatialIndexFileName.equals("")) {                spatialIndex = SpatialIndex.locateAndSetShapeData(shapeFileName,                        spatialIndexFileName);            } else {                spatialIndex = SpatialIndex.locateAndSetShapeData(shapeFileName);            }            imageURLString = props.getProperty(realPrefix                    + pointImageURLProperty);            try {                if (imageURLString != null && !imageURLString.equals("")) {                    URL imageURL = PropUtils.getResourceOrFileOrURL(this,                            imageURLString);                    ImageIcon imageIcon = new ImageIcon(imageURL);                    spatialIndex.setPointIcon(imageIcon);                }            } catch (MalformedURLException murle) {                Debug.error("ShapeLayer.setFileProperties: point image URL not so good: \n\t"                        + imageURLString);            } catch (NullPointerException npe) {                // May happen if not connected to the internet.                fireRequestMessage("Can't access icon image: \n    "                        + imageURLString);            }            setSpatialIndex(spatialIndex);        } else {            Debug.error("One of the following properties was null or empty:");            Debug.error("\t" + realPrefix + shapeFileProperty);            Debug.error("\t" + realPrefix + spatialIndexProperty);        }    }    /**     * Initializes this layer from the given properties.     *      * @param props the <code>Properties</code> holding settings for     *        this layer     */    public void setProperties(String prefix, Properties props) {        super.setProperties(prefix, props);        String realPrefix = PropUtils.getScopedPropertyPrefix(this);        setFileProperties(realPrefix, props);        drawingAttributes = new DrawingAttributes(prefix, props);        shadowX = PropUtils.intFromProperties(props, realPrefix                + shadowXProperty, 0);        shadowY = PropUtils.intFromProperties(props, realPrefix                + shadowYProperty, 0);    }    /**     * PropertyConsumer method.     */    public Properties getProperties(Properties props) {        props = super.getProperties(props);        String prefix = PropUtils.getScopedPropertyPrefix(this);        props.put(prefix + shapeFileProperty, (shapeFileName == null ? ""                : shapeFileName));        props.put(prefix + spatialIndexProperty,                (spatialIndexFileName == null ? "" : spatialIndexFileName));        props.put(prefix + pointImageURLProperty, (imageURLString == null ? ""                : imageURLString));        props.put(prefix + shadowXProperty, Integer.toString(shadowX));        props.put(prefix + shadowYProperty, Integer.toString(shadowY));        if (drawingAttributes != null) {            drawingAttributes.setPropertyPrefix(getPropertyPrefix());            drawingAttributes.getProperties(props);        } else {            DrawingAttributes da = (DrawingAttributes) DrawingAttributes.DEFAULT.clone();            da.setPropertyPrefix(getPropertyPrefix());            da.getProperties(props);        }        return props;    }    /**     * Method to fill in a Properties object with values reflecting     * the properties able to be set on this PropertyConsumer. The key     * for each property should be the raw property name (without a     * prefix) with a value that is a String that describes what the     * property key represents, along with any other information about     * the property that would be helpful (range, default value,     * etc.).     *      * @param list a Properties object to load the PropertyConsumer     *        properties into. If getList equals null, then a new     *        Properties object should be created.     * @return Properties object containing PropertyConsumer property     *         values. If getList was not null, this should equal     *         getList. Otherwise, it should be the Properties object     *         created by the PropertyConsumer.     */    public Properties getPropertyInfo(Properties list) {        list = super.getPropertyInfo(list);        String interString;        DrawingAttributes da;        if (drawingAttributes != null) {            da = drawingAttributes;        } else {            da = DrawingAttributes.DEFAULT;        }        da.getPropertyInfo(list);

⌨️ 快捷键说明

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