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

📄 graticulelayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        tenDegreeLines = null;        if (showOneAndFiveLines || showRuler || showBelowOneLines) {            float left = projection.getUpperLeft().getLongitude();            float right = projection.getLowerRight().getLongitude();            float up = projection.getUpperLeft().getLatitude();            float down = projection.getLowerRight().getLatitude();            if (up > 80.0f)                up = 80.0f;            if (down > 80.0f)                down = 80f; // unlikely            if (up < -80.0f)                up = -80.0f; // unlikely            if (down < -80)                down = -80.0f;            int showWhichLines = evaluateSpacing(up, down, left, right);            // Find out whether we need to do one or two queries,            // depending on if we're straddling the dateline.            if ((left > 0 && right < 0) || (left > right)                    || (Math.abs(left - right) < 1)) {                // Test to draw the ones and fives, which will also do                // the labels.                if (showWhichLines != SHOW_TENS) {                    newgraphics.add(constructGraticuleLines(up,                            down,                            left,                            180.0f,                            showWhichLines));                    newgraphics.add(constructGraticuleLines(up,                            down,                            -180.0f,                            right,                            showWhichLines));                } else if (showRuler) { // Just do the labels for the                    // tens lines                    newgraphics.add(constructTensLabels(up,                            down,                            left,                            180.0f,                            true));                    newgraphics.add(constructTensLabels(up,                            down,                            -180.0f,                            right,                            false));                }            } else {                // Test to draw the ones and fives, which will also do                // the labels.                if (showWhichLines != SHOW_TENS) {                    newgraphics = constructGraticuleLines(up,                            down,                            left,                            right,                            showWhichLines);                } else if (showRuler) { // Just do the labels for the                    // tens lines                    newgraphics.add(constructTensLabels(up,                            down,                            left,                            right,                            true));                }            }        }        OMGraphicList list;        if (tenDegreeLines == null) {            list = constructTenDegreeLines();            tenDegreeLines = list;        } else {            synchronized (tenDegreeLines) {                setLineTypeAndProject(tenDegreeLines,                        boxy ? OMGraphic.LINETYPE_STRAIGHT                                : OMGraphic.LINETYPE_RHUMB);            }        }        if (markerLines == null) {            list = constructMarkerLines();            markerLines = list;        } else {            synchronized (markerLines) {                setLineTypeAndProject(markerLines,                        boxy ? OMGraphic.LINETYPE_STRAIGHT                                : OMGraphic.LINETYPE_RHUMB);            }        }        newgraphics.add(markerLines);        newgraphics.add(tenDegreeLines);        if (Debug.debugging("graticule")) {            Debug.output("GraticuleLayer.constructGraticuleLines(): "                    + "constructed " + newgraphics.size() + " graticule lines");        }        return newgraphics;    }    /**     * Figure out which graticule lines should be drawn based on the     * treshold set in the layer, and the coordinates of the screen.     * Method checks for crossing of the dateline, but still assumes     * that the up and down latitude coordinates are less than     * abs(+/-80). This is because the projection shouldn't give     * anything above 90 degrees, and we limit the lines to less than     * 80..     *      * @param up northern latitude corrdinate, in decimal degrees,     * @param down southern latitude coordinate, in decimal degrees.     * @param left western longitude coordinate, in decimal degrees,     * @param right eastern longitude coordinate, in decimal degrees.     * @return which lines should be shown, either SHOW_TENS,     *         SHOW_FIVES and SHOW_ONES.     */    protected int evaluateSpacing(float up, float down, float left, float right) {        int ret = SHOW_TENS;        // Set the flag for when labels are wanted, but not the 1 and        // 5 lines;        if (!showOneAndFiveLines && !showBelowOneLines) {            return ret;        }        // Find the north - south difference        float nsdiff = up - down;        // And the east - west difference        float ewdiff;        // Check for straddling the dateline -west is positive while        // right is negative, or, in a big picture view, the west is        // positive, east is positive, and western hemisphere is        // between them.        if ((left > 0 && right < 0) || (left > right)                || (Math.abs(left - right) < 1)) {            ewdiff = (180.0f - left) + (right + 180.0f);        } else {            ewdiff = right - left;        }        // And use the lesser of the two.        float diff = (nsdiff < ewdiff) ? nsdiff : ewdiff;        // number of 10 degree lines        if ((diff / 10) <= (float) threshold)            ret = SHOW_FIVES;        // number of five degree lines        if ((diff / 5) <= (float) threshold)            ret = SHOW_ONES;        return ret;    }    /**     * Construct the five degree and one degree graticule lines,     * depending on the showWhichLines setting. Assumes that the     * coordinates passed in do not cross the dateline, and that the     * up is not greater than 80 and that the south is not less than     * -80.     *      * @param up northern latitude corrdinate, in decimal degrees,     * @param down southern latitude coordinate, in decimal degrees.     * @param left western longitude coordinate, in decimal degrees,     * @param right eastern longitude coordinate, in decimal degrees.     * @param showWhichLines indicator for which level of lines should     *        be included, either SHOW_FIVES or SHOW_ONES. SHOW_TENS     *        could be there, too, but then we wouldn't do anything.     */    protected OMGraphicList constructGraticuleLines(float up, float down,                                                    float left, float right,                                                    int showWhichLines) {        OMGraphicList lines = new OMGraphicList();        // Set the line limits for the lat/lon lines...        int north = (int) Math.ceil(up);        if (north > 80)            north = 80;        int south = (int) Math.floor(down);        south -= (south % 10); // Push down to the lowest 10 degree        // line.        // for neg numbers, Mod raised it, lower it again. Also        // handle straddling the equator.        if ((south < 0 && south > -80) || south == 0)            south -= 10;        int west = (int) Math.floor(left);        west -= (west % 10);        // for neg numbers, Mod raised it, lower it again. Also        // handle straddling the prime meridian.        if ((west < 0 && west > -180) || west == 0)            west -= 10;        int east = (int) Math.ceil(right);        if (east > 180)            east = 180;        int stepSize;        // Choose how far apart the lines will be.        stepSize = ((showWhichLines == SHOW_ONES) ? 1 : 5);        float[] llp;        OMPoly currentLine;        OMText currentText;        // For calculating text locations        java.awt.Point point;        LatLonPoint llpoint;        Projection projection = getProjection();        // generate other parallels of latitude be creating series        // of polylines        for (int i = south; i < north; i += stepSize) {            float lat = (float) i;            // generate parallel of latitude North/South of the            // equator            if (west < 0 && east > 0) {                llp = new float[6];                llp[2] = lat;                llp[3] = 0f;                llp[4] = lat;                llp[5] = east;            } else {                llp = new float[4];                llp[2] = lat;                llp[3] = east;            }            llp[0] = lat;            llp[1] = west;            // Do not duplicate the 10 degree line.            if ((lat % 10) != 0) {                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                        : OMGraphic.LINETYPE_RHUMB);                if ((lat % 5) == 0) {                    currentLine.setLinePaint(fiveDegreeColor);                } else {                    currentLine.setLinePaint(oneDegreeColor);                }                lines.addOMGraphic(currentLine);            }            if (showRuler && (lat % 2) == 0) {                if (boxy) {                    point = projection.forward(lat, west);                    point.x = 0;                    llpoint = projection.inverse(point);                } else {                    llpoint = new LatLonPoint(lat, west);                    while (projection.forward(llpoint).x < 0) {                        llpoint.setLongitude(llpoint.getLongitude() + stepSize);                    }                }                currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),                // Move them up a little                        (int) 2, (int) -2, Integer.toString((int) lat), font, OMText.JUSTIFY_LEFT);                currentText.setLinePaint(textColor);                lines.addOMGraphic(currentText);            }        }        // generate lines of longitude        for (int i = west; i < east; i += stepSize) {            float lon = (float) i;            if (north < 0 && south > 0) {                llp = new float[6];                llp[2] = 0f;                llp[3] = lon;                llp[4] = south;                llp[5] = lon;            } else {                llp = new float[4];                llp[2] = south;                llp[3] = lon;            }            llp[0] = north;            llp[1] = lon;            if ((lon % 10) != 0) {                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                        : OMGraphic.LINETYPE_GREATCIRCLE);                if ((lon % 5) == 0) {                    currentLine.setLinePaint(fiveDegreeColor);                } else {                    currentLine.setLinePaint(oneDegreeColor);                }                lines.addOMGraphic(currentLine);            }            if (showRuler && (lon % 2) == 0) {                if (boxy) {                    point = projection.forward(south, lon);                    point.y = projection.getHeight();                    llpoint = projection.inverse(point);                } else {                    llpoint = new LatLonPoint(south, lon);                    while (projection.forward(llpoint).y > projection.getHeight()) {                        llpoint.setLatitude(llpoint.getLatitude() + stepSize);                    }                }                currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),                // Move them up a little                        (int) 2, (int) -5, Integer.toString((int) lon), font, OMText.JUSTIFY_CENTER);                currentText.setLinePaint(textColor);                lines.addOMGraphic(currentText);            }        }        if (Debug.debugging("graticule")) {            Debug.output("GraticuleLayer.constructTenDegreeLines(): "                    + "constructed " + lines.size() + " graticule lines");        }        lines.generate(projection);

⌨️ 快捷键说明

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