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

📄 omline.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @return true if polyline false if not     */    public boolean isPolyline() {        return isPolyline;    }    /**     * Set the number of segments of the lat/lon line. (This is only     * for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and if     * &lt; 1, this value is generated internally).     *      * @param nsegs number of segment points     */    public void setNumSegs(int nsegs) {        this.nsegs = nsegs;    }    /**     * Get the number of segments of the lat/lon line. (This is only     * for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types).     *      * @return int number of segment points     */    public int getNumSegs() {        return nsegs;    }    /**     * Set the arc that is drawn between the points of a x-y or offset     * line.     */    public void setArc(ArcCalc ac) {        arc = ac;    }    /**     * Return the arc angle set for this line. Will only be set if it     * was set externally.     *      * @return arc angle in radians.     */    public ArcCalc getArc() {        return arc;    }    /**     * Prepare the line for rendering.     *      * @param proj Projection     * @return true if generate was successful     */    public boolean generate(Projection proj) {        setShape(null);        if (proj == null) {            Debug.message("omgraphic", "OMLine: null projection in generate!");            return false;        }        // reset the internals        isPolyline = false;        initLabelingDuringGenerate();        switch (renderType) {        case RENDERTYPE_XY:            if (arc != null) {                xpoints = new int[1][];                ypoints = new int[1][];                arc.generate(pts[0], pts[1], pts[2], pts[3]);                xpoints[0] = arc.getXPoints();                ypoints[0] = arc.getYPoints();            } else {                xpoints = new int[1][2];                ypoints = new int[1][2];                if (pts == null)                    return false;                xpoints[0][0] = pts[0];                ypoints[0][0] = pts[1];                xpoints[0][1] = pts[2];                ypoints[0][1] = pts[3];            }            shape = createShape(xpoints[0], ypoints[0], false);            break;        case RENDERTYPE_OFFSET:            if (!proj.isPlotable(latlons[0], latlons[1])) {                setNeedToRegenerate(true);// HMMM not the best flag                return false;            }            Point p1 = proj.forward(latlons[0], latlons[1]);            if (arc != null) {                xpoints = new int[1][];                ypoints = new int[1][];                arc.generate(p1.x + pts[0], p1.y + pts[1], p1.x + pts[2], p1.y                        + pts[3]);                xpoints[0] = arc.getXPoints();                ypoints[0] = arc.getYPoints();            } else {                xpoints = new int[1][2];                ypoints = new int[1][2];                xpoints[0][0] = p1.x + pts[0];                ypoints[0][0] = p1.y + pts[1];                xpoints[0][1] = p1.x + pts[2];                ypoints[0][1] = p1.y + pts[3];            }            shape = createShape(xpoints[0], ypoints[0], false);            break;        case RENDERTYPE_LATLON:            if (arc != null) {                p1 = proj.forward(latlons[0], latlons[1]);                Point p2 = proj.forward(latlons[2], latlons[3]);                xpoints = new int[1][];                ypoints = new int[1][];                arc.generate(p1.x, p1.y, p2.x, p2.y);                xpoints[0] = arc.getXPoints();                ypoints[0] = arc.getYPoints();                shape = createShape(xpoints[0], ypoints[0], false);                isPolyline = true;            } else {                ArrayList lines = proj.forwardLine(new LatLonPoint(latlons[0], latlons[1]),                        new LatLonPoint(latlons[2], latlons[3]),                        lineType,                        nsegs);                int size = lines.size();                xpoints = new int[(int) (size / 2)][0];                ypoints = new int[xpoints.length][0];                for (int i = 0, j = 0; i < size; i += 2, j++) {                    int[] xps = (int[]) lines.get(i);                    int[] yps = (int[]) lines.get(i + 1);                    xpoints[j] = xps;                    ypoints[j] = yps;                    GeneralPath gp = createShape(xps, yps, false);                    if (shape == null) {                        shape = gp;                    } else {                        ((GeneralPath) shape).append(gp, false);                    }                }                isPolyline = (lineType != LINETYPE_STRAIGHT);            }            break;        case RENDERTYPE_UNKNOWN:            System.err.println("OMLine.generate: invalid RenderType");            return false;        }        setLabelLocation(shape);        if (arrowhead != null) {            arrowhead.generate(this);        }        if (arc != null) {            // This will only do something if debugging is on.            arc.generate(proj);        }        setNeedToRegenerate(false);        return true;    }    /**     * Paint the line.     *      * @param g Graphics context to render into     */    public void render(Graphics g) {        if (!isRenderable()) {            return;        }        // Just to draw the matting for the arrowhead. The matting        // for the rest of the line will be taken care of in        // super.render().        if (arrowhead != null && isMatted() && g instanceof Graphics2D                && stroke instanceof BasicStroke) {            ((Graphics2D) g).setStroke(new BasicStroke(((BasicStroke) stroke).getLineWidth() + 2f));            setGraphicsColor(g, Color.black);            arrowhead.render(g);        }        super.render(g);        if (arrowhead != null) {            setGraphicsForEdge(g);            arrowhead.render(g);        }        if (arc != null) {            // This is a debugging thing, most times does nothing.            arc.render(g);        }    }    /**     * The OMLine should never render fill. It can think it does, if     * the geometry turns out to be curved. Returning false affects     * distance() and contains() methods.     */    public boolean shouldRenderFill() {        return false;    }    /**     * This takes the area out of OMLines that may look like they have     * area, depending on their shape. Checks to see what     * shouldRenderFill() returns (false by default) to decide how to     * measure this. If shouldRenderFill == true, the super.contains()     * method is returned, which assumes the line shape has area if it     * is curved. Otherwise, it returns true if the point is on the     * line.     */    public boolean contains(int x, int y) {        if (shouldRenderFill()) {            return super.contains(x, y);        } else {            return (distance(x, y) == 0);        }    }}

⌨️ 快捷键说明

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