📄 ompoly.java
字号:
if (!doShapes) { if (size > 1) { if (arrowhead != null) { arrowhead.generate(this); } setNeedToRegenerate(false); initLabelingDuringGenerate(); if (checkPoints(xpoints, ypoints)) { setLabelLocation(xpoints[0], ypoints[0]); } return true; } else { return false; } } break; case RENDERTYPE_UNKNOWN: Debug.error("OMPoly.generate: invalid RenderType"); return false; } if (arrowhead != null) { arrowhead.generate(this); } setNeedToRegenerate(false); createShape(); return true; } /** * Return true if the xpoints and ypoints are not null and contain * coordinates. * * @param xpoints2 * @param ypoints2 */ protected boolean checkPoints(int[][] xpoints2, int[][] ypoints2) { if (xpoints == null || ypoints == null || xpoints.length == 0 || ypoints.length == 0) { return false; } return true; } /** * Return true of the fill color/paint should be rendered (not * clear). */ public boolean shouldRenderFill() { return !isClear(getFillPaint()) && isPolygon(); } /** * Paint the poly. This works if generate() has been successful. * * @param g java.awt.Graphics to paint the poly onto. */ public void render(Graphics g) { if (shape != null) { super.render(g); if (arrowhead != null) { arrowhead.render(g); } return; } if (getNeedToRegenerate() || !isVisible()) return; // safety: grab local reference of projected points int[][] xpts = xpoints; int[][] ypts = ypoints; if (xpts == null || ypts == null) { // Shouldn't get here, but crazy EditableOMPoly events // sometimes cause this to happen. Catch and wait to // paint later. setNeedToRegenerate(true); return; } int[] _x, _y; int i; int len = xpts.length; Paint displayPaint = getDisplayPaint(); Paint fillPaint = getFillPaint(); boolean isFillClear = isClear(fillPaint); boolean isLineClear = isClear(displayPaint); Paint tm = getTextureMask(); // If shapes are null, then we have to do things the old way. try { for (i = 0; i < len; i++) { _x = xpts[i]; _y = ypts[i]; if (_x == null || _y == null) { continue; } // render polygon if (isPolygon) { // fill main polygon if (!isFillClear) { // set the interior coloring parameters setGraphicsForFill(g); g.fillPolygon(_x, _y, _x.length); if (tm != null && tm != fillPaint) { setGraphicsColor(g, tm); g.fillPolygon(_x, _y, _x.length); } } // only draw outline if different color or matted if (matted || !isLineClear || !edgeMatchesFill) { if (matted) { if (g instanceof Graphics2D && stroke instanceof BasicStroke) { ((Graphics2D) g).setStroke(new BasicStroke(((BasicStroke) stroke).getLineWidth() + 2f)); setGraphicsColor(g, mattingPaint); g.drawPolyline(_x, _y, _x.length); } } setGraphicsForEdge(g); // for some reason, this used to be // drawPolygon g.drawPolygon(_x, _y, _x.length); } } // render polyline else { if (matted) { if (g instanceof Graphics2D && stroke instanceof BasicStroke) { ((Graphics2D) g).setStroke(new BasicStroke(((BasicStroke) stroke).getLineWidth() + 2f)); // Just to draw the matting for the // arrowhead. if (arrowhead != null) { setGraphicsColor(g, mattingPaint); arrowhead.render(g); } setGraphicsColor(g, mattingPaint); g.drawPolyline(_x, _y, _x.length); } } // draw main outline setGraphicsForEdge(g); g.drawPolyline(_x, _y, _x.length); if (arrowhead != null) { arrowhead.render(g); } } } renderLabel(g); } catch (Exception e) { // Trying to catch any clipping problems from within a JRE Debug.output("OMPoly: caught Java rendering exception\n" + e.getMessage()); if (Debug.debugging("ompoly")) { e.printStackTrace(); } } } /** * Return the shortest distance from the graphic to an XY-point. * This works if generate() has been successful. * * @param x horizontal pixel location. * @param y vertical pixel location. * @return the distance of the object to the location given. */ public float distance(int x, int y) { if (shape != null) { return super.distance(x, y); } // If shape is null, then we have to do things the old way. float temp, distance = Float.POSITIVE_INFINITY; if (getNeedToRegenerate()) { return distance; } // safety: grab local reference of projected points int[][] xpts = xpoints; int[][] ypts = ypoints; int[] _x, _y; int len = xpts.length; for (int i = 0; i < len; i++) { _x = xpts[i]; _y = ypts[i]; // check if point inside polygon if (isPolygon && DrawUtil.inside_polygon(_x, _y, x, y)) return 0f; // close as can be // get the closest point temp = DrawUtil.closestPolyDistance(_x, _y, x, y, false); if (temp < distance) distance = temp; } return normalizeDistanceForLineWidth(distance); } /** * Get the array of java.awt.Shape objects that represent the * projected graphic. The array will contain more than one Shape * object of the object wraps around the earth and needs to show * up in more than one place on the map. * <p> * * The java.awt.Shape object gives you the ability to do a little * spatial analysis on the graphics. * * @return java.awt.geom.GeneralPath (Shape), or null if the * graphic needs to be generated with the current map * projection, or null if the OMGeometry hasn't been * updated to use Shape objects for its internal * representation. */ public GeneralPath getShape() { if (shape == null) { // Since polygons have the option of not creating shape // objects, should create one if asked. createShape(); } return shape; } /** * Since OMPoly has the option to not create a Shape, this method * is here to create it if it is asked for. The OMPoly needs to be * generated. */ protected void createShape() { if (getNeedToRegenerate() || !checkPoints(xpoints, ypoints)) { return; } initLabelingDuringGenerate(); switch (renderType) { case RENDERTYPE_XY: case RENDERTYPE_OFFSET: shape = createShape(xpoints[0], ypoints[0], isPolygon); break; case RENDERTYPE_LATLON: int size = xpoints.length; for (int i = 0; i < size; i++) { GeneralPath gp = createShape(xpoints[i], ypoints[i], isPolygon); if (shape == null) { shape = gp; } else { ((GeneralPath) shape).append(gp, false); } } break; default: } setLabelLocation(xpoints[0], ypoints[0]); } protected boolean geometryClosed = false; /** * Is the geometry closed ? * * @return boolean */ protected boolean isGeometryClosed() { geometryClosed = false; switch (renderType) { case RENDERTYPE_XY: case RENDERTYPE_OFFSET: if (xs != null && xs.length > 2) { geometryClosed = (xs[0] == xs[xs.length - 1] && ys[0] == ys[ys.length - 1]); } break; case RENDERTYPE_LATLON: if (rawllpts != null) { int l = rawllpts.length; if (l > 4) { geometryClosed = (Math.abs(rawllpts[0] - rawllpts[l - 2]) < 1e-5 && Math.abs(rawllpts[1] - rawllpts[l - 1]) < 1e-5); } } break; case RENDERTYPE_UNKNOWN: Debug.error("OMPoly.generate: invalid RenderType"); break; } return geometryClosed; } /** For XMLEncoder */ public float[] getRawllpts() { return this.rawllpts; } /** For XMLEncoder */ public int getUnits() { return this.units; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -