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

📄 profilegenerator.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                max = tmp;            heights[i] = tmp;        }        // get the picture drawn and written        createGIFFile(total_distance, max, distances, heights);    }    /**     * Create the image and write it the location.     *      * @param distance total length of line, in pixels     * @param max highest point, in meters of all the heights in the     *        line.     * @param post_dist array of pixel distances between the points     * @param post_height the array of heights     */    protected void createGIFFile(int distance, int max, int[] post_dist,                                 int[] post_height) {        int box_height_buffer = 20;        int gif_height_buffer = 20;        int gif_width_buffer = 20;        int text_width = 100;        int box_height = max + (box_height_buffer * 2);        int box_width = distance;        int gif_height = box_height + (gif_height_buffer * 2);        int gif_width = box_width + (gif_width_buffer * 2) + text_width;        AcmeGifFormatter formatter = new AcmeGifFormatter();        java.awt.Graphics graphics = formatter.getGraphics(gif_width,                gif_height);//        Color gray10 = new Color(25, 25, 25);        Color gray50 = new Color(128, 128, 128);//        Color gray75 = new Color(191, 191, 191);        Color gray90 = new Color(230, 230, 230);        Debug.message("terrain",                "ProfileGenerator gif creation: drawing boundaries");        /* Fill in the generic colors */        graphics.setColor(gray90);        graphics.fillRect(0, 0, gif_width, gif_height);        graphics.setColor(gray50);        graphics.fillRect(gif_width_buffer,                gif_height_buffer,                box_width,                box_height);        Debug.message("terrain", "ProfileGenerator gif creation: drawing edges");        // outside edge        graphics.setColor(Color.black);        graphics.drawRect(0, 0, gif_width - 1, gif_height - 1);        // inside edge        graphics.drawRect(gif_width_buffer,                gif_height_buffer,                box_width,                box_height);        graphics.setColor(Color.yellow);        // 0 height line        graphics.drawLine(gif_width_buffer + 1,                gif_height_buffer + box_height - box_height_buffer,                gif_width_buffer + box_width - 1,                gif_height_buffer + box_height - box_height_buffer);        // These are the horizontal reference lines in the image.        graphics.setColor(Color.black);        FontMetrics f = graphics.getFontMetrics();        Debug.message("terrain",                "ProfileGenerator gif creation: drawing level lines");        for (int i = 1; i < 9; i++) {            graphics.drawLine(gif_width_buffer, gif_height_buffer + box_height                    - box_height_buffer - (max * i / 8), gif_width_buffer                    + box_width + 5, gif_height_buffer + box_height                    - box_height_buffer - (max * i / 8));            int meters = max * i / 8;            int feet = (int) (meters * 3.2);            String lineLabel = meters + "m / " + feet + "ft";//            byte[] lineLabelBytes = lineLabel.getBytes();            graphics.drawString(lineLabel,                    gif_width_buffer + box_width + 10,                    gif_height_buffer + box_height - box_height_buffer                            - (max * i / 8) + (f.getAscent() / 2));        }//        int last_x = gif_width_buffer + 1;//        int last_height = gif_height_buffer + box_height - box_height_buffer//                - post_height[0];        int total_distance = 0;        Debug.message("terrain",                "ProfileGenerator gif creation: drawing profile");        graphics.setColor(Color.red);        for (int i = 1; i < post_height.length; i++) {            graphics.drawLine(gif_width_buffer + total_distance,                    gif_height_buffer + box_height - box_height_buffer                            - post_height[i - 1],                    gif_width_buffer + post_dist[i] + total_distance,                    gif_height_buffer + box_height - box_height_buffer                            - post_height[i]);            total_distance += post_dist[i];        }        javax.swing.ImageIcon ii = new javax.swing.ImageIcon(formatter.getBufferedImage());        javax.swing.JFrame jf = com.bbn.openmap.util.PaletteHelper.getPaletteWindow(new javax.swing.JLabel(ii),                "Path Profile",                (ComponentListener) null);        jf.show();        //      byte[] imageBytes = formatter.getImageBytes();        //      String tmppath = null;        //      try {        //          String tmpDir = Environment.get(Environment.TmpDir);        //          if (tmpDir != null) {        //              tmppath = tmpDir + File.separator + "openmap-" +        //                  Environment.timestamp() + ".gif";        //              FileOutputStream fs = new FileOutputStream(tmppath);        //              fs.write(imageBytes);        //              fs.close(); // close the streams        //              String url = "file://" + tmppath;        //              layer.fireRequestURL(url);        //          } else {        //              Debug.error("ProfileGenerator: can't create image file,        // because the openmap.TempDirectory was not set.");        //          }        //      } catch (IOException e) {        //          Debug.error("ProfileGenerator: Cannot write to temp file:"        // +        //                      Environment.get("line.separator") +        //                      "\"" + tmppath + "\"");        //      }        //      String imageString = new String(imageBytes);        //      layer.fireRequestBrowserContent(imageString);    }    /**     * Used to keep track of another point for the line, as determined     * by the state machine.     *      * @param event Mouse event that supplies the location     */    protected void addProfileEvent(MouseEvent event) {        LatLonPoint llp = proj.inverse(event.getX(), event.getY());        if (lastMouse != null) {            // Check for proximity of the click, since a double            // click means the end of the line.            if ((Math.abs(lastMouse.getX() - event.getX()) > MAX_SPACE_BETWEEN_PIXELS)                    || (Math.abs(lastMouse.getY() - event.getY()) > MAX_SPACE_BETWEEN_PIXELS)) {                // The line may need to be broken up into smaller                // segments in order for it to be a true straight                // line, to figure out the segments. The interior                // points are added to the vector.                addGreatCirclePoints(lastMouse, event);                // Now add the end point to the vector                coords.addElement(llp);                // The xy points don't need the interior points, the                // line gets these points and figures them out for                // itself. This may be redundant is some way.                xypoints.addElement(event.getPoint());            }        } else {            coords.addElement(llp);            xypoints.addElement(event.getPoint());        }        lastMouse = event;        // Reset the line to have all the new points        profileLine.setLocation(setLLPoints(), OMGraphic.RADIANS);        profileLine.generate(proj);    }    /**     * Figure out the internal points to create a great circle line     * between two points on the screen. The interior points are added     * to the coords array, but not to the xy points array.     *      * @param beginning the starting mouse event     * @param ending the ending mouse event     */    protected void addGreatCirclePoints(MouseEvent beginning, MouseEvent ending) {        LatLonPoint beg = proj.inverse(beginning.getX(), beginning.getY());        LatLonPoint end = proj.inverse(ending.getX(), ending.getY());        int num_points = (TerrainLayer.numPixelsBetween(beginning.getX(),                beginning.getY(),                ending.getX(),                ending.getY()) - 2)                / MAX_SPACE_BETWEEN_PIXELS;        float[] radPoints = GreatCircle.great_circle(beg.radlat_,                beg.radlon_,                end.radlat_,                end.radlon_,                num_points,                true);        for (int i = 0; i < radPoints.length; i++) {            coords.addElement(new LatLonPoint(radPoints[i], radPoints[i + 1], true));            Point pt = new Point();            proj.forward(radPoints[i], radPoints[i + 1], pt, true);            xypoints.addElement(pt);            //        System.out.println("addCGPoints: point " + i + " lat="            // +            //                           RadianPoint.radToDeg(radPoints[i].lat) + ", lon=" +            //                           RadianPoint.radToDeg(radPoints[i].lon) + ", x=" +            //                           (short)pt.x + ", y=" + (short)pt.y);            i++;        }    }}

⌨️ 快捷键说明

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