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

📄 projectionfactory.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param height pixel height of projection.     * @return Projection     */    public static Projection makeProjection(String projClassName,                                            float centerLat, float centerLon,                                            float scale, int width, int height) {        if (projClassName == null) {            throw new ProjectionException("No projection class name specified");        }        try {            return makeProjection(Class.forName(projClassName),                    centerLat,                    centerLon,                    scale,                    width,                    height);        } catch (ClassNotFoundException cnfe) {            throw new ProjectionException("Projection class " + projClassName                    + " not found");        }    }    /**     * Create a projection. If the class can't be found, a Mercator     * projection will be returned.     *      * @param projClass the class 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.     * @param height pixel height of projection.     * @return Projection     */    public static Projection makeProjection(Class projClass, float centerLat,                                            float centerLon, float scale,                                            int width, int height) {        ProjectionFactory factory = getInstance();        ProjectionLoader loader = MercatorLoader.defaultMercator;        for (Iterator it = factory.iterator(); it.hasNext();) {            ProjectionLoader pl = (ProjectionLoader) it.next();            if (pl.getProjectionClass() == projClass) {                loader = pl;            }        }        return factory.makeProjection(loader,                centerLat,                centerLon,                scale,                width,                height);    }    /**     * Looks at the Environment settings for the default projection     * and returns a Projection suited for those settings. If there is     * a problem creating the projection, the default projection of     * the MapBean will be returned. The ProjectionFactory needs to be     * loaded with the Projection class described in the properties     * before this will return an expected projection.     *      * @return Projection from Environment settings.     */    public static Projection getDefaultProjectionFromEnvironment() {        return getDefaultProjectionFromEnvironment(0, 0);    }    /**     * Looks at the Environment settings for the default projection     * and returns a Projection suited for those settings. If there is     * a problem creating the projection, the default projection of     * the MapBean will be returned. The ProjectionFactory needs to be     * loaded with the Projection class described in the properties     * before this will return an expected projection.     *      * @param width pixel height of projection. If 0 or less, the     *        Environment.Width value will be used.     * @param height pixel height of projection. If 0 or less, the     *        Environment.Height value will be used.     * @return Projection from Environment settings, fit for the pixel     *         height and width provided.     */    public static Projection getDefaultProjectionFromEnvironment(int width,                                                                 int height) {        // Initialize the map projection, scale, center        // with user prefs or defaults        Projection proj = null;        int w = (width <= 0) ? Environment.getInteger(Environment.Width,                MapBean.DEFAULT_WIDTH) : width;        int h = (height <= 0) ? Environment.getInteger(Environment.Height,                MapBean.DEFAULT_HEIGHT) : height;        try {            proj = ProjectionFactory.makeProjection(Environment.get(Environment.Projection),                    Environment.getFloat(Environment.Latitude, 0f),                    Environment.getFloat(Environment.Longitude, 0f),                    Environment.getFloat(Environment.Scale,                            Float.POSITIVE_INFINITY),                    w,                    h);        } catch (com.bbn.openmap.proj.ProjectionException pe) {            if (Debug.debugging("proj")) {                Debug.output("ProjectionFactory.getDefaultProjectionFromEnvironment(): Can't use ("                        + Environment.Projection                        + " = "                        + Environment.get(Environment.Projection)                        + ") property as a projection class, need a class name instead.  Using default of com.bbn.openmap.proj.Mercator.");            }            proj = ProjectionFactory.makeProjection(Mercator.class,                    Environment.getFloat(Environment.Latitude, 0f),                    Environment.getFloat(Environment.Longitude, 0f),                    Environment.getFloat(Environment.Scale,                            Float.POSITIVE_INFINITY),                    w,                    h);        }        return proj;    }    /**     * Call the provided ProjectionLoader to create the projection     * with the given parameters. The parameters are converted to     * Properties before being passed to the ProjectionLoader.     *      * @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.     */    public Projection makeProjection(ProjectionLoader loader, float centerLat,                                     float centerLon, float scale, int width,                                     int height) {        return makeProjection(loader,                centerLat,                centerLon,                scale,                width,                height,                null);    }    /**     * Call the provided ProjectionLoader to create the projection     * with the given parameters. The parameters are converted to     * Properties before being passed to the ProjectionLoader. The     * ProjectionLoader should throw a ProjectionException from here     * if it has a problem creating the projection with the provided     * parameters.     *      * @param loader projection loader to use.     * @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.     * @param projProps a Properties object to add the parameters     *        to, which can include extra parameters that are needed     *        by this particular projection loader. If null, a     *        Properties object will be created.     * @return projection, or null if the projection can't be created.     */    public Projection makeProjection(ProjectionLoader loader, float centerLat,                                     float centerLon, float scale, int width,                                     int height, Properties projProps) {        Projection proj = null;        if (loader == null) {            Debug.error("ProjectionFactory.makeProjection() not given a ProjectionLoader to use to create a Projection");            return proj;        }        if (projProps == null) {            projProps = new Properties();        }        projProps.put(CENTER, new LatLonPoint(centerLat, centerLon));        projProps.put(SCALE, Float.toString(scale));        projProps.put(WIDTH, Integer.toString(width));        projProps.put(HEIGHT, Integer.toString(height));        proj = loader.create(projProps);        if (proj == null) {            Debug.error("ProjectionFactory.makeProjection() tried to create a Projection from a "                    + loader.getPrettyName()                    + ", "                    + loader.getProjectionClass().getName() + ", failed.");        }        return proj;    }    public void addProjectionLoader(ProjectionLoader loader) {        projLoaders.add(loader);        fireLoadersChanged();    }    public boolean removeProjectionLoader(ProjectionLoader loader) {        boolean removed = projLoaders.remove(loader);        if (removed) {            fireLoadersChanged();        }        return removed;    }    public void clearProjectionLoaders() {        if (projLoaders.size() > 0) {            projLoaders.clear();            fireLoadersChanged();        }    }    public Iterator iterator() {        return projLoaders.iterator();    }    public int numProjections() {        return projLoaders.size();    }    protected void fireLoadersChanged() {        pcs.firePropertyChange(AvailableProjectionProperty, null, projLoaders);    }    public void addPropertyChangeListener(PropertyChangeListener pcl) {        if (pcl != null) {            pcs.addPropertyChangeListener(pcl);            pcl.propertyChange(new PropertyChangeEvent(this, AvailableProjectionProperty, null, projLoaders));        }    }    public void addPropertyChangeListener(String propertyName,                                          PropertyChangeListener pcl) {        if (pcl != null) {            pcs.addPropertyChangeListener(propertyName, pcl);            pcl.propertyChange(new PropertyChangeEvent(this, AvailableProjectionProperty, null, projLoaders));        }    }    public void removePropertyChangeListener(PropertyChangeListener pcl) {        pcs.removePropertyChangeListener(pcl);    }    public void removePropertyChangeListener(String propertyName,                                             PropertyChangeListener pcl) {        pcs.removePropertyChangeListener(propertyName, pcl);    }    /**     * Using the MapHandler to find ProjectionLoaders being added from     * the application.     */    public void findAndInit(Object obj) {        if (obj instanceof ProjectionLoader) {            addProjectionLoader((ProjectionLoader) obj);        }    }    /**     * Using the MapHandler to find ProjectionLoaders being removed     * from the application.     */    public void findAndUndo(Object obj) {        if (obj instanceof ProjectionLoader) {            removeProjectionLoader((ProjectionLoader) obj);        }    }    /**     * Convenience method to load default projections into the shared     * instance of the ProjectionFactory.     *      * @return ProjectionFactory shared instance.     */    public static ProjectionFactory loadDefaultProjections() {        return loadDefaultProjections(getInstance());    }    /**     * Convenience method to load default projections into a     * ProjectionFactory.     *      * @param pf     * @return ProjectionFactory     */    public static ProjectionFactory loadDefaultProjections(ProjectionFactory pf) {        if (pf != null && pf.numProjections() == 0) {            pf.addProjectionLoader(new com.bbn.openmap.proj.MercatorLoader());            pf.addProjectionLoader(new com.bbn.openmap.proj.OrthographicLoader());            pf.addProjectionLoader(new com.bbn.openmap.proj.CADRGLoader());            pf.addProjectionLoader(new com.bbn.openmap.proj.LLXYLoader());            pf.addProjectionLoader(new com.bbn.openmap.proj.GnomonicLoader());        }        return pf;    }}

⌨️ 快捷键说明

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