?? ompoly.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/omGraphics/OMPoly.java,v $// $RCSfile: OMPoly.java,v $// $Revision: 1.10.2.7 $// $Date: 2005/08/11 21:03:22 $// $Author: dietrick $//// **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.BasicStroke;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Point;import java.awt.geom.GeneralPath;import java.io.Serializable;import java.util.ArrayList;import com.bbn.openmap.proj.DrawUtil;import com.bbn.openmap.proj.ProjMath;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * Graphic object that represents a polygon or polyline * (multi-line-segment-object). * <p> * * The differentiator between polygons and polylines is the fill * color. If the fillPaint is equal to OMColor.clear, then the poly * will be considered a polyline. There are methods to override this * in the OMPoly class, but they do play around with the fillPaint, * depending on the order in which the methods are called. If you know * it's a polyline, call setIsPolygon(false) if you think that the * fillPaint could be set to anything other than the default, * OMColor.clear. * <P> * * All of the OMGraphics are moving to having their internal * representation as java.awt.Shape objects. Unfortunately, this has * the side effect of slowing OMPolys down, because the way that the * projection classes handle transformations cause more objects to be * allocated and more loops to be run through. So, by default, the * OMPoly does NOT use Shape objects internally, to keep layers that * throw down many, many polys running quickly. If you want to do some * spatial analysis on an OMPoly, call setDoShapes(true) on it, then * generate(Projection), and then call getShapes() to get the * java.awt.Shape objects for the poly. You can then run the different * Shape spatial analysis methods on the Shape objects. * * <h3>NOTES:</h3> * <ul> * <li>See the <a * href="../../../../com.bbn.openmap.proj.Projection.html#poly_restrictions"> * RESTRICTIONS </a> on Lat/Lon polygons/polylines. Not following the * guidelines listed may result in ambiguous/undefined shapes! Similar * assumptions apply to the other vector graphics that we define: * circles, ellipses, rects, lines. * <li>LatLon OMPolys store latlon coordinates internally in radian * format for efficiency in projecting. Subclasses should follow this * model. * <li>Holes in the poly are not supported. * <p> * </ul> * <h3>TODO:</h3> * <ul> * <li>Polar filled-polygon correction for Cylindrical projections * (like OMCircle). * </ul> * * @see OMCircle * @see OMRect * @see OMLine */public class OMPoly extends OMAbstractLine implements Serializable { /** * Translation offsets. For RENDERTYPE_OFFSET, the xy points are * relative to the position of fixed latlon point. */ public final static int COORDMODE_ORIGIN = 0; /** * Delta offsets. For RENDERTYPE_OFFSET, each xy point in the * array is relative to the previous point, and the first point is * relative to the fixed latlon point. */ public final static int COORDMODE_PREVIOUS = 1; /** * Radians or decimal degrees. After construction and conversion, * this should always be radians. */ protected int units = -1;// this should be set correctly at // construction /** * For RENDERTYPE_OFFSET, the latitude of the starting point of * the poly. Stored as radians! */ protected float lat = 0.0f; /** * For RENDERTYPE_OFFSET, the longitude of the starting point of * the poly. Stored as radians! */ protected float lon = 0.0f; /** * For RENDERTYPE_OFFSET, type of offset. * * @see #COORDMODE_ORIGIN * @see #COORDMODE_PREVIOUS */ protected int coordMode = COORDMODE_ORIGIN; /** * The x array of ints, representing pixels, used for x/y or * offset polys. */ protected int[] xs = null; /** * The y array of ints, representing pixels, used for x/y or * offset polys. */ protected int[] ys = null; /** * Poly is a polygon or a polyline. This is true if the fillColor * is not clear, false if it is. */ protected boolean isPolygon = false; /** raw float lats and lons stored internally in radians. */ protected float[] rawllpts = null; /** * Flag for telling the OMPoly to use the Shape objects to * represent itself internally. See intro for more info. */ protected boolean doShapes = false; /** * Construct a default OMPoly. */ public OMPoly() { super(RENDERTYPE_UNKNOWN, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); } /** * Create an OMPoly from a list of float lat/lon pairs. * <p> * NOTES: * <ul> * <li>llPoints array is converted into radians IN PLACE for more * efficient handling internally if it's not already in radians! * For even better performance, you should send us an array * already in radians format! * <li>If you want the poly to be connected (as a polygon), you * need to ensure that the first and last coordinate pairs are the * same. * </ul> * * @param llPoints array of lat/lon points, arranged lat, lon, * lat, lon, etc. * @param units radians or decimal degrees. Use OMGraphic.RADIANS * or OMGraphic.DECIMAL_DEGREES * @param lType line type, from a list defined in OMGraphic. */ public OMPoly(float[] llPoints, int units, int lType) { this(llPoints, units, lType, -1); } /** * Create an OMPoly from a list of float lat/lon pairs. * <p> * NOTES: * <ul> * <li>llPoints array is converted into radians IN PLACE for more * efficient handling internally if it's not already in radians! * For even better performance, you should send us an array * already in radians format! * <li>If you want the poly to be connected (as a polygon), you * need to ensure that the first and last coordinate pairs are the * same. * </ul> * * @param llPoints array of lat/lon points, arranged lat, lon, * lat, lon, etc. * @param units radians or decimal degrees. Use OMGraphic.RADIANS * or OMGraphic.DECIMAL_DEGREES * @param lType line type, from a list defined in OMGraphic. * @param nsegs number of segment points (only for * LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and * if < 1, this value is generated internally) */ public OMPoly(float[] llPoints, int units, int lType, int nsegs) { super(RENDERTYPE_LATLON, lType, DECLUTTERTYPE_NONE); setLocation(llPoints, units); this.nsegs = nsegs; } /** * Create an OMPoly from a list of xy pairs. If you want the poly * to be connected, you need to ensure that the first and last * coordinate pairs are the same. * * @param xypoints array of x/y points, arranged x, y, x, y, etc. */ public OMPoly(int[] xypoints) { super(RENDERTYPE_XY, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setLocation(xypoints); } /** * Create an x/y OMPoly. If you want the poly to be connected, you * need to ensure that the first and last coordinate pairs are the * same. * * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates */ public OMPoly(int[] xPoints, int[] yPoints) { super(RENDERTYPE_XY, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setLocation(xPoints, yPoints); } /** * Create an x/y OMPoly at an offset from lat/lon. If you want the * poly to be connected, you need to ensure that the first and * last coordinate pairs are the same. * * @param latPoint latitude in decimal degrees * @param lonPoint longitude in decimal degrees * @param xypoints int[] of x,y pairs * @param cMode offset coordinate mode */ public OMPoly(float latPoint, float lonPoint, int[] xypoints, int cMode) { super(RENDERTYPE_OFFSET, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setLocation(latPoint, lonPoint, OMGraphic.DECIMAL_DEGREES, xypoints); coordMode = cMode; } /** * Create an x/y OMPoly at an offset from lat/lon. If you want the * poly to be connected, you need to ensure that the first and * last coordinate pairs are the same. * * @param latPoint latitude in decimal degrees * @param lonPoint longitude in decimal degrees * @param xPoints int[] of x coordinates * @param yPoints int[] of y coordinates * @param cMode offset coordinate mode */ public OMPoly(float latPoint, float lonPoint, int[] xPoints, int[] yPoints, int cMode) { super(RENDERTYPE_OFFSET, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); setLocation(latPoint, lonPoint, OMGraphic.DECIMAL_DEGREES, xPoints, yPoints); coordMode = cMode; } /** * Set an OMPoly from a list of float lat/lon pairs. * <p> * NOTES: * <ul> * <li>llPoints array is converted into radians IN PLACE for more * efficient handling internally if it's not already in radians! * If you don't want the array to be changed, send in a copy. * <li>If you want the poly to be connected (as a polygon), you * need to ensure that the first and last coordinate pairs are the * same. * </ul> * This is for RENDERTYPE_LATLON polys. * * @param llPoints array of lat/lon points, arranged lat, lon, * lat, lon, etc. * @param units radians or decimal degrees. Use OMGraphic.RADIANS * or OMGraphic.DECIMAL_DEGREES */ public void setLocation(float[] llPoints, int units) { this.units = OMGraphic.RADIANS; if (units == OMGraphic.DECIMAL_DEGREES) { ProjMath.arrayDegToRad(llPoints); } rawllpts = llPoints; setNeedToRegenerate(true); setRenderType(RENDERTYPE_LATLON); } /** * Set an OMPoly from a list of xy pixel pairs. If you want the * poly to be connected, you need to ensure that the first and * last coordinate pairs are the same. This is for RENDERTYPE_XY * polys. * * @param xypoints array of x/y points, arranged x, y, x, y, etc. */ public void setLocation(int[] xypoints) { int end = xypoints.length >> 1; xs = new int[end]; ys = new int[end]; for (int i = 0, j = 0; i < end; i++, j += 2) { xs[i] = xypoints[j]; ys[i] = xypoints[j + 1]; } setNeedToRegenerate(true); setRenderType(RENDERTYPE_XY); } /** * Set an OMPoly from a x/y coordinates. If you want the poly to * be connected, you need to ensure that the first and last
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -