📄 areahandler.java
字号:
omgraphics = new OMGraphicList(); } catch (java.io.IOException ioe) { omgraphics = new OMGraphicList(); } catch (Exception exc) { omgraphics = new OMGraphicList(); } // 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() { if (omgraphics == null) { omgraphics = new OMGraphicList(); try { spatialIndex.getOMGraphics(-180, -90, 180, 90, omgraphics, drawingAttributes, (Projection) null, coordTransform); for (Iterator it = omgraphics.iterator(); it.hasNext();) { OMGraphic omg = (OMGraphic) it.next(); Integer recNum = (Integer) omg.getAttribute(ShapeConstants.SHAPE_INDEX_ATTRIBUTE); if (recNum != null) { getDrawParams(recNum.intValue()).setTo(omg); } } } catch (IOException ioe) { Debug.error(ioe.getMessage()); } catch (FormatException fe) { Debug.error(fe.getMessage()); } } return omgraphics; } /** * 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) { return getGraphics(ulLat, ulLon, lrLat, lrLon, (Projection) null); } /** * 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. * @param proj the current map projection. * @return OMGraphicList */ public OMGraphicList getGraphics(float ulLat, float ulLon, float lrLat, float lrLon, Projection proj) { if (cacheURL != null) { return omgraphics; } if (spatialIndex == null) { return new OMGraphicList(); } if (politicalAreas == null) { initialize(originalPrefix, originalProperties); } OMGraphicList list = new OMGraphicList(); // 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 (ProjMath.isCrossingDateline(ulLon, lrLon, proj.getScale())) { if (Debug.debugging("shape")) { Debug.output("ShapeLayer.computeGraphics(): Dateline is on screen"); } double ymin = (double) Math.min(ulLat, lrLat); double ymax = (double) Math.max(ulLat, lrLat); checkSpatialIndexEntries(ulLon, ymin, 180.0d, ymax, list, proj); checkSpatialIndexEntries(-180.0d, ymin, lrLon, ymax, list, proj); } 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); checkSpatialIndexEntries(xmin, ymin, xmax, ymax, list, proj); } return list; } /** * Uses the SpatialIndex object to create the OMGraphics that fit within the * boundaries. * * @param xmin * @param ymin * @param xmax * @param ymax * @param retList * @param proj */ protected void checkSpatialIndexEntries(double xmin, double ymin, double xmax, double ymax, OMGraphicList retList, Projection proj) { try { // There should be the same number of objects in both iterators. Iterator entryIt = spatialIndex.entryIterator(coordTransform); Iterator omgIt = getGraphics().iterator(); while (entryIt.hasNext() && omgIt.hasNext()) { Entry entry = (Entry) entryIt.next(); OMGraphic omg = (OMGraphic) omgIt.next(); if (entry.intersects(xmin, ymin, xmax, ymax)) { if (proj != null) { omg.generate(proj); } retList.add(omg); } } } catch (IOException ioe) { Debug.error(ioe.getMessage()); } catch (FormatException fe) { Debug.error(fe.getMessage()); } } /** * 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -