Changeset 33309 in osm for applications/editors/josm/plugins
- Timestamp:
- 2017-05-13T14:21:55+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r32528 r33309 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.io.IOException; 8 9 import java.io.InputStream; 9 10 import java.io.UnsupportedEncodingException; … … 20 21 import org.openstreetmap.josm.data.coor.LatLon; 21 22 import org.openstreetmap.josm.data.projection.Projection; 22 import org.openstreetmap.josm.gui.layer. ImageryLayer;23 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 23 24 import org.openstreetmap.josm.tools.ImageProvider; 24 25 import org.openstreetmap.josm.tools.Shortcut; 26 import org.xml.sax.SAXException; 25 27 26 28 /** … … 56 58 Projection proj = Main.map.mapView.getProjection(); 57 59 LatLon center = proj.eastNorth2latlon(Main.map.mapView.getCenter()); 58 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();60 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 59 61 String imagery = ImageryOffsetTools.getImageryID(layer); 60 62 if (imagery == null) … … 74 76 if (Main.map == null || Main.map.mapView == null || !Main.map.isVisible()) 75 77 state = false; 76 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();78 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 77 79 if (ImageryOffsetTools.getImageryID(layer) == null) 78 80 state = false; … … 128 130 * @param imagery Imagery ID for the layer. 129 131 */ 130 DownloadOffsetsTask(LatLon center, ImageryLayer layer, String imagery) {132 DownloadOffsetsTask(LatLon center, AbstractTileSourceLayer layer, String imagery) { 131 133 super(null, tr("Loading imagery offsets...")); 132 134 try { … … 162 164 try { 163 165 offsets = new IODBReader(inp).parse(); 164 } catch (Exception e) { 166 } catch (IOException | SAXException e) { 165 167 throw new UploadException(tr("Error processing XML response: {0}", e.getMessage())); 166 168 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffset.java
r32528 r33309 3 3 4 4 import java.util.Map; 5 import org.openstreetmap.josm.Main; 5 6 6 7 import org.openstreetmap.josm.data.coor.CoordinateFormat; 8 import org.openstreetmap.josm.data.coor.EastNorth; 7 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 11 import org.openstreetmap.josm.data.projection.Projection; 8 12 9 13 /** -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r32528 r33309 10 10 import org.openstreetmap.josm.data.coor.EastNorth; 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 12 13 import org.openstreetmap.josm.data.projection.Projection; 13 14 import org.openstreetmap.josm.gui.MapView; 14 import org.openstreetmap.josm.gui.layer. ImageryLayer;15 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 15 16 16 17 /** … … 34 35 * @return the layer, or null if it hasn't been found. 35 36 */ 36 public static ImageryLayer getTopImageryLayer() {37 public static AbstractTileSourceLayer getTopImageryLayer() { 37 38 if (Main.map == null || Main.map.mapView == null) 38 39 return null; 39 List< ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);40 for ( ImageryLayer layer : layers) {40 List<AbstractTileSourceLayer> layers = Main.getLayerManager().getLayersOfType(AbstractTileSourceLayer.class); 41 for (AbstractTileSourceLayer layer : layers) { 41 42 String url = layer.getInfo().getUrl(); 42 43 if (layer.isVisible() && url != null && !url.contains("gps-")) { … … 64 65 * @see #applyLayerOffset 65 66 */ 66 public static LatLon getLayerOffset( ImageryLayer layer, LatLon center) {67 public static LatLon getLayerOffset(AbstractTileSourceLayer layer, LatLon center) { 67 68 Projection proj = Main.getProjection(); 68 69 EastNorth offsetCenter = Main.map.mapView.getCenter(); 69 EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy()); 70 EastNorth centerOffset = offsetCenter.add(-layer.getDisplaySettings().getDx(), 71 -layer.getDisplaySettings().getDy()); 70 72 LatLon offsetLL = proj.eastNorth2latlon(centerOffset); 71 73 return offsetLL; … … 77 79 * @see #getLayerOffset 78 80 */ 79 public static void applyLayerOffset( ImageryLayer layer, ImageryOffset offset) {80 double[] dxy= calculateOffset(offset);81 layer.setOffset (dxy[0], dxy[1]);81 public static void applyLayerOffset(AbstractTileSourceLayer layer, ImageryOffset offset) { 82 OffsetBookmark bookmark = calculateOffset(offset); 83 layer.getDisplaySettings().setOffsetBookmark(bookmark); 82 84 } 83 85 … … 87 89 * @see #applyLayerOffset 88 90 */ 89 public static double[]calculateOffset(ImageryOffset offset) {91 public static OffsetBookmark calculateOffset(ImageryOffset offset) { 90 92 Projection proj = Main.getProjection(); 91 93 EastNorth center = proj.latlon2eastNorth(offset.getPosition()); 92 94 EastNorth offsetPos = proj.latlon2eastNorth(offset.getImageryPos()); 93 return new double[] {center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY()}; 95 EastNorth offsetXY = new EastNorth(center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY()); 96 OffsetBookmark b = new OffsetBookmark(proj.toCode(), offset.getImagery(), "Autogenerated", 97 offsetXY.getX(), offsetXY.getY(), offset.getPosition().lon(), offset.getPosition().lat()); 98 return b; 94 99 } 95 100 … … 99 104 * @return imagery id. 100 105 */ 101 public static String getImageryID( ImageryLayer layer) {106 public static String getImageryID(AbstractTileSourceLayer layer) { 102 107 return layer == null ? null : 103 108 ImageryIdGenerator.getImageryID(layer.getInfo().getUrl(), layer.getInfo().getImageryType()); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetWatcher.java
r32528 r33309 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 16 17 import org.openstreetmap.josm.gui.MapView; 17 18 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 18 import org.openstreetmap.josm.gui.layer. ImageryLayer;19 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 19 20 import org.openstreetmap.josm.gui.layer.Layer; 20 21 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 24 25 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 25 26 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 27 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 26 28 import org.openstreetmap.josm.tools.Destroyable; 27 29 … … 113 115 return; 114 116 } 115 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();117 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 116 118 if (layer == null) { 117 119 setOffsetGood(true); 118 120 return; 119 121 } 122 TileSourceDisplaySettings displaySettings = layer.getDisplaySettings(); 120 123 LatLon center = ImageryOffsetTools.getMapCenter(); 121 124 Integer hash = layer.hashCode(); … … 124 127 // create entry for this layer and mark as needing alignment 125 128 data = new ImageryLayerData(); 126 data.lastDx = layer.getDx();127 data.lastDy = layer.getDy();129 data.lastDx = displaySettings.getDx(); 130 data.lastDy = displaySettings.getDy(); 128 131 boolean r = false; 129 132 if (Math.abs(data.lastDx) + Math.abs(data.lastDy) > THRESHOLD) { … … 135 138 } else { 136 139 // now, we have a returning layer. 137 if (Math.abs(data.lastDx - layer.getDx()) + Math.abs(data.lastDy -layer.getDy()) > THRESHOLD) {140 if (Math.abs(data.lastDx - displaySettings.getDx()) + Math.abs(data.lastDy - displaySettings.getDy()) > THRESHOLD) { 138 141 // offset has changed, record the current position 139 data.lastDx = layer.getDx();140 data.lastDy = layer.getDy();142 data.lastDx = displaySettings.getDx(); 143 data.lastDy = displaySettings.getDy(); 141 144 data.lastChecked = center; 142 145 storeLayerOffset(layer); … … 154 157 */ 155 158 public void markGood() { 156 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();159 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 157 160 if (layer != null) { 161 TileSourceDisplaySettings displaySettings = layer.getDisplaySettings(); 158 162 LatLon center = ImageryOffsetTools.getMapCenter(); 159 163 Integer hash = layer.hashCode(); … … 162 166 // create entry for this layer and mark as good 163 167 data = new ImageryLayerData(); 164 data.lastDx = layer.getDx();165 data.lastDy = layer.getDy();168 data.lastDx = displaySettings.getDx(); 169 data.lastDy = displaySettings.getDy(); 166 170 data.lastChecked = center; 167 171 layers.put(hash, data); 168 172 } else { 169 data.lastDx = layer.getDx();170 data.lastDy = layer.getDy();173 data.lastDx = displaySettings.getDx(); 174 data.lastDy = displaySettings.getDy(); 171 175 data.lastChecked = center; 172 176 } … … 199 203 public void layerAdded(LayerAddEvent e) { 200 204 Layer newLayer = e.getAddedLayer(); 201 if (newLayer instanceof ImageryLayer)202 loadLayerOffset(( ImageryLayer) newLayer);205 if (newLayer instanceof AbstractTileSourceLayer) 206 loadLayerOffset((AbstractTileSourceLayer) newLayer); 203 207 checkOffset(); 204 208 } … … 218 222 * projections: nobody uses them anyway. 219 223 */ 220 private void storeLayerOffset( ImageryLayer layer) {224 private void storeLayerOffset(AbstractTileSourceLayer layer) { 221 225 String id = ImageryOffsetTools.getImageryID(layer); 222 226 if (!Main.pref.getBoolean("iodb.remember.offsets", true) || id == null) … … 229 233 } 230 234 LatLon center = ImageryOffsetTools.getMapCenter(); 231 offsets.add(id + ":" + center.lat() + ":" + center.lon() + ":" + layer.getDx() + ":" + layer.getDy()); 235 offsets.add(id + ":" + center.lat() + ":" + center.lon() + ":" + 236 layer.getDisplaySettings().getDx() + ":" + layer.getDisplaySettings().getDy()); 232 237 Main.pref.putCollection("iodb.stored.offsets", offsets); 233 238 } … … 236 241 * Loads the current imagery layer offset from preferences. 237 242 */ 238 private void loadLayerOffset( ImageryLayer layer) {243 private void loadLayerOffset(AbstractTileSourceLayer layer) { 239 244 String id = ImageryOffsetTools.getImageryID(layer); 240 245 if (!Main.pref.getBoolean("iodb.remember.offsets", true) || id == null) … … 249 254 dparts[i] = Double.parseDouble(parts[i+1]); 250 255 } 251 } catch (Exception e) { 256 } catch (NumberFormatException e) { 252 257 continue; 253 258 } … … 255 260 if (lastPos.greatCircleDistance(ImageryOffsetTools.getMapCenter()) < Math.max(maxDistance, 3.0) * 1000) { 256 261 // apply offset 257 layer.setOffset(dparts[2], dparts[3]); 262 OffsetBookmark bookmark = new OffsetBookmark(Main.getProjection().toCode(), 263 layer.getName(), "Restored", dparts[2], dparts[3]); 264 layer.getDisplaySettings().setOffsetBookmark(bookmark); 258 265 return; 259 266 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r32910 r33309 40 40 import org.openstreetmap.josm.gui.MapView; 41 41 import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener; 42 import org.openstreetmap.josm.gui.layer. ImageryLayer;42 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 43 43 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 44 44 import org.openstreetmap.josm.tools.HttpClient; … … 270 270 public void applyOffset() { 271 271 if (selectedOffset instanceof ImageryOffset) { 272 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();272 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 273 273 ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset) selectedOffset); 274 274 ImageryOffsetWatcher.getInstance().markGood(); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r32910 r33309 28 28 import org.openstreetmap.josm.data.coor.LatLon; 29 29 import org.openstreetmap.josm.data.projection.Projection; 30 import org.openstreetmap.josm.gui.layer. ImageryLayer;30 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 31 31 import org.openstreetmap.josm.tools.ImageProvider; 32 32 … … 127 127 */ 128 128 private double[] getLengthAndDirection(ImageryOffset offset) { 129 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 130 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()}; 129 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 130 double[] dxy = layer == null ? new double[] {0.0, 0.0} : 131 new double[] {layer.getDisplaySettings().getDx(), layer.getDisplaySettings().getDy()}; 131 132 return getLengthAndDirection(offset, dxy[0], dxy[1]); 132 133 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r32528 r33309 20 20 import org.openstreetmap.josm.data.osm.Way; 21 21 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 22 import org.openstreetmap.josm.gui.layer. ImageryLayer;22 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 23 23 24 24 /** … … 52 52 return; 53 53 54 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();54 AbstractTileSourceLayer layer = ImageryOffsetTools.getTopImageryLayer(); 55 55 if (layer == null) 56 56 return; … … 91 91 if (calibration == null) { 92 92 // register imagery offset 93 if (Math.abs(layer.getDx()) < 1e-8 && Math.abs(layer.getDy()) < 1e-8) { 93 if (Math.abs(layer.getDisplaySettings().getDx()) < 1e-8 && Math.abs(layer.getDisplaySettings().getDy()) < 1e-8) { 94 94 if (JOptionPane.showConfirmDialog(Main.parent, 95 95 tr("The topmost imagery layer has no offset. Are you sure you want to upload this?"),
Note:
See TracChangeset
for help on using the changeset viewer.