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

📄 proj.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param center LatLonPoint center     * @param scale float scale     * @param width width of screen     * @param height height of screen     */    protected void setParms(LatLonPoint center, float scale, int width,                            int height) {        ctrLat = normalize_latitude(center.radlat_);        ctrLon = wrap_longitude(center.radlon_);        this.scale = scale;        if (this.scale < minscale) {            this.scale = minscale;        } else if (this.scale > maxscale) {            this.scale = maxscale;        }        this.width = width;        if (this.width < MIN_WIDTH) {            Debug.message("proj", "Proj.setParms: width too small!");            this.width = MIN_WIDTH;        }        this.height = height;        if (this.height < MIN_HEIGHT) {            Debug.message("proj", "Proj.setParms: height too small!");            this.height = MIN_HEIGHT;        }        computeParameters();    }    /**     * Gets the projection type.     *      * @return int projection type     */    public int getProjectionType() {        return type;    }    /**     * Sets the projection ID used for determining equality. The     * projection ID String is intern()ed for efficient comparison.     */    protected void setProjectionID() {        projID = (":" + type + ":" + scale + ":" + ctrLat + ":" + ctrLon + ":"                + width + ":" + height + ":").intern();    }    /**     * Gets the projection ID used for determining equality.     *      * @return the projection ID, as an intern()ed String     */    public String getProjectionID() {        if (projID == null)            setProjectionID();        return projID;    }    /**     * Called when some fundamental parameters change.     * <p>     * Each projection will decide how to respond to this change. For     * instance, they may need to recalculate "constant" paramters     * used in the forward() and inverse() calls.     */    protected abstract void computeParameters();    /**     * Sets radian latitude to something sane.     * <p>     * Normalizes the latitude according to the particular projection.     *      * @param lat float latitude in radians     * @return float latitude (-PI/2 &lt;= y &lt;= PI/2)     * @see ProjMath#normalize_latitude(float, float)     * @see LatLonPoint#normalize_latitude(float)     */    public abstract float normalize_latitude(float lat);    /**     * Sets radian longitude to something sane.     *      * @param lon float longitude in radians     * @return float longitude (-PI &lt;= x &lt; PI)     * @see ProjMath#wrap_longitude(float)     * @see LatLonPoint#wrap_longitude(float)     */    public final static float wrap_longitude(float lon) {        return ProjMath.wrap_longitude(lon);    }    /**     * Stringify the projection.     *      * @return stringified projection     * @see #getProjectionID     */    public String toString() {        return (" radius=" + planetRadius + " ppm=" + pixelsPerMeter                + " center(" + ProjMath.radToDeg(ctrLat) + ","                + ProjMath.radToDeg(ctrLon) + ") scale=" + scale + " maxscale="                + maxscale + " minscale=" + minscale + " width=" + width                + " height=" + height + "]");    }    /**     * Test for equality.     *      * @param o Object to compare.     * @return boolean comparison     */    public boolean equals(Object o) {        if (o == null)            return false;        if (o instanceof Projection)            return getProjectionID() == ((Projection) o).getProjectionID();        return false;    }    /**     * Return hashcode value of projection.     *      * @return int hashcode     */    public int hashCode() {        return getProjectionID().hashCode();    }    /**     * Clone the projection.     *      * @return Projection clone of this one.     */    public Projection makeClone() {        return (Projection) this.clone();    }    /**     * Copies this projection.     *      * @return a copy of this projection.     */    public Object clone() {        try {            Proj proj = (Proj) super.clone();            if (mercator != null) {                proj.mercator = (Mercator) mercator.clone();            }            return proj;        } catch (CloneNotSupportedException e) {            // this shouldn't happen, since we are Cloneable            throw new InternalError();        }    }    /**     * Checks if a LatLonPoint is plot-able.     * <p>     * Call this to check and see if a LatLonPoint can be plotted.     * This is meant to be used for checking before projecting and     * rendering Point objects (bitmaps for instance).     *      * @param llpoint LatLonPoint     * @return boolean     */    public boolean isPlotable(LatLonPoint llpoint) {        return isPlotable(llpoint.getLatitude(), llpoint.getLongitude());    }    /**     * Forward project a LatLonPoint.     * <p>     * Forward projects a LatLon point into XY space. Returns a Point.     *      * @param llp LatLonPoint to be projected     * @return Point (new)     */    public final Point forward(LatLonPoint llp) {        return forward(llp.radlat_, llp.radlon_, new Point(0, 0), true);    }    /**     * Forward project lat,lon coordinates.     *      * @param lat float latitude in decimal degrees     * @param lon float longitude in decimal degrees     * @return Point (new)     */    public final Point forward(float lat, float lon) {        return forward(lat, lon, new Point(0, 0));    }    /**     * Inverse project a Point from x,y space to LatLon space.     *      * @param point x,y Point     * @return LatLonPoint (new)     */    public final LatLonPoint inverse(Point point) {        return inverse(point, new LatLonPoint());    }    /**     * Inverse project x,y coordinates.     *      * @param x integer x coordinate     * @param y integer y coordinate     * @return LatLonPoint (new)     * @see #inverse(Point)     */    public final LatLonPoint inverse(int x, int y) {        return inverse(x, y, new LatLonPoint());    }    /**     * Forward project a line.     *      * @param ll1 LatLonPoint     * @param ll2 LatLonPoint     * @param ltype LineType     * @param nsegs number of segments     * @return ArrayList     */    public ArrayList forwardLine(LatLonPoint ll1, LatLonPoint ll2, int ltype,                                 int nsegs) {        float[] rawllpts = { ll1.radlat_, ll1.radlon_, ll2.radlat_, ll2.radlon_ };        return forwardPoly(rawllpts, ltype, nsegs, false);    }    /**     * Forward project a lat/lon Line.     *      * @see #forwardLine(LatLonPoint, LatLonPoint, int, int)     */    public ArrayList forwardLine(LatLonPoint ll1, LatLonPoint ll2, int ltype) {        return forwardLine(ll1, ll2, ltype, -1);    }    /**     * Forward project a rectangle.     *      * @param ll1 LatLonPoint     * @param ll2 LatLonPoint     * @param ltype LineType     * @param nsegs number of segments     * @param isFilled filled poly?     * @return ArrayList     */    public ArrayList forwardRect(LatLonPoint ll1, LatLonPoint ll2, int ltype,                                 int nsegs, boolean isFilled) {        float[] rawllpts = { ll1.radlat_, ll1.radlon_, ll1.radlat_,                ll2.radlon_, ll2.radlat_, ll2.radlon_, ll2.radlat_,                ll1.radlon_,                // connect:                ll1.radlat_, ll1.radlon_ };        return forwardPoly(rawllpts, ltype, nsegs, isFilled);    }    public ArrayList forwardRect(LatLonPoint ll1, LatLonPoint ll2, int ltype,                                 int nsegs) {        return forwardRect(ll1, ll2, ltype, nsegs, false);    }    /**     * Forward project a lat/lon Rectangle.     *      * @see #forwardRect(LatLonPoint, LatLonPoint, int, int)     */    public ArrayList forwardRect(LatLonPoint ll1, LatLonPoint ll2, int ltype) {        return forwardRect(ll1, ll2, ltype, -1, false);    }    /**     * Forward project an arc.     *      * @param c LatLonPoint center     * @param radians boolean radius in radians?     * @param radius radius in radians or decimal degrees     * @param start the starting angle of the arc, zero being North     *        up. Units are dependent on radians parameter - the start     *        paramter is in radians if radians equals true, decimal     *        degrees if not.     * @param extent the angular extent angle of the arc, zero being     *        no length. Units are dependent on radians parameter -     *        the extent paramter is in radians if radians equals     *        true, decimal degrees if not.     */    public ArrayList forwardArc(LatLonPoint c, boolean radians, float radius,                                float start, float extent) {        return forwardArc(c,                radians,                radius,                -1,                start,                extent,                java.awt.geom.Arc2D.OPEN);    }    public ArrayList forwardArc(LatLonPoint c, boolean radians, float radius,                                int nverts, float start, float extent) {        return forwardArc(c,                radians,                radius,                nverts,                start,                extent,                java.awt.geom.Arc2D.OPEN);    }    /**     * Forward project a Lat/Lon Arc.     * <p>     * Arcs have the same restrictions as <a     * href="#poly_restrictions"> polys </a>.     *      * @param c LatLonPoint center of circle     * @param radians radius in radians or decimal degrees?     * @param radius radius of circle (0 &lt; radius &lt; 180)     * @param nverts number of vertices of the circle poly.     * @param start the starting angle of the arc, zero being North     *        up. Units are dependent on radians parameter - the start     *        paramter is in radians if radians equals true, decimal     *        degrees if not.     * @param extent the angular extent angle of the arc, zero being     *        no length. Units are dependent on radians parameter -     *        the extent paramter is in radians if radians equals     *        true, decimal degrees if not.     * @param arcType type of arc to create - see java.awt.geom.Arc2D     *        for (OPEN, CHORD, PIE). Arc2D.OPEN means that the just     *        the points for the curved edge will be provided.     *        Arc2D.PIE means that addition lines from the edge of the     *        curve to the center point will be added. Arc2D.CHORD     *        means a single line from each end of the curve will be     *        drawn.     */    public ArrayList forwardArc(LatLonPoint c, boolean radians, float radius,                                int nverts, float start, float extent,                                int arcType) {        // HACK-need better decision for number of vertices.        if (nverts < 3)            nverts = NUM_DEFAULT_CIRCLE_VERTS;        float[] rawllpts;        switch (arcType) {        case Arc2D.PIE:            rawllpts = new float[(nverts << 1) + 4];// *2 for pairs +4            // connect            break;        case Arc2D.CHORD:            rawllpts = new float[(nverts << 1) + 2];// *2 for pairs +2            // connect            break;        default:            rawllpts = new float[(nverts << 1)];// *2 for pairs, no        // connect        }        GreatCircle.earth_circle(c.radlat_, c.radlon_, (radians) ? radius                : ProjMath.degToRad(radius), (radians) ? start                : ProjMath.degToRad(start), (radians) ? extent                : ProjMath.degToRad(extent), nverts, rawllpts);        int linetype = LineType.Straight;        boolean isFilled = false;        switch (arcType) {        case Arc2D.PIE:            rawllpts[rawllpts.length - 4] = c.radlat_;            rawllpts[rawllpts.length - 3] = c.radlon_;        case Arc2D.CHORD:            rawllpts[rawllpts.length - 2] = rawllpts[0];            rawllpts[rawllpts.length - 1] = rawllpts[1];            // Need to do this for the sides, not the arc part.            linetype = LineType.GreatCircle;            isFilled = true;            break;        default:        // Don't need to do anything, defaults are already set.        }        // forward project the arc-poly.        return forwardPoly(rawllpts, linetype, -1, isFilled);    }    /**     * Forward project a circle.     *      * @param c LatLonPoint center     * @param radians boolean radius in radians?     * @param radius radius in radians or decimal degrees     */    public ArrayList forwardCircle(LatLonPoint c, boolean radians, float radius) {        return forwardCircle(c, radians, radius, -1, false);    }    public ArrayList forwardCircle(LatLonPoint c, boolean radians,                                   float radius, int nverts) {        return forwardCircle(c, radians, radius, nverts, false);    }    /**     * Forward project a Lat/Lon Circle.     * <p>

⌨️ 快捷键说明

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