Changeset 32556 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
- Timestamp:
- 2016-07-04T14:18:17+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r32329 r32556 1 // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others1 // License: GPL. For details, see LICENSE file. 2 2 package cadastre_fr; 3 3 … … 77 77 private String codeCommune = ""; 78 78 79 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0,0));79 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0, 0)); 80 80 81 81 private boolean isRaster; … … 100 100 @SuppressWarnings("serial") 101 101 class ResetOffsetActionMenu extends JosmAction { 102 publicResetOffsetActionMenu() {102 ResetOffsetActionMenu() { 103 103 super(tr("Reset offset"), null, tr("Reset offset (only vector images)"), null, false); 104 104 } 105 105 106 @Override 106 107 public void actionPerformed(ActionEvent arg0) { … … 136 137 public void destroy() { 137 138 // if the layer is currently saving the images in the cache, wait until it's finished 138 if (grabThread != null)139 if (grabThread != null) 139 140 grabThread.cancel(); 140 141 grabThread = null; … … 149 150 if (codeCommune != null && !codeCommune.isEmpty()) 150 151 ret += "(" + codeCommune + ")"; 151 return 152 return ret; 152 153 } 153 154 … … 160 161 grabThread.setGrabber(grabber); 161 162 // if it is the first layer, use the communeBBox as grab bbox (and not divided) 162 if (Main.getLayerManager().getLayers().size() == 1 163 if (Main.getLayerManager().getLayers().size() == 1) { 163 164 final Bounds bounds = this.getCommuneBBox().toBounds(); 164 165 GuiHelper.runInEDTAndWait(new Runnable() { … … 174 175 Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 175 176 } else 176 divideBbox(b, 177 divideBbox(b, 177 178 Integer.parseInt(Main.pref.get("cadastrewms.scale", CadastrePreferenceSetting.DEFAULT_GRAB_MULTIPLIER))); 178 179 } … … 199 200 dividedBbox.clear(); 200 201 if (factor < 4 || isRaster) { 201 for (int xEast = 0; xEast < factor; xEast++) 202 for (int xEast = 0; xEast < factor; xEast++) { 202 203 for (int xNorth = 0; xNorth < factor; xNorth++) { 203 204 dividedBbox.add(new EastNorthBound(new EastNorth(minEast + xEast * dEast, minNorth + xNorth * dNorth), 204 205 new EastNorth(minEast + (xEast + 1) * dEast, minNorth + (xNorth + 1) * dNorth))); 206 } 205 207 } 206 208 } else { … … 208 210 // grab all square in a spiral starting from the center (usually the most interesting place) 209 211 int c = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", String.valueOf(CadastrePreferenceSetting.DEFAULT_SQUARE_SIZE))); 210 lambertMin = lambertMin.add(- minEast%c, - minNorth%c);211 lambertMax = lambertMax.add(c - lambertMax.east() %c, c - lambertMax.north()%c);212 lambertMin = lambertMin.add(-minEast % c, -minNorth % c); 213 lambertMax = lambertMax.add(c - lambertMax.east() % c, c - lambertMax.north() % c); 212 214 EastNorth mid = lambertMax.getCenter(lambertMin); 213 215 mid = mid.add(-1, 1); // in case the boxes side is a pair, select the one one top,left to follow the rotation 214 mid = mid.add(- mid.east()%c, - mid.north()%c);215 int x = (int) (lambertMax.east() -lambertMin.east())/c;216 int y = (int) (lambertMax.north() -lambertMin.north())/c;217 int dx[] = {+1, 0,-1, 0};218 int dy[] = {0,-1, 0,+1};216 mid = mid.add(-mid.east() % c, -mid.north() % c); 217 int x = (int) (lambertMax.east() -lambertMin.east())/c; 218 int y = (int) (lambertMax.north() -lambertMin.north())/c; 219 int[] dx = {+1, 0, -1, 0}; 220 int[] dy = {0, -1, 0, +1}; 219 221 int currDir = -1, lDir = 1, i = 1, j = 0, k = -1; 220 222 if (x == 1) … … 231 233 } 232 234 j = 0; 233 currDir = (currDir+1) %4;235 currDir = (currDir+1) % 4; 234 236 } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? (x-1) : (y-1))) { 235 237 // the overall is a rectangle, not a square. Jump to the other side to grab next square. … … 240 242 } 241 243 j = lDir-1; 242 currDir = (currDir+1) %4;244 currDir = (currDir+1) % 4; 243 245 mid = new EastNorth(mid.east() + dx[currDir]*c*(lDir-1), mid.north() + dy[currDir]*c*(lDir-1)); 244 246 } … … 260 262 str += "\n"+tr("Is not vectorized."); 261 263 str += "\n"+tr("Bounding box: {0}", communeBBox); 262 if (!images.isEmpty())264 if (!images.isEmpty()) 263 265 str += "\n"+tr("Image size (px): {0}/{1}", images.get(0).image.getWidth(), images.get(0).image.getHeight()); 264 266 } else { … … 281 283 @Override 282 284 public void paint(Graphics2D g, final MapView mv, Bounds bounds) { 283 synchronized (this){285 synchronized (this) { 284 286 Object savedInterpolation = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION); 285 287 if (savedInterpolation == null) savedInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; … … 292 294 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 293 295 imagesLock.lock(); 294 for (GeorefImage img : images) 296 for (GeorefImage img : images) { 295 297 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 296 298 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 299 } 297 300 imagesLock.unlock(); 298 301 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); … … 329 332 refineGeoRef.setEnabled(isRaster && grabThread.getImagesToGrabSize() == 0); 330 333 Action resetOffset = new ResetOffsetActionMenu(); 331 resetOffset.setEnabled(!isRaster && !images.isEmpty() && (deltaEast !=0.0 || deltaNorth!=0.0));334 resetOffset.setEnabled(!isRaster && !images.isEmpty() && (deltaEast != 0.0 || deltaNorth != 0.0)); 332 335 return new Action[] { 333 336 LayerListDialog.getInstance().createShowHideLayerAction(), … … 447 450 * Called by CacheControl when a new cache file is created on disk. 448 451 * Save only primitives to keep cache independent of software changes. 449 * @param oos450 * @throws IOException451 452 */ 452 453 public void write(File associatedFile, ObjectOutputStream oos) throws IOException { … … 475 476 * Called by CacheControl when a cache file is read from disk. 476 477 * Cache uses only primitives to stay independent of software changes. 477 * @param ois478 * @throws IOException479 * @throws ClassNotFoundException480 478 */ 481 479 public boolean read(File associatedFile, ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException { … … 506 504 double maxX = ois.readDouble(); 507 505 double maxY = ois.readDouble(); 508 this.communeBBox = 506 this.communeBBox = new EastNorthBound(new EastNorth(minX, minY), new EastNorth(maxX, maxY)); 509 507 if (this.lambertZone != currentLambertZone && currentLambertZone != -1) { 510 508 JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+ … … 513 511 return false; 514 512 } 515 synchronized (this){513 synchronized (this) { 516 514 boolean EOF = false; 517 515 try { … … 534 532 } catch (EOFException ex) { 535 533 // expected exception when all images are read 534 Main.trace(ex); 536 535 } 537 536 } … … 560 559 Graphics g = newImg.getGraphics(); 561 560 // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left 562 int rasterDivider = (int) Math.sqrt(images.size());561 int rasterDivider = (int) Math.sqrt(images.size()); 563 562 for (int h = 0; h < lx.size(); h++) { 564 563 for (int v = 0; v < ly.size(); v++) { … … 569 568 } 570 569 } 571 synchronized (this) {570 synchronized (this) { 572 571 images.clear(); 573 572 images.add(new GeorefImage(newImg, min, max, this)); … … 581 580 * Works only for raster image layer (only one image in collection). 582 581 * Updates layer georeferences. 583 * @param en1 584 * @param en2 585 */ 586 public void cropImage(EastNorth en1, EastNorth en2){ 582 */ 583 public void cropImage(EastNorth en1, EastNorth en2) { 587 584 // adj1 is corner bottom, left 588 585 EastNorth adj1 = new EastNorth(en1.east() <= en2.east() ? en1.east() : en2.east(), … … 596 593 rasterMax = adj2; 597 594 setCommuneBBox(new EastNorthBound( 598 new EastNorth(0, 0),599 new EastNorth(images.get(0).image.getWidth()-1, images.get(0).image.getHeight()-1)));595 new EastNorth(0, 0), 596 new EastNorth(images.get(0).image.getWidth()-1, images.get(0).image.getHeight()-1))); 600 597 rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX()); 601 598 } … … 613 610 double minY = Double.MAX_VALUE; 614 611 double maxY = Double.MIN_VALUE; 615 for (GeorefImage image:images) {612 for (GeorefImage image:images) { 616 613 minX = image.min.east() < minX ? image.min.east() : minX; 617 614 maxX = image.max.east() > maxX ? image.max.east() : maxX; … … 649 646 images.get(0).shear(dx, dy); 650 647 } else { 651 deltaEast +=dx;652 deltaNorth +=dy;648 deltaEast += dx; 649 deltaNorth += dy; 653 650 } 654 651 } … … 675 672 EastNorthBound currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()), 676 673 mv.getEastNorth(mv.getWidth(), 0)); 677 int minX = ((int) currentView.min.east()/modulo+1)*modulo;678 int minY = ((int) currentView.min.north()/modulo+1)*modulo;679 int maxX = ((int) currentView.max.east()/modulo)*modulo;680 int maxY = ((int) currentView.max.north()/modulo)*modulo;681 int size =(maxX-minX)/modulo;682 if (size <20) {683 int px = size > 10 ? 2 : Math.abs(12-size);674 int minX = ((int) currentView.min.east()/modulo+1)*modulo; 675 int minY = ((int) currentView.min.north()/modulo+1)*modulo; 676 int maxX = ((int) currentView.max.east()/modulo)*modulo; 677 int maxY = ((int) currentView.max.north()/modulo)*modulo; 678 int size = (maxX-minX)/modulo; 679 if (size < 20) { 680 int px = size > 10 ? 2 : Math.abs(12-size); 684 681 g.setColor(Color.green); 685 for (int x =minX; x<=maxX; x+=modulo) {686 for (int y =minY; y<=maxY; y+=modulo) {687 Point p = mv.getPoint(new EastNorth(x, y));682 for (int x = minX; x <= maxX; x += modulo) { 683 for (int y = minY; y <= maxY; y += modulo) { 684 Point p = mv.getPoint(new EastNorth(x, y)); 688 685 g.drawLine(p.x-px, p.y, p.x+px, p.y); 689 686 g.drawLine(p.x, p.y-px, p.x, p.y+px);
Note:
See TracChangeset
for help on using the changeset viewer.