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

📄 areahandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        // This is handled properly yet. The PoliticalArea should be        // updated to handle URLs for area points, and have different        // icons for different areas.        // String defaultPointImageURLString =        // props.getProperty(prefix + pointImageURLProperty);        // Now, match the attributes to the graphics. Find the        // indexes of the name and the search key. Also figure out        // which areas have special coloring needs.        keyIndex = PropUtils.intFromProperties(props,                prefix + keyIndexProperty,                keyIndex);        nameIndex = PropUtils.intFromProperties(props, prefix                + nameIndexProperty, nameIndex);        String areas = props.getProperty(prefix + areasProperty);        if (areas == null)            areas = "";        StringTokenizer tokenizer = new StringTokenizer(areas, " ");        // All this uses the properties to set the individual colors        // of any area        String currentArea;        while (tokenizer.hasMoreTokens()) {            currentArea = tokenizer.nextToken();            PoliticalArea newParams = new PoliticalArea(currentArea);            if (Debug.debugging("areas")) {                Debug.output("AreaHandler: setting SPECIALIZED attributes for \""                        + newParams.id + "\"");            }            areasItems.addElement(currentArea);            newParams.drawingAttributes = new DrawingAttributes(prefix                    + areasProperty + "." + currentArea, props);            politicalAreas.put(newParams.id.toUpperCase().intern(), newParams);        }        if (Debug.debugging("areas")) {            Debug.output("AreaHandler: finished initialization");        }    }    /**     * Read a cache of OMGraphics     */    public OMGraphicList readCachedGraphics(URL url) throws java.io.IOException {        if (Debug.debugging("areas")) {            Debug.output("Reading cached graphics");        }        OMGraphicList omgraphics = new OMGraphicList();        if (url != null) {            omgraphics.readGraphics(url);        }        return omgraphics;    }    /**     * Get all the graphics from the shapefile, colored appropriately.     */    public OMGraphicList getGraphics() {        return getGraphics(90f, -180f, -90f, 180f);    }    /**     * Get the graphics for a particular lat/lon area.     *      * @param ulLat upper left latitude, in decimal degrees.     * @param ulLon upper left longitude, in decimal degrees.     * @param lrLat lower right latitude, in decimal degrees.     * @param lrLon lower right longitude, in decimal degrees.     * @return OMGraphicList     */    public OMGraphicList getGraphics(float ulLat, float ulLon, float lrLat,                                     float lrLon) {        if (cacheURL != null) {            return omgraphics;        }        if (spatialIndex == null) {            return new OMGraphicList();        }        if (politicalAreas == null) {            initialize(originalPrefix, originalProperties);        }        OMGraphicList list = null;        DrawingAttributes drawParams;        // check for dateline anomaly on the screen. we check for        // ulLon >=        // lrLon, but we need to be careful of the check for equality        // because        // of floating point arguments...        if ((ulLon > lrLon)                || MoreMath.approximately_equal(ulLon, lrLon, .001f)) {            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getGraphics(): Dateline is on screen");            }            double ymin = (double) Math.min(ulLat, lrLat);            double ymax = (double) Math.max(ulLat, lrLat);            try {                ESRIRecord records1[] = spatialIndex.locateRecords(ulLon,                        ymin,                        180.0d,                        ymax);                ESRIRecord records2[] = spatialIndex.locateRecords(-180.0d,                        ymin,                        lrLon,                        ymax);                int nRecords1 = records1.length;                int nRecords2 = records2.length;                list = new OMGraphicList(nRecords1 + nRecords2);                for (int i = 0; i < nRecords1; i++) {                    drawParams = getDrawParams(records1[i].getRecordNumber());                    list.addOMGraphic(recordList(records1[i], drawParams));                }                for (int i = 0; i < nRecords2; i++) {                    drawParams = getDrawParams(records2[i].getRecordNumber());                    list.addOMGraphic(recordList(records2[i], drawParams));                }            } catch (java.io.IOException ex) {                ex.printStackTrace();            } catch (FormatException fe) {                fe.printStackTrace();            }        } else {            double xmin = (double) Math.min(ulLon, lrLon);            double xmax = (double) Math.max(ulLon, lrLon);            double ymin = (double) Math.min(ulLat, lrLat);            double ymax = (double) Math.max(ulLat, lrLat);            try {                ESRIRecord records[] = spatialIndex.locateRecords(xmin,                        ymin,                        xmax,                        ymax);                int nRecords = records.length;                list = new OMGraphicList(nRecords);                for (int i = 0; i < nRecords; i++) {                    drawParams = getDrawParams(records[i].getRecordNumber());                    list.addOMGraphic(recordList(records[i], drawParams));                }            } catch (java.io.IOException ex) {                ex.printStackTrace();            } catch (FormatException fe) {                fe.printStackTrace();            }        }        return list;    }    /**     * Return the graphic name, given the infofile vector on the     * graphic. The AreaHandler knows which one is the name. Returns     * an empty string if something goes wrong.     */    public String getName(Vector vector) {        try {            String string = (String) vector.elementAt(nameIndex);            return string;        } catch (ClassCastException cce) {        }        return "";    }    /**     * Get the name of the object at record number. The record number     * is the shapefile record number, which is one greater than the     * index number. Returns an empty string if something goes wrong.     */    public String getName(Integer integer) {        try {            if (infoFile != null) {                Vector vector = infoFile.getRecord(integer.intValue() - 1);                if (vector != null) {                    return (String) vector.elementAt(nameIndex);                }            } else if (dbfModel != null) {                Object obj = dbfModel.getValueAt(integer.intValue() - 1,                        nameIndex);                if (obj != null) {                    if (obj instanceof String) {                        return (String) obj;                    } else {                        return obj.toString();                    }                }            }        } catch (ClassCastException cce) {        }        return "";    }    /**     * Given the shapefile record number, find the drawing parameters     * that should be used for the shape. Note, this recordNumber is     * the shapefile record number, which starts at one. All our     * indexes start at 0, so this is taken into account here. Don't     * make the adjustment elsewhere. Returns the default coloring if     * the key for the drawing parameters isn't found.     */    public DrawingAttributes getDrawParamsFromCSV(int recordNumber) {        if (infoFile == null) {            return drawingAttributes;        }        // OFF BY ONE!!! The shape record numbers        // assigned to the records start with 1, while        // everything else we do starts with 0...        Vector info = infoFile.getRecord(recordNumber - 1);        if (info == null) {            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has no info");            }            return drawingAttributes;        }        Object keyObj = info.elementAt(keyIndex);        String key = null;        PoliticalArea pa = null;        if (keyObj != null) {            key = createStringFromKeyObject(keyObj);            pa = (PoliticalArea) politicalAreas.get(key);        }        if (pa == null) {            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has key \"" + key                        + "\" and DEFAULT attributes");            }            return drawingAttributes;        } else {            // Only bother with this the first time around.            if (pa.name == null) {                String name = (String) info.elementAt(nameIndex);                if (name != null) {                    pa.name = name;                } else {                    pa.name = "";                }            }            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has key \"" + key                        + "\" and SPECIALIZED attributes");            }            return pa.drawingAttributes;        }    }    /**     * Given the shapefile record number, find the drawing parameters     * from the DBF model that should be used for the shape. Returns     * the default coloring if the key for the drawing parameters     * isn't found.     */    public DrawingAttributes getDrawParamsFromDBF(int recordNumber) {        if (dbfModel == null) {            return drawingAttributes;        }        // OFF BY ONE!!! The shape record numbers        // assigned to the records start with 1, while        // everything else we do starts with 0...        // Vector info = infoFile.getRecord(recordNumber-1);        if (dbfModel == null || dbfModel.getRowCount() < recordNumber) {            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has no info");            }            return drawingAttributes;        }        Object keyObj = dbfModel.getValueAt(recordNumber - 1, keyIndex);        String key = null;        PoliticalArea pa = null;        if (keyObj != null) {            key = createStringFromKeyObject(keyObj);            pa = (PoliticalArea) politicalAreas.get(key);        }        if (pa == null) {            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has key \"" + key                        + "\" and DEFAULT attributes");            }            return drawingAttributes;        } else {            // Only bother with this the first time around.            if (pa.name == null) {                // String name = (String) info.elementAt(nameIndex);                String name = (String) dbfModel.getValueAt(recordNumber - 1,                        nameIndex);                if (name != null) {                    pa.name = name;                } else {                    pa.name = "";                }            }            if (Debug.debugging("areas")) {                Debug.output("AreaHandler.getDrawParameters: record "                        + recordNumber + " has key \"" + key                        + "\" and SPECIALIZED attributes");            }            return pa.drawingAttributes;        }    }        /**     * OK, we can't assume that we are assigning a string as a     * key, you might want to key in on a specific attribute that     * is a number, like the country coloring code that ESRI has     * in the country file. We're going to assume that if the     * number has an integer value, it shouldn't have decimal     * places. That is, a 1.0 will be truncated to 1, because that     * makes more sense in a data file where you are using a key     * as a factor. If the double value doesn't match the integer     * value, though, we'll assume that's what was meant and leave     * it alone.<p>     */    protected String createStringFromKeyObject(Object keyObj) {        String key = null;        if (keyObj instanceof String) {            key = ((String) keyObj).toUpperCase().intern();        } else if (keyObj instanceof Number) {            Number keyNum = (Number) keyObj;            if (keyNum.doubleValue() == (double) keyNum.intValue()) {                // Strips off empty decimal places, for sure                key = Integer.toString(keyNum.intValue()).intern();            } else {                key = Double.toString(keyNum.doubleValue()).intern();            }        } else {            try {                key = keyObj.toString().toUpperCase().intern();            } catch (Exception e) {                Debug.error("AreaHandler.createStringFromKeyObject: bad key object:" + keyObj);

⌨️ 快捷键说明

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