?? editableompoly.java
字號:
// returned, instead of the duplicate ending point. int lastPointIndex = polyGrabPoints.size() - 1; if (gb != null && gb == (GrabPoint) polyGrabPoints.get(lastPointIndex) && isEnclosed()) { gb = (GrabPoint) polyGrabPoints.get(0); setMovingPoint(gb); } return gb; } /** * Check to make sure the grab points are not null. If they are, * allocate them, and them assign them to the array. */ public void assertGrabPoints() { // This gets called alot. Usually, for EditableOMGraphics // that have the same number of GrabPoints, they can just be // allocated here. I think we'll have to look at the OMPoly, // find out how many points have been defined for it (since // it's variable), and make sure everything's OK. if (polyGrabPoints == null) { polyGrabPoints = new ArrayList(); } // At least we know about this one. if (gpo == null) { gpo = new OffsetGrabPoint(-1, -1); } } /** * An internal method that trys to make sure that the grab point * for the first node, and for the last, in case of an enclosed * polygon, are OffsetGrabPoints. All of the other points will be * regular GrabPoints. Usually called when assigning points to a * previously defined poly. * * @param x the horizontal pixel location of the grab point. * @param y the vertical pixel location of the grab point. * @param index the index of the grab point. * @param last the index of the last point. */ protected GrabPoint createGrabPoint(int x, int y, int index, int last) { if (index == 0 || (index == last && (isEnclosed()))) { return new OffsetGrabPoint(x, y); } else { return new GrabPoint(x, y); } } /** * Set the grab points for the graphic provided, setting them on * the extents of the graphic. Called when you want to set the * grab points off the points of the graphic. */ public void setGrabPoints(OMGraphic graphic) { if (!(graphic instanceof OMPoly)) { return; } assertGrabPoints(); polyGrabPoints.clear(); gpo.clear(); OMPoly poly = (OMPoly) graphic; boolean ntr = poly.getNeedToRegenerate(); int renderType = poly.getRenderType(); Point p = new Point(); GrabPoint gb; int i; int npts; if (ntr == false) { if (renderType == OMGraphic.RENDERTYPE_LATLON) { Debug.message("eomg", "EditableOMPoly: modifying lat/lon line"); if (projection != null) { float[] ll = poly.getLatLonArray(); gb = null; //reset for this loop for (i = 0; i < ll.length; i += 2) { projection.forward(ll[i], ll[i + 1], p, true); // Need to add a grab point for this // coordinate gb = new OffsetGrabPoint((int) p.getX(), (int) p.getY()); polyGrabPoints.add(gb); } } } else if (renderType == OMGraphic.RENDERTYPE_OFFSET) { // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: modifying offset poly"); int x; int y; npts = poly.xs.length; // Check to see if the poly is a offset poly, and set // the // offset grab point accordingly. if (projection != null) { projection.forward(poly.lat, poly.lon, p, true); gpo.set((int) p.getX(), (int) p.getY()); if (poly.coordMode == OMPoly.COORDMODE_ORIGIN) { for (i = 0; i < npts; i++) { x = poly.xs[i] + p.x; y = poly.ys[i] + p.y; gb = new OffsetGrabPoint(x, y); polyGrabPoints.add(gb); } } else { // CMode Previous offset deltas int lastX = p.x; int lastY = p.y; for (i = 0; i < npts; i++) { x = poly.xs[i] + lastX; y = poly.ys[i] + lastY; gb = new OffsetGrabPoint(x, y); polyGrabPoints.add(gb); lastX += x; lastY += y; } } } } else { npts = poly.xs.length; Debug.message("eomg", "EditableOMPoly: modifying x/y poly"); for (i = 0; i < npts; i++) { gb = new OffsetGrabPoint(poly.xs[i], poly.ys[i]); polyGrabPoints.add(gb); } } // Add the || to maintain manualEnclosed if it was // externally set before the OMPoly is actually defined, // indicating that the user wants to draw a polygon. setEnclosed(syncEnclosed() || isEnclosed()); addPolyGrabPointsToOGP(gpo); } else { Debug.message("eomg", "EditableOMPoly.setGrabPoints: graphic needs to be regenerated "); } } /** * Take the current location of the GrabPoints, and modify the * location parameters of the OMPoly with them. Called when you * want the graphic to change according to the grab points. */ public void setGrabPoints() { int i; GrabPoint gb; // just to use a temp marker LatLonPoint llp = new LatLonPoint(); int renderType = poly.getRenderType(); if (renderType == OMGraphic.RENDERTYPE_LATLON) { if (projection != null) { float[] floats = new float[polyGrabPoints.size() * 2]; for (i = 0; i < polyGrabPoints.size(); i++) { gb = (GrabPoint) polyGrabPoints.get(i); projection.inverse(gb.getX(), gb.getY(), llp); floats[2 * i] = llp.radlat_; floats[2 * i + 1] = llp.radlon_; } poly.setLocation((float[]) floats, OMGraphic.RADIANS); } else { Debug.message("eomg", "EditableOMPoly.setGrabPoints: projection is null, can't figure out LATLON points for poly."); } } else if (renderType == OMGraphic.RENDERTYPE_OFFSET) { // Do the offset point. if (projection != null) { projection.inverse(gpo.getX(), gpo.getY(), llp); } else { Debug.message("eomg", "EditableOMPoly.setGrabPoints: projection is null, can't figure out LATLON points for poly offset."); } } if (renderType == OMGraphic.RENDERTYPE_XY || renderType == OMGraphic.RENDERTYPE_OFFSET) { int[] ints = new int[polyGrabPoints.size() * 2]; if (renderType == OMGraphic.RENDERTYPE_OFFSET && gpo != null) { // If offset rendertype, the x-y have to be offset // distances, not screen pixel locations. For the // polygon, you also need to take into account that // the ints can represent 2 different things: distance // from the origin (Offset) or distance from the // previous point. Need to check with the poly to // find out which to do. GrabPoint previous = gpo; for (i = 0; i < polyGrabPoints.size(); i++) { gb = (GrabPoint) polyGrabPoints.get(i); if (poly.coordMode == OMPoly.COORDMODE_PREVIOUS) { ints[2 * i] = gb.getX() - previous.getX(); ints[2 * i + 1] = gb.getY() - previous.getY(); previous = gb; } else { ints[2 * i] = gb.getX() - gpo.getX(); ints[2 * i + 1] = gb.getY() - gpo.getY(); } } poly.setLocation(llp.radlat_, llp.radlon_, OMGraphic.RADIANS, ints); } else { for (i = 0; i < polyGrabPoints.size(); i++) { gb = (GrabPoint) polyGrabPoints.get(i); ints[2 * i] = gb.getX(); ints[2 * i + 1] = gb.getY(); } poly.setLocation(ints); } } } /** * Add a point to the end of the polyline/polygon and then make it * the moving one. * * @return the index for the point in the polygon, starting with * 0. */ public int addMovingPoint(int x, int y) { int position = addPoint(x, y); setMovingPoint((GrabPoint) polyGrabPoints.get(position)); return position; } /** * Add a point to the end of the polyline/polygon. * * @return the index for the point in the polygon, starting with * 0. */ public int addPoint(int x, int y) { return addPoint(x, y, Integer.MAX_VALUE); } /** * Add a point at a certain point in the polygon coordinate list. * If the position is less than zero, the point will be the * starting point. If the position is greater than the list of * current points, the point will be added to the end of the poly. * * @return the index for the point in the polygon, starting with * 0. */ public int addPoint(int x, int y, int position) { return addPoint(new OffsetGrabPoint(x, y), position); } /** * Add a point at a certain point in the polygon coordinate list. * If the position is less than zero, the point will be the * starting point. If the position is greater than the list of * current points, the point will be added to the end of the poly. * This method is convenient because it lets you define the * GrabPoint object to use for the node, in case you need a * special type of GrabPoint. * * @param gp the GrabPoint set to the screen coordinates of the * point to be added. * @return the index for the point in the polygon, starting with * 0. */ public int addPoint(GrabPoint gp) { return addPoint(gp, Integer.MAX_VALUE); } /** * Add a point at a certain point in the polygon coordinate list. * If the position is less than zero, the point will be the * starting point. If the position is greater than the list of * current points, the point will be added to the end of the poly. * This method is convenient because it lets you define the * GrabPoint object to use for the node, in case you need a * special type of GrabPoint. * * @return the index for the point in the polygon, starting with * 0. */ public int addPoint(GrabPoint gp, int position) { if (gp == null) { return -1; } int x = gp.getX(); int y = gp.getY(); int renderType = poly.getRenderType(); if (renderType == OMGraphic.RENDERTYPE_LATLON) { Debug.message("eomg", "EditableOMPoly: adding point to lat/lon poly"); if (projection != null) { float[] ll = poly.getLatLonArray(); int actualPosition = (position == Integer.MAX_VALUE ? ll.length : position * 2); LatLonPoint llpnt = projection.inverse(x, y); if (Debug.debugging("eomp")) { Debug.output("EditableOMPoly: adding point to lat/lon poly at " + x + ", " + y + ": " + llpnt + ", at the end of "); for (int j = 0; j < ll.length; j += 2) { Debug.output(ll[j] + ", " + ll[j + 1]); } } float[] newll = new float[ll.length + 2]; if (actualPosition >= ll.length) { // Put the new points at the end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -