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

📄 projectionfactory.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/proj/ProjectionFactory.java,v $// $RCSfile: ProjectionFactory.java,v $// $Revision: 1.4.2.8 $// $Date: 2005/08/11 21:03:19 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.proj;import com.bbn.openmap.Environment;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MapBean;import com.bbn.openmap.OMComponent;import com.bbn.openmap.util.Debug;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.util.Iterator;import java.util.Properties;import java.util.Vector;/** * The ProjectionFactory creates Projections. It used to have * Projection classes hard-coded into it which were accessable through * static methods, but this paradigm has been changed slightly so the * ProjectionFactory is actually a singleton which can be accessed by * a ProjectionFactory.getInstance() static method. This was done so * that the singleton, when added to the MapHandler, can look for * ProjectionLoaders to dynamically add projections to the factory. * For convenience, there are still some static methods on the * ProjectionFactory class which use the singleton to create and * return projection objects. Changes to the available projections can * be discovered through property changes. * <P> *  * The ProjectionFactory singleton instance can be added to the * MapHandler via the openmap.properties file by adding the * ProjectionFactoryLoader to the openmap.components property. If you * are using the openmap.properties file to configure your * application, you MUST add the ProjectionFactoryLoader, or you won't * see any projections. */public class ProjectionFactory extends OMComponent {    /**     * Center lat/lon property parameter for new projections passed to     * ProjectionLoader.     */    public final static String CENTER = "CENTER";    /**     * Scale property parameter for new projections passed to     * ProjectionLoader.     */    public final static String SCALE = "SCALE";    /**     * Projeciton height (pixels) property parameter for new     * projections passed to ProjectionLoader.     */    public final static String HEIGHT = "HEIGHT";    /**     * Projection width (pixels) property parameter for new     * projections passed to ProjectionLoader.     */    public final static String WIDTH = "WIDTH";    /**     * Datum property parameter for new projections passed to     * ProjectionLoader.     */    public final static String DATUM = "DATUM";    /**     * The property name that is fired when the list of available     * projections has changed.     */    public final static String AvailableProjectionProperty = "AvailableProjections";    /**     * PropertyChangeSupport for letting listeners know about new     * projections that are available from the factory.     */    protected PropertyChangeSupport pcs;    /**     * Singleton instance.     */    protected static ProjectionFactory instance;    protected Vector projLoaders = new Vector();    /**     * Singleton constructor.     */    private ProjectionFactory() {        pcs = new PropertyChangeSupport(this);        projLoaders = new Vector();    }    /**     * Get the singleton instance of the ProjectionFactory.     */    public static ProjectionFactory getInstance() {        if (instance == null) {            instance = new ProjectionFactory();        }        return instance;    }    /**     * Returns an array of Projection names available from this     * factory.     */    public static String[] getAvailableProjections() {        ProjectionFactory factory = getInstance();        int nProjections = factory.numProjections();        String projNames[] = new String[nProjections];        int i = 0;        for (Iterator it = factory.iterator(); it.hasNext(); projNames[i++] = ((ProjectionLoader) it.next()).getPrettyName())            ;        return projNames;    }    /**     * Return the Projection Class with the given pretty name.     *      * @param name the name of the projection, set in the pretty name     *        of it's ProjectionLoader.     * @return Class of Projection, or null if not found.     */    public static Class getProjClassForName(String name) {        if (name != null) {            for (Iterator it = getInstance().iterator(); it.hasNext();) {                ProjectionLoader loader = (ProjectionLoader) it.next();                if (name.equalsIgnoreCase(loader.getPrettyName())) {                    return loader.getProjectionClass();                }            }            // If there wasn't a class with the pretty name, check to            // make sure it wasn't a class name itself. If it fails,            // return null. We just want to do this in case people            // start using class names for pretty names.            try {                return Class.forName(name);            } catch (ClassNotFoundException cnfe) {            }        }        return null;    }    /**     * Return an int representing the OpenMap projection, given the     * name of the projection. Useful for setting a projection based     * on the name stated in a properties file.     *      * @param projName the projection name from the Projection class.     * @return the projection type number for that name.     * @deprecated The notion of a projection type number is going     *             away, use the class of the projection instead.     */    public static int getProjType(String projName) {        int projType = Mercator.MercatorType;        if (projName == null) {        } else if (projName.equalsIgnoreCase(Mercator.MercatorName))            projType = Mercator.MercatorType;        else if (projName.equalsIgnoreCase(MercatorView.MercatorViewName))            projType = MercatorView.MercatorViewType;        else if (projName.equalsIgnoreCase(Orthographic.OrthographicName))            projType = Orthographic.OrthographicType;        else if (projName.equalsIgnoreCase(OrthographicView.OrthographicViewName))            projType = OrthographicView.OrthographicViewType;        else if (projName.equalsIgnoreCase(LLXY.LLXYName))            projType = LLXY.LLXYType;        else if (projName.equalsIgnoreCase(LLXYView.LLXYViewName))            projType = LLXYView.LLXYViewType;        else if (projName.equalsIgnoreCase(CADRG.CADRGName))            projType = CADRG.CADRGType;        else if (projName.equalsIgnoreCase(Gnomonic.GnomonicName))            projType = Gnomonic.GnomonicType;        return projType;    }    /**     * Makes a new projection based on the given projection and given     * type.     * <p>     * The <code>centerLat</code>,<code>centerLon</code>,     * <code>scale</code>,<code>width</code>, and     * <code>height</code> parameters are taken from the given     * projection, and the type is taken from the type argument.     *      * @param newProjType the type for the resulting projection     * @param p the projection from which to copy other parameters     * @deprecated The notion of a projection type number is going     *             away, use the class of the projection instead.     */    public static Projection makeProjection(int newProjType, Projection p) {        LatLonPoint ctr = p.getCenter();        return makeProjection(newProjType,                ctr.getLatitude(),                ctr.getLongitude(),                p.getScale(),                p.getWidth(),                p.getHeight());    }    /**     * Create a projection.     *      * @param projType projection type     * @param centerLat center latitude in decimal degrees     * @param centerLon center latitude in decimal degrees     * @param scale float scale     * @param width pixel width of projection     * @param height pixel height of projection     * @return Projection     * @deprecated The notion of a projection type number is going     *             away, use the class of the projection instead.     */    public static Projection makeProjection(int projType, float centerLat,                                            float centerLon, float scale,                                            int width, int height) {        Class projClass = null;        switch (projType) {        case CADRG.CADRGType:            projClass = com.bbn.openmap.proj.CADRG.class;            break;        case Mercator.MercatorType:            projClass = com.bbn.openmap.proj.Mercator.class;            break;        case MercatorView.MercatorViewType:            projClass = com.bbn.openmap.proj.MercatorView.class;            break;        case LLXY.LLXYType:            projClass = com.bbn.openmap.proj.LLXY.class;            break;        case LLXYView.LLXYViewType:            projClass = com.bbn.openmap.proj.LLXYView.class;            break;        case Orthographic.OrthographicType:            projClass = com.bbn.openmap.proj.Orthographic.class;            break;        case OrthographicView.OrthographicViewType:            projClass = com.bbn.openmap.proj.OrthographicView.class;            break;        case Gnomonic.GnomonicType:            projClass = com.bbn.openmap.proj.Gnomonic.class;            break;        default:            System.err.println("Unknown projection type " + projType                    + " in ProjectionFactory.create()");        }        return makeProjection(projClass,                centerLat,                centerLon,                scale,                width,                height);    }    /**     * Makes a new projection based on the given projection class name     * and parameters from the given projection.     */    public static Projection makeProjection(String projClassName, Projection p) {        LatLonPoint ctr = p.getCenter();        return makeProjection(projClassName,                ctr.getLatitude(),                ctr.getLongitude(),                p.getScale(),                p.getWidth(),                p.getHeight());    }    /**     * Create a projection. If the Class for the classname can't be     * found, a Mercator projection will be returned.     *      * @param projClassName the classname of the projection.     * @param centerLat center latitude in decimal degrees.     * @param centerLon center latitude in decimal degrees.     * @param scale float scale.     * @param width pixel width of projection.

⌨️ 快捷键说明

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