Changeset 28008 in osm for applications/editors/josm/plugins/imagery_offset_db/src
- Timestamp:
- 2012-03-06T21:32:44+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationObject.java
r27986 r28008 1 1 package iodb; 2 2 3 import org.openstreetmap.josm.data.osm.OsmPrimitive;4 import org.openstreetmap.josm.data.osm. User;3 import java.util.Map; 4 import org.openstreetmap.josm.data.osm.*; 5 5 6 6 /** … … 18 18 19 19 public CalibrationObject(OsmPrimitive object) { 20 this(object, -1);20 this(object, getLastUserId(object)); 21 21 } 22 22 … … 28 28 return object; 29 29 } 30 31 private static long getLastUserId( OsmPrimitive object ) { 32 return object.getUser() == null ? -1 : object.getUser().getId(); // todo? 33 } 34 35 @Override 36 public void putServerParams( Map<String, String> map ) { 37 super.putServerParams(map); 38 map.put("object", object instanceof Node ? "node" : "way"); 39 map.put("id", String.valueOf(object.getId())); 40 map.put("lastuser", String.valueOf(lastUserId)); 41 } 42 30 43 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r27986 r28008 37 37 private List<ImageryOffsetBase> offsets; 38 38 39 private HashMap<String, String> imageryAliases;40 41 39 public GetImageryOffsetAction() { 42 40 super(tr("Get Imagery Offset..."), "getoffset", tr("Download offsets for current imagery from a server"), … … 48 46 Projection proj = Main.map.mapView.getProjection(); 49 47 LatLon center = proj.eastNorth2latlon(Main.map.mapView.getCenter()); 50 // todo: download a list of offsets for current bbox * N 51 List<ImageryOffsetBase> offsets = download(center); // todo: async 52 DownloadOffsets download = new DownloadOffsets(); 48 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 49 String imagery = ImageryOffsetTools.getImageryID(layer); 50 if( imagery == null ) 51 return; 52 53 List<ImageryOffsetBase> offsets = download(center, imagery); // todo: async 54 /*DownloadOffsets download = new DownloadOffsets(); 53 55 Future<?> future = Main.worker.submit(download); 54 56 try { … … 57 59 ex.printStackTrace(); 58 60 return; 59 } 61 }*/ 60 62 61 63 // todo: show a dialog for selecting one of the offsets (without "update" flag) … … 63 65 if( offset != null ) { 64 66 // todo: use the chosen offset 67 if( offset instanceof ImageryOffset ) { 68 ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset)offset); 69 } else if( offset instanceof CalibrationObject ) { 70 // todo: select object 71 } 65 72 } 66 73 } 67 74 68 private List<ImageryOffsetBase> download( LatLon center ) {69 String base = Main.pref.get("iodb.server.url", "http:// textual.ru/iodb.php");70 String query = " ?action=get&lat=" + center.getX() + "&lon=" + center.getY();75 private List<ImageryOffsetBase> download( LatLon center, String imagery ) { 76 String base = Main.pref.get("iodb.server.url", "http://offsets.textual.ru/"); 77 String query = "get?lat=" + center.getX() + "&lon=" + center.getY(); 71 78 List<ImageryOffsetBase> result = null; 72 79 try { 73 query = query + "&imagery=" + URLEncoder.encode( getImageryID(), "utf-8");80 query = query + "&imagery=" + URLEncoder.encode(imagery, "utf-8"); 74 81 URL url = new URL(base + query); 82 System.out.println("url=" + url); 75 83 HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 76 84 connection.connect(); … … 79 87 if( inp != null ) { 80 88 result = new IODBReader(inp).parse(); 89 System.out.println("result.size() = " + result.size()); 81 90 } 82 91 connection.disconnect(); … … 95 104 result = new ArrayList<ImageryOffsetBase>(); 96 105 return result; 97 }98 99 private String getImageryID() {100 List<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class);101 String url = null;102 for( ImageryLayer layer : layers ) {103 if( layer.isVisible() ) {104 url = layer.getInfo().getUrl();105 break;106 }107 }108 if( url == null )109 return null;110 111 if( imageryAliases == null )112 loadImageryAliases();113 for( String substr : imageryAliases.keySet() )114 if( url.contains(substr) )115 return imageryAliases.get(substr);116 117 return url; // todo: strip parametric parts, etc118 }119 120 private void loadImageryAliases() {121 if( imageryAliases == null )122 imageryAliases = new HashMap<String, String>();123 else124 imageryAliases.clear();125 126 // { substring, alias }127 imageryAliases.put("bing", "bing");128 // todo: load from a resource?129 }130 131 // Following three methods were snatched from TMSLayer132 private double latToTileY(double lat, int zoom) {133 double l = lat / 180 * Math.PI;134 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));135 return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI;136 }137 138 private double lonToTileX(double lon, int zoom) {139 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;140 }141 142 private int getCurrentZoom() {143 if (Main.map == null || Main.map.mapView == null) {144 return 1;145 }146 MapView mv = Main.map.mapView;147 LatLon topLeft = mv.getLatLon(0, 0);148 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());149 double x1 = lonToTileX(topLeft.lon(), 1);150 double y1 = latToTileY(topLeft.lat(), 1);151 double x2 = lonToTileX(botRight.lon(), 1);152 double y2 = latToTileY(botRight.lat(), 1);153 154 int screenPixels = mv.getWidth() * mv.getHeight();155 double tilePixels = Math.abs((y2 - y1) * (x2 - x1) * 256 * 256);156 if (screenPixels == 0 || tilePixels == 0) {157 return 1;158 }159 double factor = screenPixels / tilePixels;160 double result = Math.log(factor) / Math.log(2) / 2 + 1;161 int intResult = (int) Math.floor(result);162 return intResult;163 106 } 164 107 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffset.java
r27986 r28008 1 1 package iodb; 2 2 3 import java.util.Map; 4 import org.openstreetmap.josm.data.coor.CoordinateFormat; 3 5 import org.openstreetmap.josm.data.coor.LatLon; 4 6 … … 19 21 this.maxZoom = 30; 20 22 } 21 23 22 24 public void setMaxZoom(int maxZoom) { 23 25 this.maxZoom = maxZoom; … … 43 45 return minZoom; 44 46 } 47 48 @Override 49 public void putServerParams( Map<String, String> map ) { 50 super.putServerParams(map); 51 map.put("imagery", imagery); 52 map.put("imlat", imageryPos.latToString(CoordinateFormat.DECIMAL_DEGREES)); 53 map.put("imlon", imageryPos.lonToString(CoordinateFormat.DECIMAL_DEGREES)); 54 if( minZoom > 0 ) 55 map.put("minzoom", String.valueOf(minZoom)); 56 if( maxZoom < 30 ) 57 map.put("maxzoom", String.valueOf(maxZoom)); 58 } 45 59 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetBase.java
r27986 r28008 2 2 3 3 import java.util.Date; 4 import java.util.Map; 5 import org.openstreetmap.josm.data.coor.CoordinateFormat; 4 6 import org.openstreetmap.josm.data.coor.LatLon; 5 7 … … 51 53 return position; 52 54 } 55 56 public void putServerParams( Map<String, String> map ) { 57 map.put("lat", position.latToString(CoordinateFormat.DECIMAL_DEGREES)); 58 map.put("lon", position.lonToString(CoordinateFormat.DECIMAL_DEGREES)); 59 map.put("author", author); 60 map.put("description", description); 61 } 53 62 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r27986 r28008 14 14 * @author zverik 15 15 */ 16 public class OffsetDialog extends JDialog {16 public class OffsetDialog extends JDialog implements ActionListener { 17 17 private List<ImageryOffsetBase> offsets; 18 private intselectedOffset;18 private ImageryOffsetBase selectedOffset; 19 19 20 20 public OffsetDialog( List<ImageryOffsetBase> offsets ) { … … 27 27 JPanel buttonPanel = new JPanel(new GridLayout(offsets.size() + 1, 1)); 28 28 for( ImageryOffsetBase offset : offsets ) { 29 buttonPanel.add(new OffsetDialogButton(offset)); 29 OffsetDialogButton button = new OffsetDialogButton(offset); 30 button.addActionListener(this); 31 buttonPanel.add(button); 30 32 } 31 33 JButton cancelButton = new JButton("Cancel"); 32 cancelButton.addActionListener(new ActionListener() { 33 public void actionPerformed(ActionEvent e) { 34 selectedOffset = -1; 35 OffsetDialog.this.setVisible(false); 36 } 37 }); 34 cancelButton.addActionListener(this); 38 35 buttonPanel.add(cancelButton); // todo: proper button 39 36 setContentPane(buttonPanel); … … 43 40 44 41 public ImageryOffsetBase showDialog() { 45 selectedOffset = -1;42 selectedOffset = null; 46 43 prepareDialog(); 47 44 setVisible(true); 48 return selectedOffset < 0 ? null : offsets.get(selectedOffset); 45 return selectedOffset; 46 } 47 48 public void actionPerformed( ActionEvent e ) { 49 if( e.getSource() instanceof OffsetDialogButton ) { 50 selectedOffset = ((OffsetDialogButton)e.getSource()).getOffset(); 51 } else 52 selectedOffset = null; 53 setVisible(false); 49 54 } 50 55 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r27986 r28008 9 9 */ 10 10 public class OffsetDialogButton extends JButton { 11 12 private ImageryOffsetBase offset; 11 13 12 14 public OffsetDialogButton( ImageryOffsetBase offset ) { 13 15 super(offset.getDescription() + " (" + offset.getPosition().lat() + ", " + offset.getPosition().lon() + ")"); 16 this.offset = offset; 17 } 18 19 public ImageryOffsetBase getOffset() { 20 return offset; 14 21 } 15 22 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r27986 r28008 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.util.HashMap; 5 import java.util.Map; 4 6 import org.openstreetmap.josm.Main; 5 7 import org.openstreetmap.josm.actions.JosmAction; … … 20 22 21 23 public void actionPerformed(ActionEvent e) { 24 // todo: check that there is an imagery 25 // and that it is moved 22 26 Projection proj = Main.map.mapView.getProjection(); 23 27 LatLon center = proj.eastNorth2latlon(Main.map.mapView.getCenter()); … … 27 31 // todo: upload object info to server 28 32 } 33 34 private static void upload( ImageryOffsetBase offset ) { 35 String base = Main.pref.get("iodb.server.url", "http://offsets.textual.ru/"); 36 Map<String, String> params = new HashMap<String, String>(); 37 offset.putServerParams(params); 38 // todo 39 } 29 40 }
Note:
See TracChangeset
for help on using the changeset viewer.