Changeset 13575 in osm for applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin
- Timestamp:
- 2009-02-07T21:47:41+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/JumpToAction.java
r13497 r13575 42 42 } 43 43 44 public JTextField url = new JTextField(); 45 public JTextField lat = new JTextField(); 46 public JTextField lon = new JTextField(); 44 private JTextField url = new JTextField(); 45 private JTextField lat = new JTextField(); 46 private JTextField lon = new JTextField(); 47 private JTextField zm = new JTextField(); 48 49 private double zoomFactor = 0; 47 50 public void showJumpToDialog() { 48 51 LatLon curPos=Main.proj.eastNorth2latlon(Main.map.mapView.getCenter()); 49 52 lat.setText(java.lang.Double.toString(curPos.lat())); 50 53 lon.setText(java.lang.Double.toString(curPos.lon())); 54 55 LatLon ll1 = Main.map.mapView.getLatLon(0,0); 56 LatLon ll2 = Main.map.mapView.getLatLon(100,0); 57 double dist = ll1.greatCircleDistance(ll2); 58 zoomFactor = Main.map.mapView.getScale()/dist; 59 60 zm.setText(java.lang.Long.toString(Math.round(dist*100)/100)); 51 61 updateUrl(true); 52 62 … … 75 85 lat.getDocument().addDocumentListener(x); 76 86 lon.getDocument().addDocumentListener(x); 87 zm.getDocument().addDocumentListener(x); 77 88 url.getDocument().addDocumentListener(new osmURLListener()); 78 89 … … 86 97 p.add(lon, GBC.eol().fill(GBC.HORIZONTAL)); 87 98 99 p.add(new JLabel(tr("Zoom (in metres)")), GBC.eol()); 100 p.add(zm, GBC.eol().fill(GBC.HORIZONTAL)); 101 88 102 p.add(new JLabel(tr("URL")), GBC.eol()); 89 103 p.add(url, GBC.eol().fill(GBC.HORIZONTAL)); … … 91 105 Object[] buttons = { tr("Jump there"), tr("Cancel") }; 92 106 LatLon ll = null; 107 double zoomLvl = 100; 93 108 while(ll == null) { 94 109 int option = JOptionPane.showOptionDialog( … … 104 119 if (option != JOptionPane.OK_OPTION) return; 105 120 try { 121 zoomLvl = Double.parseDouble(zm.getText()); 106 122 ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText())); 107 123 } catch (Exception ex) { 108 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse Latitude or Longitude. Please check."), tr("Unable to parse Lon/Lat"), JOptionPane.ERROR_MESSAGE);124 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse Latitude, Longitude or Zoom. Please check."), tr("Unable to parse Lon/Lat"), JOptionPane.ERROR_MESSAGE); 109 125 } 110 126 } 111 127 112 Main.map.mapView.zoomTo(Main.proj.latlon2eastNorth(ll), Main.map.mapView.getScale()); 113 114 128 Main.map.mapView.zoomTo(Main.proj.latlon2eastNorth(ll), zoomFactor * zoomLvl); 115 129 } 116 130 … … 119 133 Bounds b = OsmUrlToBounds.parse(url.getText()); 120 134 if (b != null) { 121 lat.setText(java.lang.Double.toString((b.min.lat() + b.max.lat())/2)); 122 lon.setText(java.lang.Double.toString((b.min.lon() + b.max.lon())/2)); 135 lat.setText(Double.toString((b.min.lat() + b.max.lat())/2)); 136 lon.setText(Double.toString((b.min.lon() + b.max.lon())/2)); 137 138 int zoomLvl = 16; 139 String[] args = url.getText().substring(url.getText().indexOf('?')+1).split("&"); 140 for (String arg : args) { 141 int eq = arg.indexOf('='); 142 if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue; 143 144 zoomLvl = Integer.parseInt(arg.substring(eq + 1)); 145 break; 146 } 147 148 // 10000000 = 10 000 * 1000 = World * (km -> m) 149 zm.setText(Double.toString(Math.round(10000000 * Math.pow(2, (-1) * zoomLvl)))); 123 150 } 124 151 } 125 152 126 153 private void updateUrl(boolean force) { 127 if(!lat.hasFocus() && !lon.hasFocus() && ! force) return;154 if(!lat.hasFocus() && !lon.hasFocus() && !zm.hasFocus() && !force) return; 128 155 try { 129 156 double dlat = Double.parseDouble(lat.getText()); 130 157 double dlon = Double.parseDouble(lon.getText()); 131 int zoom = Main.map.mapView.zoom();158 int zoomLvl = getZoom(zoomFactor * Double.parseDouble(zm.getText())); 132 159 133 int decimals = (int) Math.pow(10, (zoom / 3));160 int decimals = (int) Math.pow(10, (zoomLvl / 3)); 134 161 dlat = Math.round(dlat * decimals); 135 162 dlat /= decimals; 136 163 dlon = Math.round(dlon * decimals); 137 164 dlon /= decimals; 138 url.setText("http://www.openstreetmap.org/?lat="+dlat+"&lon="+dlon+"&zoom="+zoom );165 url.setText("http://www.openstreetmap.org/?lat="+dlat+"&lon="+dlon+"&zoom="+zoomLvl); 139 166 } catch (NumberFormatException x) {} 140 167 } … … 142 169 public void actionPerformed(ActionEvent e) { 143 170 showJumpToDialog(); 171 } 172 173 /** 174 * Converts a given scale into OSM-Style zoom factors 175 * @param double scale 176 */ 177 public int getZoom(double scale) { 178 double sizex = scale * Main.map.mapView.getWidth(); 179 double sizey = scale * Main.map.mapView.getHeight(); 180 for (int zoom = 0; zoom <= 32; zoom++, sizex *= 2, sizey *= 2) 181 if (sizex > Main.map.mapView.world.east() || sizey > Main.map.mapView.world.north()) 182 return zoom; 183 return 32; 144 184 } 145 185
Note:
See TracChangeset
for help on using the changeset viewer.