Changeset 71 in josm for src/org/openstreetmap/josm/gui/NavigatableComponent.java
- Timestamp:
- 2006-03-25T16:21:09+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r66 r71 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.GeoPoint; 10 import org.openstreetmap.josm.data.coor.LatLon; 11 import org.openstreetmap.josm.data.coor.EastNorth; 11 12 import org.openstreetmap.josm.data.osm.LineSegment; 12 13 import org.openstreetmap.josm.data.osm.Node; … … 32 33 * Center n/e coordinate of the desired screen center. 33 34 */ 34 protected GeoPointcenter;35 protected EastNorth center; 35 36 36 37 /** … … 46 47 * change the center by accessing the return value. Use zoomTo instead. 47 48 */ 48 public GeoPoint getCenter() { 49 return center.clone(); 50 } 51 52 /** 53 * Get geographic coordinates from a specific pixel coordination 54 * on the screen. 55 * 56 * If you don't need it, provide false at third parameter to speed 57 * up the calculation. 58 * 49 public EastNorth getCenter() { 50 return center; 51 } 52 53 /** 59 54 * @param x X-Pixelposition to get coordinate from 60 55 * @param y Y-Pixelposition to get coordinate from 61 * @param latlon If set, the return value will also have the 62 * latitude/longitude filled. 63 * 64 * @return The geographic coordinate, filled with x/y (northing/easting) 65 * settings and, if requested with latitude/longitude. 66 */ 67 public GeoPoint getPoint(int x, int y, boolean latlon) { 68 GeoPoint p = new GeoPoint(); 69 p.x = center.x + (x - getWidth()/2.0)*scale; 70 p.y = center.y - (y - getHeight()/2.0)*scale; 71 if (latlon) 72 getProjection().xy2latlon(p); 73 return p; 74 } 75 76 /** 77 * Return the point on the screen where this GeoPoint would be. 56 * 57 * @return Geographic coordinates from a specific pixel coordination 58 * on the screen. 59 */ 60 public EastNorth getEastNorth(int x, int y) { 61 return new EastNorth( 62 center.east() + (x - getWidth()/2.0)*scale, 63 center.north() - (y - getHeight()/2.0)*scale); 64 } 65 66 /** 67 * @param x X-Pixelposition to get coordinate from 68 * @param y Y-Pixelposition to get coordinate from 69 * 70 * @return Geographic unprojected coordinates from a specific pixel coordination 71 * on the screen. 72 */ 73 public LatLon getLatLon(int x, int y) { 74 EastNorth eastNorth = new EastNorth( 75 center.east() + (x - getWidth()/2.0)*scale, 76 center.north() - (y - getHeight()/2.0)*scale); 77 return Main.pref.getProjection().eastNorth2latlon(eastNorth); 78 } 79 80 /** 81 * Return the point on the screen where this Coordinate would be. 78 82 * @param point The point, where this geopoint would be drawn. 79 83 * @return The point on screen where "point" would be drawn, relative 80 84 * to the own top/left. 81 85 */ 82 public Point getScreenPoint(GeoPoint point) { 83 GeoPoint p; 84 if (!Double.isNaN(point.x) && !Double.isNaN(point.y)) 85 p = point; 86 else { 87 if (Double.isNaN(point.lat) || Double.isNaN(point.lon)) 88 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set."); 89 p = point.clone(); 90 getProjection().latlon2xy(p); 91 } 92 double x = (p.x-center.x)/scale + getWidth()/2; 93 double y = (center.y-p.y)/scale + getHeight()/2; 86 public Point getPoint(EastNorth p) { 87 double x = (p.east()-center.east())/scale + getWidth()/2; 88 double y = (center.north()-p.north())/scale + getHeight()/2; 94 89 return new Point((int)x,(int)y); 95 90 } … … 101 96 * @param scale The scale to use. 102 97 */ 103 public void zoomTo( GeoPointnewCenter, double scale) {104 center = newCenter .clone();105 getProjection(). xy2latlon(center);98 public void zoomTo(EastNorth newCenter, double scale) { 99 center = newCenter; 100 getProjection().eastNorth2latlon(center); 106 101 this.scale = scale; 107 102 repaint(); … … 127 122 * 128 123 * @param p The point on screen. 129 * @param lsInsteadWay Whether the line segment (true) or only the whole124 * @param segmentInsteadWay Whether the line segment (true) or only the whole 130 125 * way should be returned. 131 126 * @return The primitive, that is nearest to the point p. 132 127 */ 133 public OsmPrimitive getNearest(Point p, boolean lsInsteadWay) {128 public OsmPrimitive getNearest(Point p, boolean segmentInsteadWay) { 134 129 double minDistanceSq = Double.MAX_VALUE; 135 130 OsmPrimitive minPrimitive = null; … … 139 134 if (n.isDeleted()) 140 135 continue; 141 Point sp = get ScreenPoint(n.coor);136 Point sp = getPoint(n.eastNorth); 142 137 double dist = p.distanceSq(sp); 143 138 if (minDistanceSq > dist && dist < 100) { … … 151 146 // for whole ways, try the ways first 152 147 minDistanceSq = Double.MAX_VALUE; 153 if (! lsInsteadWay) {154 for (Way w : Main.main.ds.wa ies) {148 if (!segmentInsteadWay) { 149 for (Way w : Main.main.ds.ways) { 155 150 if (w.isDeleted()) 156 151 continue; … … 158 153 if (ls.isDeleted() || ls.incomplete) 159 154 continue; 160 Point A = get ScreenPoint(ls.from.coor);161 Point B = get ScreenPoint(ls.to.coor);155 Point A = getPoint(ls.from.eastNorth); 156 Point B = getPoint(ls.to.eastNorth); 162 157 double c = A.distanceSq(B); 163 158 double a = p.distanceSq(B); … … 179 174 if (ls.isDeleted() || ls.incomplete) 180 175 continue; 181 Point A = get ScreenPoint(ls.from.coor);182 Point B = get ScreenPoint(ls.to.coor);176 Point A = getPoint(ls.from.eastNorth); 177 Point B = getPoint(ls.to.eastNorth); 183 178 double c = A.distanceSq(B); 184 179 double a = p.distanceSq(B); … … 201 196 * If its a node, return all line segments and 202 197 * streets the node is part of, as well as all nodes 203 * (with their line segments and wa ies) with the same198 * (with their line segments and ways) with the same 204 199 * location. 205 200 * 206 * If its a line segment, return all wa ies this segment201 * If its a line segment, return all ways this segment 207 202 * belongs to as well as all line segments that are between 208 * the same nodes (in both direction) with all their wa ies.203 * the same nodes (in both direction) with all their ways. 209 204 * 210 205 * @return A collection of all items or <code>null</code> … … 221 216 Node node = (Node)osm; 222 217 for (Node n : Main.main.ds.nodes) 223 if (!n.isDeleted() && n.coor.equals LatLon(node.coor))218 if (!n.isDeleted() && n.coor.equals(node.coor)) 224 219 c.add(n); 225 220 for (LineSegment ls : Main.main.ds.lineSegments) … … 235 230 } 236 231 if (osm instanceof Node || osm instanceof LineSegment) { 237 for (Way t : Main.main.ds.wa ies) {232 for (Way t : Main.main.ds.ways) { 238 233 if (t.isDeleted()) 239 234 continue;
Note:
See TracChangeset
for help on using the changeset viewer.