Changeset 32211 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
- Timestamp:
- 2016-06-01T00:55:28+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r32060 r32211 21 21 import java.util.ArrayList; 22 22 import java.util.HashSet; 23 import java.util.Locale; 23 24 import java.util.Vector; 24 25 import java.util.concurrent.locks.Lock; … … 39 40 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 40 41 import org.openstreetmap.josm.gui.layer.Layer; 42 import org.openstreetmap.josm.gui.util.GuiHelper; 41 43 42 44 /** … … 77 79 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0)); 78 80 79 private boolean isRaster = false;80 private boolean isAlreadyGeoreferenced = false;81 private boolean isRaster; 82 private boolean isAlreadyGeoreferenced; 81 83 public double X0, Y0, angle, fX, fY; 82 84 … … 87 89 88 90 // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels 89 public double deltaEast =0;90 public double deltaNorth =0;91 public double deltaEast; 92 public double deltaNorth; 91 93 92 94 private Action saveAsPng; … … 107 109 Main.map.mapView.repaint(); 108 110 } 109 110 111 } 111 112 … … 114 115 public GrabThread grabThread; 115 116 117 /** 118 * Constructs a new {@code WMSLayer}. 119 */ 116 120 public WMSLayer() { 117 121 this(tr("Blank Layer"), "", -1); … … 142 146 143 147 private static String buildName(String location, String codeCommune) { 144 String ret = location.toUpperCase(); 145 if (codeCommune != null && !codeCommune. equals(""))148 String ret = location.toUpperCase(Locale.FRANCE); 149 if (codeCommune != null && !codeCommune.isEmpty()) 146 150 ret += "(" + codeCommune + ")"; 147 151 return ret; … … 149 153 150 154 private String rebuildName() { 151 return buildName(this.location.toUpperCase(), this.codeCommune); 155 return buildName(this.location.toUpperCase(Locale.FRANCE), this.codeCommune); 152 156 } 153 157 … … 157 161 // if it is the first layer, use the communeBBox as grab bbox (and not divided) 158 162 if (Main.map.mapView.getAllLayers().size() == 1 ) { 159 b = this.getCommuneBBox().toBounds(); 160 Main.map.mapView.zoomTo(b); 161 divideBbox(b, 1); 163 final Bounds bounds = this.getCommuneBBox().toBounds(); 164 GuiHelper.runInEDTAndWait(new Runnable() { 165 @Override 166 public void run() { 167 Main.map.mapView.zoomTo(bounds); 168 } 169 }); 170 divideBbox(bounds, 1); 162 171 } else { 163 172 if (isRaster) { 164 b = new Bounds(Main.getProjection().eastNorth2latlon(rasterMin), Main.getProjection().eastNorth2latlon(rasterMax)); 165 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", 166 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 173 divideBbox(new Bounds(Main.getProjection().eastNorth2latlon(rasterMin), Main.getProjection().eastNorth2latlon(rasterMax)), 174 Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 167 175 } else 168 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", CadastrePreferenceSetting.DEFAULT_GRAB_MULTIPLIER))); 176 divideBbox(b, 177 Integer.parseInt(Main.pref.get("cadastrewms.scale", CadastrePreferenceSetting.DEFAULT_GRAB_MULTIPLIER))); 169 178 } 170 179 grabThread.addImages(dividedBbox); … … 223 232 j = 0; 224 233 currDir = (currDir+1)%4; 225 } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? x-1 : y-1)) {234 } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? (x-1) : (y-1))) { 226 235 // the overall is a rectangle, not a square. Jump to the other side to grab next square. 227 236 k++; … … 251 260 str += "\n"+tr("Is not vectorized."); 252 261 str += "\n"+tr("Bounding box: {0}", communeBBox); 253 if(images. size()>0)262 if(!images.isEmpty()) 254 263 str += "\n"+tr("Image size (px): {0}/{1}", images.get(0).image.getWidth(), images.get(0).image.getHeight()); 255 } else 264 } else { 256 265 str += "\n"+tr("Is vectorized."); 257 266 str += "\n"+tr("Commune bbox: {0}", communeBBox); 267 } 258 268 return str; 259 269 } … … 266 276 @Override 267 277 public void mergeFrom(Layer from) { 278 // Do nothing 268 279 } 269 280 … … 318 329 refineGeoRef.setEnabled(isRaster && grabThread.getImagesToGrabSize() == 0); 319 330 Action resetOffset = new ResetOffsetActionMenu(); 320 resetOffset.setEnabled(!isRaster && images. size() > 0&& (deltaEast!=0.0 || deltaNorth!=0.0));331 resetOffset.setEnabled(!isRaster && !images.isEmpty() && (deltaEast!=0.0 || deltaNorth!=0.0)); 321 332 return new Action[] { 322 333 LayerListDialog.getInstance().createShowHideLayerAction(), … … 328 339 resetOffset, 329 340 new LayerListPopup.InfoAction(this), 330 331 341 }; 332 342 } … … 368 378 return minX+","+minY+","+maxX+","+maxY; 369 379 } 370 371 380 372 381 public String getLocation() { … … 548 557 int newWidth = oldImgWidth*lx.size(); 549 558 int newHeight = oldImgHeight*ly.size(); 550 BufferedImage new _img = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/);551 Graphics g = new _img.getGraphics();559 BufferedImage newImg = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/); 560 Graphics g = newImg.getGraphics(); 552 561 // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left 553 562 int rasterDivider = (int)Math.sqrt(images.size()); … … 562 571 synchronized(this) { 563 572 images.clear(); 564 images.add(new GeorefImage(new _img, min, max, this));573 images.add(new GeorefImage(newImg, min, max, this)); 565 574 } 566 575 } … … 586 595 rasterMin = adj1; 587 596 rasterMax = adj2; 588 setCommuneBBox(new EastNorthBound(new EastNorth(0,0), new EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1))); 597 setCommuneBBox(new EastNorthBound( 598 new EastNorth(0,0), 599 new EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1))); 589 600 rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX()); 590 601 } … … 598 609 return communeBBox; 599 610 } 600 double min _x= Double.MAX_VALUE;601 double max _x= Double.MIN_VALUE;602 double min _y= Double.MAX_VALUE;603 double max _y= Double.MIN_VALUE;611 double minX = Double.MAX_VALUE; 612 double maxX = Double.MIN_VALUE; 613 double minY = Double.MAX_VALUE; 614 double maxY = Double.MIN_VALUE; 604 615 for (GeorefImage image:images){ 605 min_x = image.min.east() < min_x ? image.min.east() : min_x; 606 max_x = image.max.east() > max_x ? image.max.east() : max_x; 607 min_y = image.min.north() < min_y ? image.min.north() : min_y; 608 max_y = image.max.north() > max_y ? image.max.north() : max_y; 609 } 610 EastNorthBound maxGrabbedBBox = new EastNorthBound(new EastNorth(min_x, min_y), new EastNorth(max_x, max_y)); 611 return maxGrabbedBBox; 616 minX = image.min.east() < minX ? image.min.east() : minX; 617 maxX = image.max.east() > maxX ? image.max.east() : maxX; 618 minY = image.min.north() < minY ? image.min.north() : minY; 619 maxY = image.max.north() > maxY ? image.max.north() : maxY; 620 } 621 return new EastNorthBound(new EastNorth(minX, minY), new EastNorth(maxX, maxY)); 612 622 } 613 623 … … 653 663 this.rasterMin = rasterMin.rotate(rasterCenter, angle); 654 664 this.rasterMax = rasterMax.rotate(rasterCenter, angle); 655 // double proportion = dst1.distance(dst2)/org1.distance(org2);656 665 images.get(0).rotate(rasterCenter, angle); 657 666 this.angle += angle; … … 718 727 imagesLock.unlock(); 719 728 } 720 721 729 }
Note:
See TracChangeset
for help on using the changeset viewer.
