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

📄 linkpoly.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/link/LinkPoly.java,v $// $RCSfile: LinkPoly.java,v $// $Revision: 1.4.2.1 $// $Date: 2004/10/14 18:27:08 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.util.Debug;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;/** * Read and write a Link protocol polyline/polygon. */public class LinkPoly implements LinkGraphicConstants, LinkPropertiesConstants {    /**     * Write a poly, with an array of alternating lat/lon points.     * Lat/lons in decimal degrees.     *      * @param llPoints alternating latitude and logitude points of     *        poly.     * @param units degrees or radians.     * @param lType straight, rhumb, great circle.     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(float[] llPoints, int units, int lType,                             LinkProperties properties, DataOutputStream dos)            throws IOException {        LinkPoly.write(llPoints, units, lType, -1, properties, dos);    }    /**     * Write a poly.     *      * @param llpoints alternating latitude and longitude points of     *        poly.     * @param units degrees or radians.     * @param lType straight, rhumb, great circle.     * @param nsegs number of segments to use to approimate curved     *        poly lines..     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(float[] llpoints, int units, int lType, int nsegs,                             LinkProperties properties, DataOutputStream dos)            throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_LATLON);        dos.writeInt(lType);        dos.writeInt(llpoints.length);        for (int i = 0; i < llpoints.length; i++) {            dos.writeFloat(llpoints[i]);        }        dos.writeInt(units);        dos.writeInt(nsegs);        properties.write(dos);    }    /**     * Write a poly.     *      * @param latpoints latitude points of poly.     * @param lonpoints longitude points of poly.     * @param units degrees or radians.     * @param lType straight, rhumb, great circle.     * @param nsegs number of segments to use to approimate curved     *        poly lines..     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(float[] latpoints, float[] lonpoints, int units,                             int lType, int nsegs, LinkProperties properties,                             DataOutputStream dos) throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_LATLON);        dos.writeInt(lType);        int length = latpoints.length;        // We only want to write out the points that have equal        // pairings.        if (lonpoints.length < latpoints.length) {            length = lonpoints.length;        }        dos.writeInt(length);        for (int i = 0; i < length; i++) {            dos.writeFloat(latpoints[i]);            dos.writeFloat(lonpoints[i]);        }        dos.writeInt(units);        dos.writeInt(nsegs);        properties.write(dos);    }    /**     * Write a poly.     *      * @param xypoints alternating x and y pixel locations of poly.     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(int[] xypoints, LinkProperties properties,                             DataOutputStream dos) throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_XY);        dos.writeInt(xypoints.length);        for (int i = 0; i < xypoints.length; i++) {            dos.writeInt(xypoints[i]);        }        properties.write(dos);    }    /**     * Write a poly in the response.     *      * @param xpoints horizontal pixel locations of poly.     * @param ypoints vertical pixel locations of poly.     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(int[] xpoints, int[] ypoints,                             LinkProperties properties, DataOutputStream dos)            throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_XY);        int numPoints = xpoints.length + ypoints.length;        dos.writeInt(numPoints);        for (int i = 0; i < numPoints / 2; i++) {            dos.writeInt(xpoints[i]);            dos.writeInt(ypoints[i]);        }        properties.write(dos);    }    /**     * Write a poly.     *      * @param latPoint the latitude anchor point of the poly.     * @param lonPoint the longitude anchor point of the poly.     * @param xypoints alternating x and y offset polygon points.     * @param cMode Coordinate Mode (Origin or Previous) that indicate     *        whether the x and y points are relative to the first     *        point, or to the previous point. .     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(float latPoint, float lonPoint, int[] xypoints,                             int cMode, LinkProperties properties,                             DataOutputStream dos) throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_OFFSET);        dos.writeFloat(latPoint);        dos.writeFloat(lonPoint);        dos.writeInt(xypoints.length);        for (int i = 0; i < xypoints.length; i++) {            dos.writeInt(xypoints[i]);        }        dos.writeInt(cMode);        properties.write(dos);    }    /**     * Write a poly.     *      * @param latPoint the latitude anchor point of the poly.     * @param lonPoint the longitude anchor point of the poly.     * @param xpoints horizontal pixel offset polygon points.     * @param ypoints vertical pixel offset polygon points.     * @param cMode Coordinate Mode (Origin or Previous) that indicate     *        whether the x and y points are relative to the first     *        point, or to the previous point. .     * @param properties description of drawing attributes.     * @param dos DataOutputStream     * @throws IOException     */    public static void write(float latPoint, float lonPoint, int[] xpoints,                             int[] ypoints, int cMode,                             LinkProperties properties, DataOutputStream dos)            throws IOException {        dos.write(Link.POLY_HEADER.getBytes());        dos.writeInt(GRAPHICTYPE_POLY);        dos.writeInt(RENDERTYPE_OFFSET);        dos.writeFloat(latPoint);        dos.writeFloat(lonPoint);        int numPoints = xpoints.length + ypoints.length;        dos.writeInt(numPoints);        for (int i = 0; i < numPoints / 2; i++) {            dos.writeInt(xpoints[i]);            dos.writeInt(ypoints[i]);        }        dos.writeInt(cMode);        properties.write(dos);    }    /**     * Write a poly to the link.     */    public static void write(OMPoly poly, Link link, LinkProperties props)            throws IOException {        switch (poly.getRenderType()) {        case OMPoly.RENDERTYPE_LATLON:            write(poly.getLatLonArray(),                    OMPoly.RADIANS,                    poly.getLineType(),                    poly.getNumSegs(),                    props,                    link.dos);            break;        case OMPoly.RENDERTYPE_XY:            write(poly.getXs(), poly.getYs(), props, link.dos);            break;        case OMPoly.RENDERTYPE_OFFSET:            write(poly.getLat(),                    poly.getLon(),                    poly.getXs(),                    poly.getYs(),                    poly.getCoordMode(),                    props,                    link.dos);            break;        default:            Debug.error("LinkPoly.write: poly rendertype unknown.");        }    }    /**     * Read the DataInputStream to create a OMPoly. Assumes the     * LinkPoly header has already been read.     *      * @param dis DataInputStream     * @return OMPoly     * @throws IOException     * @see com.bbn.openmap.omGraphics.OMPoly     */    public static OMPoly read(DataInputStream dis) throws IOException {        OMPoly poly = null;        int numPoints;        int[] xpoints, ypoints;        int renderType = dis.readInt();        switch (renderType) {        case RENDERTYPE_LATLON:            int lineType = dis.readInt();            numPoints = dis.readInt();            float[] llpoints = new float[numPoints];            for (int i = 0; i < numPoints; i++) {                llpoints[i] = dis.readFloat();            }            int units = dis.readInt();            int nsegs = dis.readInt();            if (Debug.debugging("linkdetail")) {                System.out.println("  Lat/Lon LinkPoly:");                System.out.println("  linetype = " + lineType);                System.out.println("  number of points = " + numPoints / 2);                //              for (int i = 0; i < numPoints; i+=2) {                //                  System.out.println(" Lat = " + llpoints[i] +                //                                     ", Lon = " + llpoints[i+1]);                //              }                System.out.println("  units = " + units);                System.out.println("  nsegs = " + nsegs);            }            poly = new OMPoly(llpoints, units, lineType, nsegs);            break;        case RENDERTYPE_XY:            numPoints = dis.readInt();            xpoints = new int[numPoints / 2];            ypoints = new int[numPoints / 2];            for (int i = 0; i < numPoints / 2; i += 1) {                xpoints[i] = dis.readInt();                ypoints[i] = dis.readInt();            }            if (Debug.debugging("linkdetail")) {                System.out.println("  X/Y LinkPoly:");                System.out.println("  number of points = " + numPoints / 2);                //              for (i = 0; i < numPoints; i++) {                //                  System.out.println(" X = " + xpoints[i] +                //                                     ", Y = " + ypoints[i]);                //              }            }            poly = new OMPoly(xpoints, ypoints);            break;        case RENDERTYPE_OFFSET:            float lat_1 = dis.readFloat();            float lon_1 = dis.readFloat();            numPoints = dis.readInt();            xpoints = new int[numPoints / 2];            ypoints = new int[numPoints / 2];            for (int i = 0; i < numPoints / 2; i += 1) {                xpoints[i] = dis.readInt();                ypoints[i] = dis.readInt();            }            int cMode = dis.readInt();            if (Debug.debugging("linkdetail")) {                System.out.println("  Offset LinkPoly:");                System.out.println("  lat = " + lat_1);                System.out.println("  lon = " + lon_1);                System.out.println("  number of points = " + numPoints / 2);                //              for (i = 0; i < numPoints; i+=2) {                //                  System.out.println(" Lat = " + llpoints[i] +                //                                     ", Lon = " + llpoints[i+1]);                //              }                System.out.println("  cMode = " + cMode);            }            poly = new OMPoly(lat_1, lon_1, xpoints, ypoints, cMode);            break;        default:        }        LinkProperties properties = new LinkProperties(dis);        if (poly != null) {            properties.setProperties(poly);        }        return poly;    }}

⌨️ 快捷键说明

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