Changeset 12093 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2017-05-10T12:22:20+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r11844 r12093 15 15 16 16 private static final long serialVersionUID = 1L; 17 18 public static final EastNorth ZERO = new EastNorth(0, 0); 17 19 18 20 /** -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r12084 r12093 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.Preferences.pref; 14 import org.openstreetmap.josm.data.Preferences.writeExplicitly; 14 15 import org.openstreetmap.josm.data.coor.EastNorth; 15 16 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.data.projection.Projection; 18 import org.openstreetmap.josm.data.projection.Projections; 16 19 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 17 20 import org.openstreetmap.josm.gui.layer.ImageryLayer; 18 21 22 /** 23 * Class to save a displacement of background imagery as a bookmark. 24 * 25 * Known offset bookmarks will be stored in the preferences and can be 26 * restored by the user in later sessions. 27 */ 19 28 public class OffsetBookmark { 20 29 private static final List<OffsetBookmark> allBookmarks = new ArrayList<>(); … … 23 32 @pref private String imagery_name; 24 33 @pref private String name; 25 @pref private double dx, dy;34 @pref @writeExplicitly private double dx, dy; 26 35 @pref private double center_lon, center_lat; 27 36 28 37 public boolean isUsable(ImageryLayer layer) { 29 38 if (projection_code == null) return false; 30 if (!Main.getProjection().toCode().equals(projection_code) ) return false;39 if (!Main.getProjection().toCode().equals(projection_code) && !hasCenter()) return false; 31 40 return layer.getInfo().getName().equals(imagery_name); 32 41 } … … 83 92 } 84 93 85 public EastNorth getOffset() { 94 /** 95 * Get displacement in EastNorth coordinates of the original projection. 96 * 97 * @see #getProjectionCode() 98 * @return the displacement 99 */ 100 public EastNorth getDisplacement() { 86 101 return new EastNorth(dx, dy); 87 102 } 88 103 104 /** 105 * Get displacement in EastNorth coordinates of a given projection. 106 * 107 * Displacement will be converted to the given projection, with respect to the 108 * center (reference point) of this bookmark. 109 * @param proj the projection 110 * @return the displacement, converted to that projection 111 */ 112 public EastNorth getDisplacement(Projection proj) { 113 if (proj.toCode().equals(projection_code)) { 114 return getDisplacement(); 115 } 116 LatLon center = getCenter(); 117 Projection offsetProj = Projections.getProjectionByCode(projection_code); 118 EastNorth centerEN = offsetProj.latlon2eastNorth(center); 119 EastNorth shiftedEN = centerEN.add(getDisplacement()); 120 LatLon shifted = offsetProj.eastNorth2latlon(shiftedEN); 121 EastNorth centerEN2 = proj.latlon2eastNorth(center); 122 EastNorth shiftedEN2 = proj.latlon2eastNorth(shifted); 123 return shiftedEN2.subtract(centerEN2); 124 } 125 126 /** 127 * Get center/reference point of the bookmark. 128 * 129 * Basically this is the place where it was created and is valid. 130 * The center may be unrecorded (see {@link #hasCenter()), in which 131 * case a dummy center (0,0) will be returned. 132 * @return the center 133 */ 89 134 public LatLon getCenter() { 90 135 return new LatLon(center_lat, center_lon); 91 136 } 92 137 138 /** 139 * Check if bookmark has a valid center. 140 * @return true if bookmark has a valid center 141 */ 142 public boolean hasCenter() { 143 return center_lat != 0 || center_lon != 0; 144 } 145 93 146 public void setProjectionCode(String projectionCode) { 94 147 this.projection_code = projectionCode; … … 103 156 } 104 157 105 public void set Offset(EastNorth offset) {106 this.dx = offset.east();107 this.dy = offset.north();158 public void setDisplacement(EastNorth displacement) { 159 this.dx = displacement.east(); 160 this.dy = displacement.north(); 108 161 } 109 162
Note:
See TracChangeset
for help on using the changeset viewer.