Changeset 33309 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetWatcher.java
- Timestamp:
- 2017-05-13T14:21:55+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.