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

📄 graticulelayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        return lines;    }    /** Create the ten degree lines. */    protected OMGraphicList constructTenDegreeLines() {        OMGraphicList lines = new OMGraphicList(3);        OMPoly currentLine;        // generate other parallels of latitude by creating series        // of polylines        for (int i = 1; i <= 8; i++) {            for (int j = -1; j < 2; j += 2) {                float lat = (float) (10 * i * j);                // generate parallel of latitude North/South of the                // equator                float[] llp = { lat, -180f, lat, -90f, lat, 0f, lat, 90f, lat,                        180f };                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                        : OMGraphic.LINETYPE_RHUMB);                currentLine.setLinePaint(tenDegreeColor);                lines.addOMGraphic(currentLine);            }        }        // generate lines of longitude        for (int i = 1; i < 18; i++) {            for (int j = -1; j < 2; j += 2) {                float lon = (float) (10 * i * j);                //not quite 90.0 for beautification reasons.                float[] llp = { 80f, lon, 0f, lon, -80f, lon };                if (MoreMath.approximately_equal(Math.abs(lon), 90f, 0.001f)) {                    llp[0] = 90f;                    llp[4] = -90f;                }                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                        : OMGraphic.LINETYPE_GREATCIRCLE);                currentLine.setLinePaint(tenDegreeColor);                lines.addOMGraphic(currentLine);            }        }        if (Debug.debugging("graticule")) {            Debug.output("GraticuleLayer.constructTenDegreeLines(): "                    + "constructed " + lines.size() + " graticule lines");        }        lines.generate(getProjection());        return lines;    }    /**     * Constructs the labels for the tens lines. Called from within     * the constructGraticuleLines if the showRuler variable is true.     * Usually called only if the ones and fives lines are not being     * drawn.     *      * @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 doLats do the latitude labels if true.     * @return OMGraphicList of labels.     */    protected OMGraphicList constructTensLabels(float up, float down,                                                float left, float right,                                                boolean doLats) {        OMGraphicList labels = 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        if ((south < 0 && south > -70) || south == 0) {            south -= 10;        }        int west = (int) Math.floor(left);        west -= (west % 10);        // for neg numbers, Mod raised it, lower it again        if ((west < 0 && west > -170) || west == 0) {            west -= 10;        }        int east = (int) Math.ceil(right);        if (east > 180)            east = 180;        int stepSize = 10;        OMText currentText;        // For calculating text locations        java.awt.Point point;        LatLonPoint llpoint;        Projection projection = getProjection();        if (doLats) {            // generate other parallels of latitude be creating series            // of labels            for (int i = south; i < north; i += stepSize) {                float lat = (float) i;                if ((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(), (int) 2, (int) -2, // Move                            // them                            // up a                            // little                            Integer.toString((int) lat), font, OMText.JUSTIFY_LEFT);                    currentText.setLinePaint(textColor);                    labels.addOMGraphic(currentText);                }            }        }        // generate labels of longitude        for (int i = west; i < east; i += stepSize) {            float lon = (float) i;            if ((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);                labels.addOMGraphic(currentText);            }        }        if (Debug.debugging("graticule")) {            Debug.output("GraticuleLayer.constructTensLabels(): "                    + "constructed " + labels.size() + " graticule labels");        }        labels.generate(projection);        return labels;    }    /** Constructs the Dateline and Prime Meridian lines. */    protected OMGraphicList constructMarkerLines() {        OMGraphicList lines = new OMGraphicList(3);        OMPoly currentLine;        // generate Prime Meridian and Dateline        for (int j = 0; j < 360; j += 180) {            float lon = (float) j;            float[] llp = { 90f, lon, 0f, lon, -90f, lon };            currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                    : OMGraphic.LINETYPE_GREATCIRCLE);            currentLine.setLinePaint(dateLineColor);            lines.addOMGraphic(currentLine);        }        // equator        float[] llp = { 0f, -180f, 0f, -90f, 0f, 0f, 0f, 90f, 0f, 180f };        // polyline        currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT                : OMGraphic.LINETYPE_GREATCIRCLE);        currentLine.setLinePaint(equatorColor);        lines.addOMGraphic(currentLine);        if (Debug.debugging("graticule")) {            Debug.output("GraticuleLayer.constructMarkerLines(): "                    + "constructed " + lines.size() + " graticule lines");        }        lines.generate(getProjection());        return lines;    }    /**     * Take a graphic list, and set all the items on the list to the     * line type specified, and project them into the current     * projection.     *      * @param list the list containing the lines to change.     * @param lineType the line type to cahnge the lines to.     */    protected void setLineTypeAndProject(OMGraphicList list, int lineType) {        int size = list.size();        OMGraphic graphic;        for (int i = 0; i < size; i++) {            graphic = list.getOMGraphicAt(i);            graphic.setLineType(lineType);            graphic.generate(getProjection());        }    }    //----------------------------------------------------------------------    // GUI    //----------------------------------------------------------------------    /** The user interface palette for the DTED layer. */    protected Box palette = null;    /** Creates the interface palette. */    public java.awt.Component getGUI() {        if (palette == null) {            if (Debug.debugging("graticule"))                Debug.output("GraticuleLayer: creating Graticule Palette.");            palette = Box.createVerticalBox();            JPanel layerPanel = PaletteHelper.createPaletteJPanel(i18n.get(GraticuleLayer.class,                    "layerPanel",                    "Graticule Layer Options"));            ActionListener al = new ActionListener() {                public void actionPerformed(ActionEvent e) {                    String ac = e.getActionCommand();                    if (ac.equalsIgnoreCase(ShowRulerProperty)) {                        JCheckBox jcb = (JCheckBox) e.getSource();                        showRuler = jcb.isSelected();                    } else if (ac.equalsIgnoreCase(ShowOneAndFiveProperty)) {                        JCheckBox jcb = (JCheckBox) e.getSource();                        showOneAndFiveLines = jcb.isSelected();                    } else {                        Debug.error("Unknown action command \"" + ac                                + "\" in GraticuleLayer.actionPerformed().");                    }                }            };            showRulerButton = new JCheckBox(i18n.get(GraticuleLayer.class,                    "showRulerButton",                    "Show Lat/Lon Labels"), showRuler);            showRulerButton.addActionListener(al);            showRulerButton.setActionCommand(ShowRulerProperty);            show15Button = new JCheckBox(i18n.get(GraticuleLayer.class,                    "show15Button",                    "Show 1, 5 Degree Lines"), showOneAndFiveLines);            show15Button.addActionListener(al);            show15Button.setActionCommand(ShowOneAndFiveProperty);//            showBelow1Button = new JCheckBox(i18n.get(GraticuleLayer.class,//                    "showSub1Button",//                    "Show Sub-1 Degree Lines"), showBelowOneLines);//            showBelow1Button.addActionListener(al);//            showBelow1Button.setActionCommand(ShowBelowOneProperty);            layerPanel.add(showRulerButton);            layerPanel.add(show15Button);//            layerPanel.add(showBelow1Button);            palette.add(layerPanel);            JPanel subbox3 = new JPanel(new GridLayout(0, 1));            JButton setProperties = new JButton(i18n.get(GraticuleLayer.class,                    "setProperties",                    "Preferences"));            setProperties.setActionCommand(DisplayPropertiesCmd);            setProperties.addActionListener(this);            subbox3.add(setProperties);            JButton redraw = new JButton(i18n.get(GraticuleLayer.class,                    "redraw",                    "Redraw Graticule Layer"));            redraw.setActionCommand(RedrawCmd);            redraw.addActionListener(this);            subbox3.add(redraw);            palette.add(subbox3);        }        return palette;    }    //----------------------------------------------------------------------    // ActionListener interface implementation    //----------------------------------------------------------------------    /**     * Used just for the redraw button.     */    public void actionPerformed(ActionEvent e) {        super.actionPerformed(e);        String command = e.getActionCommand();        if (command == RedrawCmd) {            //redrawbutton            if (isVisible()) {                doPrepare();            }        }    }}

⌨️ 快捷键说明

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