Changeset 4423 in josm
- Timestamp:
- 2011-09-15T15:14:22+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r4363 r4423 43 43 44 44 public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 45 this.minLat = roundToOsmPrecision(minlat); 46 this.minLon = roundToOsmPrecision(minlon); 47 this.maxLat = roundToOsmPrecision(maxlat); 48 this.maxLon = roundToOsmPrecision(maxlon); 45 this.minLat = LatLon.roundToOsmPrecision(minlat); 46 this.minLon = LatLon.roundToOsmPrecision(minlon); 47 this.maxLat = LatLon.roundToOsmPrecision(maxlat); 48 this.maxLon = LatLon.roundToOsmPrecision(maxlon); 49 49 } 50 50 … … 53 53 if (coords.length != 4) 54 54 throw new IllegalArgumentException(MessageFormat.format("Expected array of length 4, got {0}", coords.length)); 55 this.minLat = roundToOsmPrecision(coords[0]); 56 this.minLon = roundToOsmPrecision(coords[1]); 57 this.maxLat = roundToOsmPrecision(coords[2]); 58 this.maxLon = roundToOsmPrecision(coords[3]); 55 this.minLat = LatLon.roundToOsmPrecision(coords[0]); 56 this.minLon = LatLon.roundToOsmPrecision(coords[1]); 57 this.maxLat = LatLon.roundToOsmPrecision(coords[2]); 58 this.maxLon = LatLon.roundToOsmPrecision(coords[3]); 59 59 } 60 60 … … 81 81 throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[3])); 82 82 83 this.minLat = roundToOsmPrecision(values[0]); 84 this.minLon = roundToOsmPrecision(values[1]); 85 this.maxLat = roundToOsmPrecision(values[2]); 86 this.maxLon = roundToOsmPrecision(values[3]); 83 this.minLat = LatLon.roundToOsmPrecision(values[0]); 84 this.minLon = LatLon.roundToOsmPrecision(values[1]); 85 this.maxLat = LatLon.roundToOsmPrecision(values[2]); 86 this.maxLon = LatLon.roundToOsmPrecision(values[3]); 87 87 } 88 88 … … 114 114 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0.0 exptected, got {1}", "lonExtent", lonExtent)); 115 115 116 this.minLat = roundToOsmPrecision(center.lat() - latExtent / 2); 117 this.minLon = roundToOsmPrecision(center.lon() - lonExtent / 2); 118 this.maxLat = roundToOsmPrecision(center.lat() + latExtent / 2); 119 this.maxLon = roundToOsmPrecision(center.lon() + lonExtent / 2); 116 this.minLat = LatLon.roundToOsmPrecision(center.lat() - latExtent / 2); 117 this.minLon = LatLon.roundToOsmPrecision(center.lon() - lonExtent / 2); 118 this.maxLat = LatLon.roundToOsmPrecision(center.lat() + latExtent / 2); 119 this.maxLon = LatLon.roundToOsmPrecision(center.lon() + lonExtent / 2); 120 120 } 121 121 … … 145 145 public void extend(LatLon ll) { 146 146 if (ll.lat() < minLat) { 147 minLat = roundToOsmPrecision(ll.lat()); 147 minLat = LatLon.roundToOsmPrecision(ll.lat()); 148 148 } 149 149 if (ll.lon() < minLon) { 150 minLon = roundToOsmPrecision(ll.lon()); 150 minLon = LatLon.roundToOsmPrecision(ll.lon()); 151 151 } 152 152 if (ll.lat() > maxLat) { 153 maxLat = roundToOsmPrecision(ll.lat()); 153 maxLat = LatLon.roundToOsmPrecision(ll.lat()); 154 154 } 155 155 if (ll.lon() > maxLon) { 156 maxLon = roundToOsmPrecision(ll.lon()); 156 maxLon = LatLon.roundToOsmPrecision(ll.lon()); 157 157 } 158 158 } … … 284 284 return true; 285 285 } 286 287 /**288 * Returns the value rounded to OSM precisions, i.e. to289 * LatLon.MAX_SERVER_PRECISION290 *291 * @return rounded value292 */293 private double roundToOsmPrecision(double value) {294 return Math.round(value / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION;295 }296 286 } -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r4206 r4423 223 223 return "LatLon[lat="+lat()+",lon="+lon()+"]"; 224 224 } 225 225 226 /** 227 * Returns the value rounded to OSM precisions, i.e. to 228 * LatLon.MAX_SERVER_PRECISION 229 * 230 * @return rounded value 231 */ 232 public static double roundToOsmPrecision(double value) { 233 return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; 234 } 235 226 236 /** 227 237 * Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. to … … 232 242 public LatLon getRoundedToOsmPrecision() { 233 243 return new LatLon( 234 Math.round(lat() / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION,235 Math.round(lon() / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION244 roundToOsmPrecision(lat()), 245 roundToOsmPrecision(lon()) 236 246 ); 237 247 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4405 r4423 39 39 public String getUrlString() { 40 40 return urlString; 41 } 42 } 43 44 public static class ImageryBounds extends Bounds { 45 public ImageryBounds(String asString, String separator) { 46 super(asString, separator); 47 } 48 49 private List<Shape> shapes = new ArrayList<Shape>(); 50 51 public void addShape(Shape shape) { 52 this.shapes.add(shape); 53 } 54 55 public void setShapes(List<Shape> shapes) { 56 this.shapes = shapes; 57 } 58 59 public List<Shape> getShapes() { 60 return shapes; 41 61 } 42 62 } … … 52 72 private int defaultMaxZoom = 0; 53 73 private int defaultMinZoom = 0; 54 private Bounds bounds = null; 74 private ImageryBounds bounds = null; 55 75 private List<String> serverProjections; 56 76 private String attributionText; … … 107 127 res.add(attributionImage); 108 128 res.add(termsOfUseURL); 129 // Shapes 130 String shapesString = ""; 131 if (bounds != null) { 132 for (Shape s : bounds.getShapes()) { 133 if (!shapesString.isEmpty()) { 134 shapesString += ";"; 135 } 136 shapesString += s.encodeAsString(","); 137 } 138 } 139 res.add(shapesString.isEmpty() ? null : shapesString); 109 140 return res; 110 141 } … … 128 159 if(array.size() >= 5 && !array.get(4).isEmpty()) { 129 160 try { 130 bounds = new Bounds(array.get(4), ","); 161 bounds = new ImageryBounds(array.get(4), ","); 131 162 } catch (IllegalArgumentException e) { 132 163 Main.warn(e.toString()); … … 144 175 if(array.size() >= 9 && !array.get(8).isEmpty()) { 145 176 setTermsOfUseURL(array.get(8)); 177 } 178 if(bounds != null && array.size() >= 10 && !array.get(9).isEmpty()) { 179 try { 180 for (String s : array.get(9).split(";")) { 181 bounds.addShape(new Shape(s, ",")); 182 } 183 } catch (IllegalArgumentException e) { 184 Main.warn(e.toString()); 185 } 146 186 } 147 187 } … … 201 241 } 202 242 203 public void setBounds(Bounds b) { 243 public void setBounds(ImageryBounds b) { 204 244 this.bounds = b; 205 245 } 206 246 207 public Bounds getBounds() { 247 public ImageryBounds getBounds() { 208 248 return bounds; 209 249 } 210 250 211 251 public void setAttributionText(String text) { 212 252 attributionText = text; 213 253 } 214 254 -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4416 r4423 18 18 import java.net.MalformedURLException; 19 19 import java.net.URL; 20 import java.util.ArrayList; 20 21 import java.util.HashMap; 21 22 import java.util.List; … … 51 52 52 53 import org.openstreetmap.gui.jmapviewer.JMapViewer; 54 import org.openstreetmap.gui.jmapviewer.MapPolygonImpl; 53 55 import org.openstreetmap.gui.jmapviewer.MapRectangleImpl; 56 import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon; 54 57 import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; 55 58 import org.openstreetmap.josm.Main; 56 import org.openstreetmap.josm.data.Bounds;57 59 import org.openstreetmap.josm.data.imagery.ImageryInfo; 60 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; 58 61 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 59 62 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 60 63 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 64 import org.openstreetmap.josm.data.imagery.Shape; 61 65 import org.openstreetmap.josm.gui.layer.ImageryLayer; 62 66 import org.openstreetmap.josm.gui.layer.TMSLayer; … … 418 422 map.setZoomContolsVisible(false); 419 423 map.setPreferredSize(new Dimension(200, 200)); 420 add(map, GBC.std().insets(5, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(0.33 3, 0.6).insets(5, 0, 0, 0));424 add(map, GBC.std().insets(5, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(0.33, 0.6).insets(5, 0, 0, 0)); 421 425 422 426 listdef.getSelectionModel().addListSelectionListener(new DefListSelectionListener()); … … 460 464 // Listener of default providers list selection 461 465 private final class DefListSelectionListener implements ListSelectionListener { 462 // The current drawn rectangles 466 // The current drawn rectangles and polygons 463 467 private final Map<Integer, MapRectangle> mapRectangles; 468 private final Map<Integer, List<MapPolygon>> mapPolygons; 464 469 465 470 private DefListSelectionListener() { 466 471 this.mapRectangles = new HashMap<Integer, MapRectangle>(); 472 this.mapPolygons = new HashMap<Integer, List<MapPolygon>>(); 467 473 } 468 474 469 475 @Override 470 476 public void valueChanged(ListSelectionEvent e) { 471 // First index is set to -1 when the list is refreshed, so discard all map rectangles 477 // First index is set to -1 when the list is refreshed, so discard all map rectangles and polygons 472 478 if (e.getFirstIndex() == -1) { 473 479 map.removeAllMapRectangles(); 480 map.removeAllMapPolygons(); 474 481 mapRectangles.clear(); 482 mapPolygons.clear(); 475 483 // Only process complete (final) selection events 476 484 } else if (!e.getValueIsAdjusting()) { 477 485 for (int i = e.getFirstIndex(); i<=e.getLastIndex(); i++) { 478 Bounds bounds = modeldef.getRow(i).getBounds(); 479 if (bounds != null) { 480 if (listdef.getSelectionModel().isSelectedIndex(i)) { 481 if (!mapRectangles.containsKey(i)) { 482 // Add new map rectangle 483 MapRectangle rectangle = new MapRectangleImpl(bounds); 484 mapRectangles.put(i, rectangle); 485 map.addMapRectangle(rectangle); 486 updateBoundsAndShapes(i); 487 } 488 // If needed, adjust map to show all map rectangles and polygons 489 if (!mapRectangles.isEmpty() || !mapPolygons.isEmpty()) { 490 map.setDisplayToFitMapElements(false, true, true); 491 map.zoomOut(); 492 } 493 } 494 } 495 496 private void updateBoundsAndShapes(int i) { 497 ImageryBounds bounds = modeldef.getRow(i).getBounds(); 498 if (bounds != null) { 499 List<Shape> shapes = bounds.getShapes(); 500 if (shapes != null && !shapes.isEmpty()) { 501 if (listdef.getSelectionModel().isSelectedIndex(i)) { 502 if (!mapPolygons.containsKey(i)) { 503 List<MapPolygon> list = new ArrayList<MapPolygon>(); 504 mapPolygons.put(i, list); 505 // Add new map polygons 506 for (Shape shape : shapes) { 507 MapPolygon polygon = new MapPolygonImpl(shape.getPoints()); 508 list.add(polygon); 509 map.addMapPolygon(polygon); 486 510 } 487 } else if (mapRectangles.containsKey(i)) {488 // Remove previousliy drawn map rectangle489 map.removeMapRectangle(mapRectangles.get(i));490 mapRectangles.remove(i);491 511 } 512 } else if (mapPolygons.containsKey(i)) { 513 // Remove previously drawn map polygons 514 for (MapPolygon polygon : mapPolygons.get(i)) { 515 map.removeMapPolygon(polygon); 516 } 517 mapPolygons.remove(i); 492 518 } 493 } 494 // If needed, adjust map to show all map rectangles 495 if (!mapRectangles.isEmpty()) { 496 map.setDisplayToFitMapRectangle(); 497 map.zoomOut(); 519 // Only display bounds when no polygons (shapes) are defined for this provider 520 } else { 521 if (listdef.getSelectionModel().isSelectedIndex(i)) { 522 if (!mapRectangles.containsKey(i)) { 523 // Add new map rectangle 524 MapRectangle rectangle = new MapRectangleImpl(bounds); 525 mapRectangles.put(i, rectangle); 526 map.addMapRectangle(rectangle); 527 } 528 } else if (mapRectangles.containsKey(i)) { 529 // Remove previously drawn map rectangle 530 map.removeMapRectangle(mapRectangles.get(i)); 531 mapRectangles.remove(i); 532 } 498 533 } 499 534 } -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r4419 r4423 19 19 20 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.data.Bounds;22 21 import org.openstreetmap.josm.data.imagery.ImageryInfo; 22 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; 23 23 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 24 import org.openstreetmap.josm.data.imagery.Shape; 24 25 import org.openstreetmap.josm.io.MirroredInputStream; 25 26 import org.openstreetmap.josm.io.UTFInputStreamReader; … … 41 42 SUPPORTED_PROJECTIONS, 42 43 PR, 44 BOUNDS, 45 SHAPE, 43 46 UNKNOWN, // element is not recognized in the current context 44 47 } 45 48 46 public ImageryReader(String source) throws IOException{49 public ImageryReader(String source) { 47 50 this.source = source; 48 51 } … … 143 146 // 5th parameter optional for bounds 144 147 try { 145 info.setBounds(new Bounds(val[4], ",")); 148 info.setBounds(new ImageryBounds(val[4], ",")); 146 149 } catch (IllegalArgumentException e) { 147 150 Main.warn(e.toString()); … … 190 193 191 194 ImageryInfo entry; 192 Bounds bounds; 195 ImageryBounds bounds; 196 Shape shape; 193 197 List<String> supported_srs; 194 198 … … 241 245 } else if (qName.equals("bounds")) { 242 246 try { 243 bounds = new Bounds( 247 bounds = new ImageryBounds( 244 248 atts.getValue("min-lat") + "," + 245 249 atts.getValue("min-lon") + "," + … … 249 253 break; 250 254 } 251 newState = State. ENTRY_ATTRIBUTE;255 newState = State.BOUNDS; 252 256 } else if (qName.equals("supported-projections")) { 253 257 supported_srs = new ArrayList<String>(); 254 258 newState = State.SUPPORTED_PROJECTIONS; 259 } 260 break; 261 case BOUNDS: 262 if (qName.equals("shape")) { 263 shape = new Shape(); 264 newState = State.SHAPE; 265 } 266 break; 267 case SHAPE: 268 if (qName.equals("point")) { 269 try { 270 shape.addPoint(atts.getValue("lat"), atts.getValue("lon")); 271 } catch (IllegalArgumentException e) { 272 break; 273 } 255 274 } 256 275 break; … … 339 358 } 340 359 } 341 } else if (qName.equals("bounds")) {342 entry.setBounds(bounds);343 bounds = null;344 360 } else if (qName.equals("attribution-text")) { 345 361 entry.setAttributionText(accumulator.toString()); … … 359 375 } 360 376 break; 377 case BOUNDS: 378 entry.setBounds(bounds); 379 bounds = null; 380 break; 381 case SHAPE: 382 bounds.addShape(shape); 383 shape = null; 384 break; 361 385 case PR: 362 386 supported_srs.add(accumulator.toString());
Note:
See TracChangeset
for help on using the changeset viewer.