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

📄 basicgeometry.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        replaceAppObjectWithAttributeMap();        return (Map) getAppObject(false);    }    /**     * Method to extend if you don't like Hashtables used for     * attribute table.     */    protected Map createAttributeMap() {        return new Hashtable();    }    /**     * Adds a key-value pair to the attribute Map. The Map will be     * created if it doesn't exist.     */    public void putAttribute(Object key, Object value) {        if (key != null && value != null) {            getAttributeMap().put(key, value);        }    }    /**     * Returns the object stored in a Map stored in the appObject. If     * the appObject is a Map, the key will be passed to it even if     * the Map isn't considered to be the 'official' attribute Map.     */    public Object getAttribute(Object key) {        if (key != null) {            Object appObj = getAppObject(false);            if (appObj instanceof Map) {                return ((Map) appObj).get(key);            }        }        return null;    }    /**     * Removes the object stored in a Map stored in the appObject. If     * the appObject is a Map, the key will be passed to it even if     * the Map isn't considered to be the 'official' attribute Map.     * Returns the removed value from the Map, or null if there wasn't     * a value for the given key.     */    public Object removeAttribute(Object key) {        Object appObj = getAppObject(false);        if (appObj instanceof Map) {            return ((Map) appObj).remove(key);        }        // else        return null;    }    /**     * Removes all of the objects stored in a Map stored in the     * appObject. If the appObject is a Map, the clear command will be     * passed to it even if the Map isn't considered to be the     * 'official' attribute Map.     */    public void clearAttributes() {        Object appObj = getAppObject(false);        if (appObj instanceof Map) {            ((Map) appObj).clear();        }    }    /**     * Returns the 'official' attribute Map, null if it hasn't been     * set.     */    public Map getAttributes() {        Object appObj = getAppObject(false);        if (checkAttributeMap(appObj)) {            // Only returns the attribute Map if it's the official            // version, which is marked by having a pointer to itself            // under the ATT_MAP_KEY            return (Map) appObj;        }        // else        return null;    }    /**     * Sets the 'official' attribute Map, moving any appObject that     * isn't currently the 'official' attribute Map into the map under     * the APP_OBJECT_KEY.     */    public void setAttributes(Map atts) {        if (!checkAttributeMap()) {            if (appObject != null) {                atts.put(APP_OBJECT_KEY, appObject);            }        } else {            Object appObj = getAttribute(APP_OBJECT_KEY);            if (appObj != null) {                atts.put(APP_OBJECT_KEY, appObj);            }        }        setAppObject(atts, false);    }    //////////////////////////////////////////////////////////////////////////    /**     * Prepare the geometry for rendering. This must be done before     * calling <code>render()</code>! If a vector graphic has     * lat-lon components, then we project these vertices into x-y     * space. For raster graphics we prepare in a different fashion.     * <p>     * If the generate is unsuccessful, it's usually because of some     * oversight, (for instance if <code>proj</code> is null), and     * if debugging is enabled, a message may be output to the     * controlling terminal.     * <p>     *      * @param proj Projection     * @return boolean true if successful, false if not.     * @see #regenerate     */    public abstract boolean generate(Projection proj);    /**     *       */    public boolean isRenderable() {        return (!getNeedToRegenerate() && isVisible() && shape != null);    }    /**     * Paint the graphic, as a filled shape.     * <P>     *      * This paints the graphic into the Graphics context. This is     * similar to <code>paint()</code> function of     * java.awt.Components. Note that if the graphic has not been     * generated or if it isn't visible, it will not be rendered.     * <P>     *      * This method used to be abstract, but with the conversion of     * OMGeometrys to internally represent themselves as     * java.awt.Shape objects, it's a more generic method. If the     * OMGeometry hasn't been updated to use Shape objects, it should     * have its own render method.     *      * @param g Graphics2D context to render into.     */    public void fill(Graphics g) {        if (isRenderable()) {            ((Graphics2D) g).fill(shape);        }    }    /**     * Paint the graphic, as an outlined shape.     * <P>     *      * This paints the graphic into the Graphics context. This is     * similar to <code>paint()</code> function of     * java.awt.Components. Note that if the graphic has not been     * generated or if it isn't visible, it will not be rendered.     * <P>     *      * This method used to be abstract, but with the conversion of     * OMGeometrys to internally represent themselves as     * java.awt.Shape objects, it's a more generic method. If the     * OMGeometry hasn't been updated to use Shape objects, it should     * have its own render method.     *      * @param g Graphics2D context to render into.     */    public void draw(Graphics g) {        if (isRenderable()) {            ((Graphics2D) g).draw(shape);        }    }    /**     * Return the shortest distance from the edge of a graphic to an     * XY-point.     * <p>     *      * @param x X coordinate of the point.     * @param y Y coordinate of the point.     * @return float distance, in pixels, from graphic to the point.     *         Returns Float.POSITIVE_INFINITY if the graphic isn't     *         ready (ungenerated).     */    public float distanceToEdge(int x, int y) {        float distance = Float.POSITIVE_INFINITY;        if (getNeedToRegenerate() || shape == null) {            return distance;        }        PathIterator pi2 = shape.getPathIterator(null);        FlatteningPathIterator pi = new FlatteningPathIterator(pi2, .25);        double[] coords = new double[6];        int count = 0;        double startPntX = 0;        double startPntY = 0;        double endPntX = 0;        double endPntY = 0;        while (!pi.isDone()) {            int type = pi.currentSegment(coords);            float dist;            if (type == PathIterator.SEG_LINETO) {                startPntX = endPntX;                startPntY = endPntY;                endPntX = coords[0];                endPntY = coords[1];                dist = (float) Line2D.ptSegDist(startPntX,                        startPntY,                        endPntX,                        endPntY,                        (double) x,                        (double) y);                if (dist < distance) {                    distance = dist;                }                if (Debug.debugging("omgraphicdetail")) {                    Debug.output("Type: " + type + "(" + (count++) + "), "                            + startPntX + ", " + startPntY + ", " + endPntX                            + ", " + endPntY + ", " + x + ", " + y                            + ", distance: " + distance);                }            } else {                // This should be the first and last                // condition, SEG_MOVETO and SEG_CLOSE                startPntX = coords[0];                startPntY = coords[1];                endPntX = coords[0];                endPntY = coords[1];            }            pi.next();        }        return distance;    }    /**     * Return the shortest distance from the graphic to an XY-point.     * Checks to see of the point is contained within the OMGraphic,     * which may, or may not be the right thing for clear OMGraphics     * or lines.     * <p>     *      * This method used to be abstract, but with the conversion of     * OMGeometrys to internally represent themselves as     * java.awt.Shape objects, it's a more generic method. If the     * OMGeometry hasn't been updated to use Shape objects, it should     * have its own distance method.     * <p>     *      * Calls _distance(x, y);     *      * @param x X coordinate of the point.     * @param y Y coordinate of the point.     * @return float distance, in pixels, from graphic to the point.     *         Returns Float.POSITIVE_INFINITY if the graphic isn't     *         ready (ungenerated).     */    public float distance(int x, int y) {        return _distance(x, y);    }    /**     * Return the shortest distance from the graphic to an XY-point.     * Checks to see of the point is contained within the OMGraphic,     * which may, or may not be the right thing for clear OMGraphics     * or lines.     * <p>     *      * _distance was added so subclasses could make this call if their     * geometries/attributes require this action (when fill color     * doesn't matter).     *      * @param x X coordinate of the point.     * @param y Y coordinate of the point.     * @return float distance, in pixels, from graphic to the point.     *         Returns Float.POSITIVE_INFINITY if the graphic isn't     *         ready (ungenerated).     */    protected float _distance(int x, int y) {        float distance = Float.POSITIVE_INFINITY;        if (getNeedToRegenerate() || shape == null) {            return distance;        }        if (shape.contains((double) x, (double) y)) {            //          if (Debug.debugging("omgraphicdetail")) {            //              Debug.output(" contains " + x + ", " + y);            //          }            return 0f;        } else {            return distanceToEdge(x, y);        }    }    /**     * Answsers the question whether or not the OMGeometry contains     * the given pixel point.     * <P>     * This method used to be abstract, but with the conversion of     * OMGeometrys to internally represent themselves as     * java.awt.Shape objects, it's a more generic method. If the     * OMGeometry hasn't been updated to use Shape objects, it should     * have its own contains method.     * <P>     * This method duplicates a java.awt.Shape method, with some     * protection wrapped around it. If you have other queries for the     * internal Shape object, just ask for it and then ask it     * directly. This method is provided because it is the most     * useful, used when determining if a mouse event is occuring over     * an object on the map.

⌨️ 快捷键说明

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