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

📄 shapelinkserver.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/shape/ShapeLinkServer.java,v $// $RCSfile: ShapeLinkServer.java,v $// $Revision: 1.3.2.1 $// $Date: 2004/10/14 18:27:09 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link.shape;import java.awt.Color;import java.io.File;import java.io.IOException;import java.net.Socket;import java.util.Vector;import com.bbn.openmap.Environment;import com.bbn.openmap.util.ColorFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.layer.link.*;import com.bbn.openmap.layer.shape.*;/** * This LinkServer provides graphics from ShapeFiles. The LinkLayer * can provide several properties that can control how these graphics * are to be rendered (defined in the .propertiesURL file for the * layer): * <P> *  * <pre> *  *   *  # Graphic edge color *  lineColor=AARRGGBB *  # Graphic fill Color *  fillColor=AARRGGBB *  # Graphic selected edge color *  highlightColor=AARRGGBB *  # Graphic edge pixel width *  lineWidth=pixel width *   *   * </pre> */public class ShapeLinkServer extends LinkServer implements        LinkPropertiesConstants {    protected LinkSpatialIndex spatialIndex;    /** The color to outline the shapes. */    protected Color lineColor = Color.black;    /** The color to fill the shapes. */    protected Color fillColor = ColorFactory.createColor(0, 0, 0, 0, true);    protected LinkProperties lineProperties;    public ShapeLinkServer(Socket socket, String shapeFile,            String spatialIndexFile) {        super(socket);        locateAndSetShapeData(shapeFile, spatialIndexFile);    }    public void finalize() {        if (Debug.debugging("gc")) {            Debug.output("ShapeLinkServer instance gc'd - client gone");        }    }    /**     * handleClient is a method that listens to the link to a client,     * and responds to requests that are made.     */    public void handleClient() throws IOException {        boolean validQuery;        try {            while (true) {                link.readAndParse();                validQuery = false;                // For instance, you could do something like this...                LinkMapRequest graphicsQuery = link.getMapRequest();                //          LinkActionRequest gestureQuery =                // link.getActionRequest();                if (graphicsQuery != null) {                    getRectangle(graphicsQuery, link);                    validQuery = true;                }                graphicsQuery = null;                //              if (gestureQuery != null){                //                  handleGesture(gestureQuery, link);                //                  validQuery = true;                //              }                if (!validQuery) {                    huh(link);                }            }        } catch (IOException ioe) {            spatialIndex = null;            lineColor = null;            fillColor = null;            lineProperties = null;            throw ioe;        }    }    public void setFillColor(Color fColor) {        fillColor = fColor;    }    public void setLineColor(Color lColor) {        lineColor = lColor;    }    public Color getFillColor() {        return fillColor;    }    public Color getLineColor() {        return lineColor;    }    public void getRectangle(LinkMapRequest query, Link link)            throws IOException {        String value;        if (spatialIndex == null)            link.end(Link.END_TOTAL);        LinkProperties args = query.getProperties();        LinkGraphicList lgl = new LinkGraphicList(link, args);        //      System.out.println(args);        lineProperties = new LinkProperties();        value = args.getProperty(LPC_LINECOLOR);        if (value != null)            lineProperties.setProperty(LPC_LINECOLOR, value);        value = args.getProperty(LPC_FILLCOLOR);        if (value != null)            lineProperties.setProperty(LPC_FILLCOLOR, value);        value = args.getProperty(LPC_HIGHLIGHTCOLOR);        if (value != null)            lineProperties.setProperty(LPC_HIGHLIGHTCOLOR, value);        value = args.getProperty(LPC_LINEWIDTH);        if (value != null)            lineProperties.setProperty(LPC_LINEWIDTH, value);        LinkBoundingPoly[] bounds = query.getBoundingPolys();        for (int i = 0; i < bounds.length; i++) {            fetchGraphics((double) bounds[i].minX,                    (double) bounds[i].minY,                    (double) bounds[i].maxX,                    (double) bounds[i].maxY,                    lgl,                    lineProperties);        }        lgl.end(Link.END_TOTAL);    }    /**     *       */    protected void fetchGraphics(double xmin, double ymin, double xmax,                                 double ymax, LinkGraphicList lgl,                                 LinkProperties properties) throws IOException {        Debug.message("shape", "fetchGraphics: " + xmin + ", " + ymin + ", "                + xmax + ", " + ymax);        try {            ESRIRecord records[] = spatialIndex.locateRecords(xmin,                    ymin,                    xmax,                    ymax);            int nRecords = records.length;            ESRILinkRecord rec;            for (int i = 0; i < nRecords; i++) {                if (records[i] instanceof ESRILinkRecord) {                    rec = (ESRILinkRecord) records[i];                    rec.writeLinkGraphics(lgl, properties);                }            }        } catch (java.io.IOException ex) {            if (Debug.debugging("shape")) {                ex.printStackTrace();            }            return;        } catch (com.bbn.openmap.io.FormatException fe) {            Debug.error("ShapeLinkServer caught FormatException in the file");            fe.printStackTrace();        }    }    protected void locateAndSetShapeData(String shapeFileName,                                         String spatialIndexFileName) {        Debug.message("shape", "ShapeLinkServer: Reading shape file.");        File spatialIndexFile = new File(spatialIndexFileName);        if (spatialIndexFile.isAbsolute()) {            //          System.out.println("Absolute!");            try {                spatialIndex = new LinkSpatialIndex(spatialIndexFileName, shapeFileName);            } catch (java.io.IOException e) {                if (Debug.debugging("shape")) {                    e.printStackTrace();                }            }        } else {            //          System.out.println("Relative!");            Vector dirs = Environment.getClasspathDirs();            int nDirs = dirs.size();            if (nDirs > 0) {                for (int i = 0; i < nDirs; i++) {                    String dir = (String) dirs.elementAt(i);                    File sif = new File(dir, spatialIndexFileName);                    if (sif.isFile()) {                        File sf = new File(dir, shapeFileName);                        try {                            //                          System.out.println(sif.toString());                            //                          System.out.println(sf.toString());                            spatialIndex = new LinkSpatialIndex(sif.toString(), sf.toString());                            break;                        } catch (java.io.IOException e) {                            if (Debug.debugging("shape")) {                                e.printStackTrace();                            }                        }                    }                }                if (spatialIndex == null) {                    System.err.println("Unable to find file: " + shapeFileName);                    System.err.println("Unable to find file: "                            + spatialIndexFileName);                }            } else {                System.err.println("No directories in CLASSPATH!");                System.err.println("Unable to locate file: " + shapeFileName);                System.err.println("Unable to locate file: "                        + spatialIndexFileName);            }        }    }}

⌨️ 快捷键说明

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