?? editableompoly.java
字號:
if (ll.length != 0) { System.arraycopy(ll, 0, newll, 0, ll.length); } newll[ll.length] = llpnt.radlat_; newll[ll.length + 1] = llpnt.radlon_; position = ll.length / 2; } else if (actualPosition <= 0) { // Put the new point at the beginning System.arraycopy(ll, 0, newll, 2, ll.length); newll[0] = llpnt.radlat_; newll[1] = llpnt.radlon_; position = 0; } else { // actualPosition because there are 2 floats for // every // position. newll[actualPosition] = llpnt.radlat_; newll[actualPosition + 1] = llpnt.radlon_; System.arraycopy(ll, 0, newll, 0, actualPosition); System.arraycopy(ll, actualPosition, newll, actualPosition + 2, ll.length - actualPosition); } poly.setLocation((float[]) newll, OMGraphic.RADIANS); } } else if (renderType == OMGraphic.RENDERTYPE_XY) { // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: adding point to x/y poly"); int currentLength = poly.xs.length; int[] newxs = new int[currentLength + 1]; int[] newys = new int[currentLength + 1]; if (position >= currentLength) { // Put the new points at the end System.arraycopy(poly.xs, 0, newxs, 0, currentLength); System.arraycopy(poly.ys, 0, newys, 0, currentLength); newxs[currentLength] = x; newys[currentLength] = y; position = currentLength; } else if (position <= 0) { // Put the new points at the beginning System.arraycopy(poly.xs, 0, newxs, 1, currentLength); System.arraycopy(poly.ys, 0, newys, 1, currentLength); newxs[0] = x; newys[0] = y; position = 0; } else { newxs[position] = x; newys[position] = y; System.arraycopy(poly.xs, 0, newxs, 0, position); System.arraycopy(poly.xs, position, newxs, position + 1, currentLength - position); System.arraycopy(poly.ys, 0, newys, 0, position); System.arraycopy(poly.ys, position, newys, position + 1, currentLength - position); } poly.setLocation(newxs, newys); } else { // Rendertype is offset... // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: adding point to offset poly"); int currentLength = poly.xs.length; int[] newxs = new int[currentLength + 1]; int[] newys = new int[currentLength + 1]; if (position >= currentLength) { // Put the new points at the end position = currentLength; System.arraycopy(poly.xs, 0, newxs, 0, currentLength); System.arraycopy(poly.ys, 0, newys, 0, currentLength); } else if (position <= 0) { // Put the new points at the beginning position = 0; System.arraycopy(poly.xs, 0, newxs, 1, currentLength); System.arraycopy(poly.ys, 0, newys, 1, currentLength); } else { System.arraycopy(poly.xs, 0, newxs, 0, position); System.arraycopy(poly.xs, position, newxs, position + 1, currentLength - position); System.arraycopy(poly.ys, 0, newys, 0, position); System.arraycopy(poly.ys, position, newys, position + 1, currentLength - position); } int offsetX; int offsetY; if (gpo.getX() == -1 && gpo.getY() == -1) { offsetX = projection.getWidth() / 2; offsetY = projection.getHeight() / 2; } else { offsetX = gpo.getX(); } if (poly.coordMode == OMPoly.COORDMODE_ORIGIN || position == 0) { // cover // the // first // point newxs[position] = x - offsetX; newys[position] = y - offsetY; } else { // CMode Previous offset deltas newxs[position] = x - offsetX - newxs[position - 1]; newys[position] = y - offsetY - newys[position - 1]; } if (position == 0) { // Could call projection.getCenter() but that might // break if/when we make other projection // libraries/paradigms active. LatLonPoint llpnt = projection.inverse(offsetX, offsetY); poly.lat = llpnt.radlat_; poly.lon = llpnt.radlon_; } poly.setLocation(poly.lat, poly.lon, OMGraphic.RADIANS, newxs, newys); } // Need to reset the arrowhead when an end point is added, // removing it from the shape when the point gets added. // Otherwise, you end up with a arrowhead at each junction of // the polygon. OMArrowHead omah = poly.getArrowHead(); poly.setArrowHead(null); // This is the standard call that needs to be made here, the // arrowhead changes are around this. poly.regenerate(projection); // Reset the arrowhead so it will get drawn on the new // segment. poly.setArrowHead(omah); polyGrabPoints.add(position, gp); if (gpo != null) { gpo.addGrabPoint(gp); } return position; } /** * Delete a point off the end of the polyline/polygon. */ public void deletePoint() { deletePoint(Integer.MAX_VALUE); } /** * Delete a point at a certain point in the polygon coordinate * list. If the position is less than zero, the deleted point will * be the starting point. If the position is greater than the list * of current points, the point will be deleted from the end of * the poly. */ public void deletePoint(int position) { int renderType = poly.getRenderType(); boolean needToHookUp = false; if (position <= 0 && isEnclosed()) { // if the position is 0 and the polygon is enclosed, we // need to disengage the two points, then reattach. enclose(false); needToHookUp = true; } if (renderType == OMGraphic.RENDERTYPE_LATLON) { Debug.message("eomg", "EditableOMPoly: adding point to lat/lon poly"); if (projection != null) { float[] ll = poly.getLatLonArray(); float[] newll = new float[ll.length - 2]; int actualPosition = (position == Integer.MAX_VALUE ? ll.length : position * 2); if (actualPosition >= ll.length) { // Pull the new points off the end System.arraycopy(ll, 0, newll, 0, ll.length - 2); position = (ll.length - 2) / 2; } else if (actualPosition <= 0) { // Pull the new points off the beginning System.arraycopy(ll, 2, newll, 0, ll.length - 2); position = 0; } else { // actualPosition because there are 2 floats for // every // position. System.arraycopy(ll, 0, newll, 0, actualPosition); System.arraycopy(ll, actualPosition + 2, newll, actualPosition, ll.length - actualPosition - 2); } poly.setLocation((float[]) newll, OMGraphic.RADIANS); } } else { // Grab the projected endpoints Debug.message("eomg", "EditableOMPoly: adding point to x/y or offset poly"); int currentLength = poly.xs.length; int[] newxs = new int[currentLength - 1]; int[] newys = new int[currentLength - 1]; if (position >= currentLength) { // Pull the points from the end... System.arraycopy(poly.xs, 0, newxs, 0, currentLength - 1); System.arraycopy(poly.ys, 0, newys, 0, currentLength - 1); position = currentLength - 1; } else if (position <= 0) { // Pull the points from the beginning... System.arraycopy(poly.xs, 1, newxs, 0, currentLength - 1); position = 0; } else { System.arraycopy(poly.xs, 0, newxs, 0, position); System.arraycopy(poly.xs, position + 1, newxs, position, currentLength - position - 1); System.arraycopy(poly.ys, 0, newys, 0, position); position + 1, newys, position, currentLength - position - 1); } if (poly.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) { poly.setLocation(poly.lat, poly.lon, OMGraphic.RADIANS, newxs, newys); } else { poly.setLocation(newxs, newys); } } if (projection != null) { poly.regenerate(projection); } // Remove the GrabPoint for the deleted spot. GrabPoint gp = (GrabPoint) polyGrabPoints.remove(position); if (gpo != null && gp != null) { gpo.removeGrabPoint(gp); } if (needToHookUp) { enclose(true); } } /** * Called to set the OffsetGrabPoint to the current mouse * location, and update the OffsetGrabPoint with all the other * GrabPoint locations, so everything can shift smoothly. Should * also set the OffsetGrabPoint to the movingPoint. Should be * called only once at the beginning of the general movement, in * order to set the movingPoint. After that, redraw(e) should just * be called, and the movingPoint will make the adjustments to the * graphic that are needed. */ public void move(MouseEvent e) { // Need to check to see if the OffsetGrabPoint is currently // being used. If not, just use it, otherwise, will need to // create a special one for the move. if (poly.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) { gpm = new OffsetGrabPoint(e.getX(), e.getY()); gpm.clear(); } else { gpm = gpo; gpm.clear(); gpm.set(e.getX(), e.getY()); } // Move all the other points along with the offset point... addPolyGrabPointsToOGP(gpm); movingPoint = gpm; } /** * This method adds all the GrabPoints associated with the polygon * nodes and adds them to the offset GrabPoint representing the * lat/lon anchor point. */ protected void addPolyGrabPointsToOGP(OffsetGrabPoint ogp) { if (ogp == null) return; // Reset the points to the offset point. int count = 0; Iterator gps = polyGrabPoints.iterator(); while (gps.hasNext()) { GrabPoint gb = (GrabPoint) gps.next(); ogp.addGrabPoint(gb); count++; } ogp.updateOffsets(); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -