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

📄 mapbean.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * events.     *      * @param l ProjectionListener     */    public synchronized void removeProjectionListener(ProjectionListener l) {        projectionSupport.removeProjectionListener(l);    }    /**     * Called from within the MapBean when its projection listeners     * need to know about a projection change.     */    protected void fireProjectionChanged() {        // Fire the property change, so the messages get cleared out.        // Then, if any of the layers have a problem with their new        // projection, their messages will be displayed.        if (Debug.debugging("proj")) {            Debug.output("MapBean firing projection: " + getProjection());        }        firePropertyChange(ProjectionProperty, null, getProjection());        projectionSupport.fireProjectionChanged(getProjection());        purgeAndNotifyRemovedLayers();    }    /**     * Clear the vector containing all of the removed layers, and let     * those layers know they have been removed from the map.     */    public void purgeAndNotifyRemovedLayers() {        // Tell any layers that have been removed that they have        // been removed        if (removedLayers.size() == 0) {            return;        }        for (int i = 0; i < removedLayers.size(); i++) {            Layer l = ((Layer) removedLayers.elementAt(i));            l.removed(this);        }        removedLayers.removeAllElements();        // Shouldn't call this, but it's the only thing        // that seems to make it work...        // Seems to help gc'ing layers in a timely manner.        if (Debug.debugging("helpgc")) {            System.gc();        }    }    /*----------------------------------------------------------------------     * Properties     *----------------------------------------------------------------------*/    /**     * Gets the scale of the map.     *      * @return float the current scale of the map     * @see Projection#getScale     */    public float getScale() {        return projection.getScale();    }    /**     * Sets the scale of the map. The Projection may silently     * disregard this setting, setting it to a <strong>maxscale     * </strong> or <strong>minscale </strong> value.     *      * @param newScale the new scale     * @see Proj#setScale     */    public void setScale(float newScale) {        projection.setScale(newScale);        fireProjectionChanged();    }    /**     * Gets the center of the map in the form of a LatLonPoint.     *      * @return the center point of the map     * @see Projection#getCenter     */    public LatLonPoint getCenter() {        return projection.getCenter();    }    /**     * Sets the center of the map.     *      * @param newCenter the center point of the map     * @see Proj#setCenter(LatLonPoint)     */    public void setCenter(LatLonPoint newCenter) {        projection.setCenter(newCenter);        fireProjectionChanged();    }    /**     * Sets the center of the map.     *      * @param lat the latitude of center point of the map in decimal     *        degrees     * @param lon the longitude of center point of the map in decimal     *        degrees     * @see Proj#setCenter(float, float)     */    public void setCenter(float lat, float lon) {        projection.setCenter(lat, lon);        fireProjectionChanged();    }    /**     * Get the type of the projection.     *      * @return int type     * @see Projection#getProjectionType     * @deprecated Projection Type integers are no longer really used.     *             The ProjectionFactory should be consulted for which     *             type are available, and the projection should be     *             created there.     */    public int getProjectionType() {        return projection.getProjectionType();    }    /**     * Set the type of the projection. If different from the current     * type, this installs a new projection with the same center,     * scale, width, and height of the previous one.     *      * @param newType the new projection type     * @deprecated Projection Type integers are no longer really used.     *             The ProjectionFactory should be consulted for which     *             type are available, and the projection should be     *             created there.     */    public void setProjectionType(int newType) {        int oldType = projection.getProjectionType();        if (oldType != newType) {            LatLonPoint ctr = projection.getCenter();            setProjection((Proj) (ProjectionFactory.makeProjection(newType,                    ctr.getLatitude(),                    ctr.getLongitude(),                    projection.getScale(),                    projection.getWidth(),                    projection.getHeight())));        }    }    /**     * Set the background color of the map. If the background for this     * MapBean is not null, the background of the projection will be     * used.     *      * @param color java.awt.Color.     */    public void setBackgroundColor(Color color) {        setBackground(color);    }    public void setBackground(Color color) {        super.setBackground(color);        setBckgrnd((Paint) color);    }    /**     * Set the background of the map. If the background for this     * MapBean is not null, the background of the projection will be     * used.     *      * @param paint java.awt.Paint.     */    public void setBckgrnd(Paint paint) {        setBufferDirty(true);        // Instead, do this.        Paint oldBackground = background;        background = paint;        firePropertyChange(BackgroundProperty, oldBackground, background);        repaint();    }    /**     * Get the background color of the map. If the background color     * for this MapBean has been explicitly set, that value will be     * returned. Otherwise, the background color of the projection     * will be returned. If the background is not a color (as opposed     * to Paint) this method will return null.     *      * @return color java.awt.Color.     */    public Color getBackground() {        Paint ret = getBckgrnd();        if (ret instanceof Color) {            return (Color) ret;        }        return super.getBackground();    }    /**     * Get the background of the map. If the background for this     * MapBean has been explicitly set, that value will be returned.     * Otherwise, the background of the projection will be returned.     *      * @return color java.awt.Color.     */    public Paint getBckgrnd() {        Paint ret = background;        if (ret == null) {            //          ret = projection.getBackgroundColor();            ret = super.getBackground();        }        return ret;    }    /**     * Get the projection property.     *      * @return Projection     */    public Projection getProjection() {        return projection;    }    /**     * Set the projection. Shouldn't be null, and won't do anything if     * it is.     *      * @param aProjection Projection     */    public void setProjection(Projection aProjection) {        if (aProjection != null) {            setBufferDirty(true);            projection = (Proj) aProjection;            setPreferredSize(new Dimension(projection.getWidth(), projection.getHeight()));            fireProjectionChanged();        }    }    //------------------------------------------------------------    // CenterListener interface    //------------------------------------------------------------    /**     * Handles incoming <code>CenterEvents</code>.     *      * @param evt the incoming center event     */    public void center(CenterEvent evt) {        setCenter(evt.getLatitude(), evt.getLongitude());    }    //------------------------------------------------------------    // PanListener interface    //------------------------------------------------------------    /**     * Handles incoming <code>PanEvents</code>.     *      * @param evt the incoming pan event     */    public void pan(PanEvent evt) {        if (Debug.debugging("mapbean")) {            debugmsg("PanEvent: " + evt);        }        float az = evt.getAzimuth();        float c = evt.getArcDistance();        if (Float.isNaN(c)) {            projection.pan(az);        } else {            projection.pan(az, c);        }        fireProjectionChanged();    }    //------------------------------------------------------------    // ZoomListener interface    //------------------------------------------------------------    /**     * Zoom the Map. Part of the ZoomListener interface. Sets the     * scale of the MapBean projection, based on a relative or     * absolute amount.     *      * @param evt the ZoomEvent describing the new scale.     */    public void zoom(ZoomEvent evt) {        float newScale;        if (evt.isAbsolute()) {            newScale = evt.getAmount();        } else if (evt.isRelative()) {            newScale = getScale() * evt.getAmount();        } else {            return;        }        setScale(newScale);    }    //------------------------------------------------------------    // ContainerListener interface    //------------------------------------------------------------    protected transient Layer[] currentLayers = new Layer[0];    protected transient boolean doContainerChange = true;    /**     * ContainerListener Interface method. Should not be called     * directly. Part of the ContainerListener interface, and it's     * here to make the MapBean a good Container citizen.     *      * @param value boolean     */    public void setDoContainerChange(boolean value) {        // if changing from false to true, call changeLayers()        if (!doContainerChange && value) {            doContainerChange = value;            changeLayers(null);        } else {            doContainerChange = value;        }    }    /**     * ContainerListener Interface method. Should not be called     * directly. Part of the ContainerListener interface, and it's     * here to make the MapBean a good Container citizen.     *      * @return boolean     */    public boolean getDoContainerChange() {        return doContainerChange;    }    /**     * ContainerListener Interface method. Should not be called     * directly. Part of the ContainerListener interface, and it's     * here to make the MapBean a good Container citizen.     *      * @param e ContainerEvent     */    public void componentAdded(ContainerEvent e) {        // Blindly cast. addImpl has already checked to be        // sure the child is a Layer.        addProjectionListener((Layer) e.getChild());        // If the new layer is in the queue to have removed() called        // on it take it off the queue, and don't add it to the        // added() queue (it doesn't know that it was removed, yet).        // Otherwise, add it to the queue to have added() called on        // it.        if (!removedLayers.removeElement(e.getChild())) {            addedLayers.addElement(e.getChild());        }        changeLayers(e);    }    /**     * ContainerListener Interface method. Should not be called     * directly. Part of the ContainerListener interface, and it's     * here to make the MapBean a good Container citizen. Layers that     * are removed are added to a list, which is cleared when the     * projection changes. If they are added to the MapBean again     * before the projection changes, they are taken off the list,     * added back to the MapBean, and are simply repainted. This     * prevents layers from doing unnecessary work if they are toggled     * on and off without projection changes.     *      * @param e ContainerEvent     * @see com.bbn.openmap.MapBean#purgeAndNotifyRemovedLayers     */    public void componentRemoved(ContainerEvent e) {        // Blindly cast. addImpl has already checked to be        // sure the child is a Layer.        removeProjectionListener((Layer) e.getChild());        removedLayers.addElement(e.getChild());        changeLayers(e);    }    /**     * ContainerListener Interface method. Should not be called     * directly. Part of the ContainerListener interface, and it's     * here to make the MapBean a good Container citizen.     *      * @param e ContainerEvent     */    protected void changeLayers(ContainerEvent e) {        // Container Changes can be disabled to speed adding/removing        // multiple layers        if (!doContainerChange) {            return;        }        Component[] comps = this.getComponents();        int ncomponents = comps.length;        Layer[] newLayers = new Layer[ncomponents];        System.arraycopy(comps, 0, newLayers, 0, ncomponents);        if (Debug.debugging("mapbean"))

⌨️ 快捷键说明

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