Changeset 1814 in josm for trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
- Timestamp:
- 2009-07-19T19:04:49+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r1797 r1814 27 27 import org.openstreetmap.josm.data.osm.WaySegment; 28 28 import org.openstreetmap.josm.data.projection.Projection; 29 import org.openstreetmap.josm.data.projection.Mercator;30 29 31 30 /** … … 55 54 } 56 55 57 protected DataSet getData() 58 { 59 return Main.ds; 56 protected DataSet getCurrentDataSet() { 57 return Main.main.getCurrentDataSet(); 60 58 } 61 59 … … 102 100 public ProjectionBounds getProjectionBounds() { 103 101 return new ProjectionBounds( 104 new EastNorth( 105 center.east() - getWidth()/2.0*scale, 106 center.north() - getHeight()/2.0*scale), 107 new EastNorth( 108 center.east() + getWidth()/2.0*scale, 109 center.north() + getHeight()/2.0*scale)); 102 new EastNorth( 103 center.east() - getWidth()/2.0*scale, 104 center.north() - getHeight()/2.0*scale), 105 new EastNorth( 106 center.east() + getWidth()/2.0*scale, 107 center.north() + getHeight()/2.0*scale)); 110 108 }; 111 109 112 110 public Bounds getRealBounds() { 113 111 return new Bounds( 114 getProjection().eastNorth2latlon(new EastNorth( 115 center.east() - getWidth()/2.0*scale, 116 center.north() - getHeight()/2.0*scale)), 117 getProjection().eastNorth2latlon(new EastNorth( 118 center.east() + getWidth()/2.0*scale, 119 center.north() + getHeight()/2.0*scale))); 112 getProjection().eastNorth2latlon(new EastNorth( 113 center.east() - getWidth()/2.0*scale, 114 center.north() - getHeight()/2.0*scale)), 115 getProjection().eastNorth2latlon(new EastNorth( 116 center.east() + getWidth()/2.0*scale, 117 center.north() + getHeight()/2.0*scale))); 120 118 }; 121 119 … … 163 161 */ 164 162 private void zoomTo(EastNorth newCenter, double newScale) { 165 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */ 163 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */ 166 164 boolean rep = false; 167 165 if (!newCenter.equals(center)) { … … 177 175 firePropertyChange("scale", oldScale, newScale); 178 176 } 179 if(rep) 177 if(rep) { 180 178 repaint(); 179 } 181 180 } 182 181 … … 186 185 187 186 public void zoomTo(LatLon newCenter) { 188 if (newCenter instanceof CachedLatLon)187 if(newCenter instanceof CachedLatLon) { 189 188 zoomTo(((CachedLatLon)newCenter).getEastNorth(), scale); 190 else189 } else { 191 190 zoomTo(getProjection().latlon2eastNorth(newCenter), scale); 191 } 192 192 } 193 193 … … 197 197 // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom 198 198 zoomTo(new EastNorth( 199 center.east() - (x - getWidth()/2.0) * (newScale - scale), 200 center.north() + (y - getHeight()/2.0) * (newScale - scale)), 201 newScale); 199 center.east() - (x - getWidth()/2.0) * (newScale - scale), 200 center.north() + (y - getHeight()/2.0) * (newScale - scale)), 201 newScale); 202 202 } 203 203 … … 213 213 // -20 to leave some border 214 214 int w = getWidth()-20; 215 if (w < 20) 215 if (w < 20) { 216 216 w = 20; 217 } 217 218 int h = getHeight()-20; 218 if (h < 20) 219 if (h < 20) { 219 220 h = 20; 221 } 220 222 221 223 double scaleX = (box.max.east()-box.min.east())/w; … … 228 230 public void zoomTo(Bounds box) { 229 231 zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min), 230 getProjection().latlon2eastNorth(box.max))); 232 getProjection().latlon2eastNorth(box.max))); 231 233 } 232 234 … … 238 240 double minDistanceSq = snapDistance; 239 241 Node minPrimitive = null; 240 for (Node n : get Data().nodes) {241 if (n.deleted || n.incomplete) 242 for (Node n : getCurrentDataSet().nodes) { 243 if (n.deleted || n.incomplete) { 242 244 continue; 245 } 243 246 Point sp = getPoint(n); 244 247 double dist = p.distanceSq(sp); … … 249 252 // when multiple nodes on one point, prefer new or selected nodes 250 253 else if(dist == minDistanceSq && minPrimitive != null 251 && ((n.id == 0 && n.selected) 252 || (!minPrimitive.selected && (n.selected || n.id == 0)))) 254 && ((n.id == 0 && n.selected) 255 || (!minPrimitive.selected && (n.selected || n.id == 0)))) { 253 256 minPrimitive = n; 257 } 254 258 } 255 259 return minPrimitive; … … 264 268 public final List<WaySegment> getNearestWaySegments(Point p) { 265 269 TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>(); 266 for (Way w : getData().ways) { 267 if (w.deleted || w.incomplete) continue; 270 for (Way w : getCurrentDataSet().ways) { 271 if (w.deleted || w.incomplete) { 272 continue; 273 } 268 274 Node lastN = null; 269 275 int i = -2; 270 276 for (Node n : w.nodes) { 271 277 i++; 272 if (n.deleted || n.incomplete) continue; 278 if (n.deleted || n.incomplete) { 279 continue; 280 } 273 281 if (lastN == null) { 274 282 lastN = n; … … 283 291 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 284 292 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) { 285 if(w.selected) // prefer selected ways a little bit293 if(w.selected) { 286 294 perDist -= 0.00001; 295 } 287 296 List<WaySegment> l; 288 297 if (nearest.containsKey(perDist)) { … … 315 324 public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) { 316 325 List<WaySegment> nearest = getNearestWaySegments(p); 317 if (ignore != null) nearest.removeAll(ignore); 326 if (ignore != null) { 327 nearest.removeAll(ignore); 328 } 318 329 return nearest.isEmpty() ? null : nearest.get(0); 319 330 } … … 376 387 public Collection<OsmPrimitive> getAllNearest(Point p) { 377 388 Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>(); 378 for (Way w : getData().ways) { 379 if (w.deleted || w.incomplete) continue; 389 for (Way w : getCurrentDataSet().ways) { 390 if (w.deleted || w.incomplete) { 391 continue; 392 } 380 393 Node lastN = null; 381 394 for (Node n : w.nodes) { 382 if (n.deleted || n.incomplete) continue; 395 if (n.deleted || n.incomplete) { 396 continue; 397 } 383 398 if (lastN == null) { 384 399 lastN = n; … … 393 408 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) { 394 409 nearest.add(w); 395 break;396 }410 break; 411 } 397 412 lastN = n; 398 }399 }400 for (Node n : get Data().nodes) {413 } 414 } 415 for (Node n : getCurrentDataSet().nodes) { 401 416 if (!n.deleted && !n.incomplete 402 417 && getPoint(n).distanceSq(p) < snapDistance) { … … 417 432 public Collection<Node> getNearestNodes(Point p) { 418 433 Collection<Node> nearest = new HashSet<Node>(); 419 for (Node n : get Data().nodes) {434 for (Node n : getCurrentDataSet().nodes) { 420 435 if (!n.deleted && !n.incomplete 421 436 && getPoint(n).distanceSq(p) < snapDistance) { … … 436 451 public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) { 437 452 Collection<Node> nearest = getNearestNodes(p); 438 if (nearest == null) return null; 439 if (ignore != null) nearest.removeAll(ignore); 453 if (nearest == null) return null; 454 if (ignore != null) { 455 nearest.removeAll(ignore); 456 } 440 457 return nearest.isEmpty() ? null : nearest; 441 458 }
Note:
See TracChangeset
for help on using the changeset viewer.
