Changeset 5670 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-01-25T22:34:19+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r5538 r5670 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 … … 65 66 import org.openstreetmap.josm.gui.MapFrame; 66 67 import org.openstreetmap.josm.gui.MapView; 68 import org.openstreetmap.josm.gui.NavigatableComponent.ViewportData; 67 69 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 68 70 import org.openstreetmap.josm.gui.io.SaveLayersDialog; … … 406 408 */ 407 409 public final synchronized void addLayer(final Layer layer) { 408 if (map == null) { 409 final MapFrame mapFrame = new MapFrame(contentPanePrivate); 410 setMapFrame(mapFrame); 411 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction(), layer); 412 mapFrame.setVisible(true); 413 mapFrame.initializeDialogsPane(); 414 // bootstrapping problem: make sure the layer list dialog is going to 415 // listen to change events of the very first layer 416 // 417 layer.addPropertyChangeListener(LayerListDialog.getInstance().getModel()); 410 boolean noMap = map == null; 411 if (noMap) { 412 createMapFrame(layer, null); 418 413 } 419 414 layer.hookUpMapView(); 420 415 map.mapView.addLayer(layer); 416 if (noMap) { 417 Main.map.setVisible(true); 418 } 419 } 420 421 public synchronized void createMapFrame(Layer firstLayer, ViewportData viewportData) { 422 MapFrame mapFrame = new MapFrame(contentPanePrivate, viewportData); 423 setMapFrame(mapFrame); 424 if (firstLayer != null) { 425 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction(), firstLayer); 426 } 427 mapFrame.initializeDialogsPane(); 428 // bootstrapping problem: make sure the layer list dialog is going to 429 // listen to change events of the very first layer 430 // 431 firstLayer.addPropertyChangeListener(LayerListDialog.getInstance().getModel()); 421 432 } 422 433 -
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r4982 r5670 19 19 20 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.actions.JosmAction;22 21 import org.openstreetmap.josm.data.Bounds; 23 22 import org.openstreetmap.josm.data.coor.LatLon; -
trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
r5573 r5670 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.coor.EastNorth; 18 19 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 20 import org.openstreetmap.josm.gui.NavigatableComponent; 21 import org.openstreetmap.josm.gui.NavigatableComponent.ViewportData; 19 22 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 20 23 import org.openstreetmap.josm.gui.layer.Layer; … … 47 50 private List<Layer> layers; 48 51 private List<Runnable> postLoadTasks; 52 private ViewportData viewport; 49 53 50 54 public Loader(File file, boolean zip) { … … 66 70 public void run() { 67 71 if (canceled) return; 68 for (Layer l : layers) { 69 if (canceled) return; 70 Main.main.addLayer(l); 72 if (!layers.isEmpty()) { 73 Layer firstLayer = layers.iterator().next(); 74 boolean noMap = Main.map == null; 75 if (noMap) { 76 Main.main.createMapFrame(firstLayer, viewport); 77 } 78 for (Layer l : layers) { 79 if (canceled) return; 80 Main.main.addLayer(l); 81 } 82 if (noMap) { 83 Main.map.setVisible(true); 84 } 71 85 } 72 86 for (Runnable task : postLoadTasks) { … … 89 103 layers = reader.getLayers(); 90 104 postLoadTasks = reader.getPostLoadTasks(); 105 viewport = reader.getViewport(); 91 106 } catch (IllegalDataException e) { 92 107 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r4065 r5670 17 17 18 18 /** 19 * Construct bounds out of two points 19 * Construct bounds out of two points. 20 20 */ 21 21 public ProjectionBounds(EastNorth min, EastNorth max) { -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r5463 r5670 54 54 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 55 55 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 56 import org.openstreetmap.josm.gui.NavigatableComponent.ViewportData; 56 57 import org.openstreetmap.josm.gui.dialogs.ChangesetDialog; 57 58 import org.openstreetmap.josm.gui.dialogs.CommandStackDialog; … … 144 145 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>(); 145 146 146 public MapFrame(JPanel contentPane) { 147 /** 148 * Constructs a new {@code MapFrame}. 149 * @param contentPane The content pane used to register shortcuts in its 150 * {@link InputMap} and {@link ActionMap} 151 * @param viewportData the initial viewport of the map. Can be null, then 152 * the viewport is derived from the layer data. 153 */ 154 public MapFrame(JPanel contentPane, ViewportData viewportData) { 147 155 setSize(400,400); 148 156 setLayout(new BorderLayout()); 149 157 150 158 151 mapView = new MapView(contentPane );159 mapView = new MapView(contentPane, viewportData); 152 160 153 161 new FileDrop(mapView); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r5519 r5670 219 219 /** 220 220 * Constructs a new {@code MapView}. 221 * @param contentPane The content pane used to register shortcuts in its {@link InputMap} and {@link ActionMap} 222 */ 223 public MapView(final JPanel contentPane) { 221 * @param contentPane The content pane used to register shortcuts in its 222 * {@link InputMap} and {@link ActionMap} 223 * @param viewportData the initial viewport of the map. Can be null, then 224 * the viewport is derived from the layer data. 225 */ 226 public MapView(final JPanel contentPane, final ViewportData viewportData) { 224 227 Main.pref.addPreferenceChangeListener(this); 225 228 … … 237 240 238 241 mapMover = new MapMover(MapView.this, contentPane); 239 OsmDataLayer layer = getEditLayer(); 240 if (layer != null) { 241 if (!zoomToDataSetBoundingBox(layer.data)) { 242 // no bounding box defined 243 AutoScaleAction.autoScale("data"); 242 if (viewportData != null) { 243 zoomTo(viewportData.getCenter(), viewportData.getScale()); 244 } else { 245 OsmDataLayer layer = getEditLayer(); 246 if (layer != null) { 247 if (!zoomToDataSetBoundingBox(layer.data)) { 248 // no bounding box defined 249 AutoScaleAction.autoScale("data"); 250 } 251 } else { 252 AutoScaleAction.autoScale("layer"); 244 253 } 245 } else {246 AutoScaleAction.autoScale("layer");247 254 } 248 255 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r5565 r5670 65 65 } 66 66 67 /** 68 * Simple data class that keeps map center and scale in one object. 69 */ 70 public static class ViewportData { 71 private EastNorth center; 72 private Double scale; 73 74 public ViewportData(EastNorth center, Double scale) { 75 this.center = center; 76 this.scale = scale; 77 } 78 79 /** 80 * Return the projected coordinates of the map center 81 * @return the center 82 */ 83 public EastNorth getCenter() { 84 return center; 85 } 86 87 /** 88 * Return the scale factor in east-/north-units per pixel. 89 * @return the scale 90 */ 91 public Double getScale() { 92 return scale; 93 } 94 } 95 67 96 public static final IntegerProperty PROP_SNAP_DISTANCE = new IntegerProperty("mappaint.node.snap-distance", 10); 68 97 … … 172 201 public EastNorth getCenter() { 173 202 return center; 203 } 204 205 public double getScale() { 206 return scale; 174 207 } 175 208 -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r5572 r5670 33 33 34 34 import org.openstreetmap.josm.Main; 35 import org.openstreetmap.josm.data.coor.EastNorth; 36 import org.openstreetmap.josm.data.coor.LatLon; 37 import org.openstreetmap.josm.data.projection.Projection; 38 import org.openstreetmap.josm.data.projection.Projections; 35 39 import org.openstreetmap.josm.gui.ExtendedDialog; 40 import org.openstreetmap.josm.gui.NavigatableComponent.ViewportData; 36 41 import org.openstreetmap.josm.gui.layer.Layer; 37 42 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 84 89 private List<Layer> layers = new ArrayList<Layer>(); 85 90 private List<Runnable> postLoadTasks = new ArrayList<Runnable>(); 91 private ViewportData viewport; 86 92 87 93 /** … … 97 103 public List<Runnable> getPostLoadTasks() { 98 104 return postLoadTasks; 105 } 106 107 /** 108 * Return the viewport (map position and scale). 109 * @return The viewport. Can be null when no viewport info is found in the file. 110 */ 111 public ViewportData getViewport() { 112 return viewport; 99 113 } 100 114 … … 277 291 } 278 292 279 NodeList layersNL = root.getElementsByTagName("layers"); 280 if (layersNL.getLength() == 0) return; 281 282 Element layersEl = (Element) layersNL.item(0); 293 Element viewportEl = getElementByTagName(root, "viewport"); 294 if (viewportEl != null) { 295 EastNorth center = null; 296 Element centerEl = getElementByTagName(viewportEl, "center"); 297 if (centerEl != null && centerEl.hasAttribute("lat") && centerEl.hasAttribute("lon")) { 298 try { 299 LatLon centerLL = new LatLon(Double.parseDouble(centerEl.getAttribute("lat")), Double.parseDouble(centerEl.getAttribute("lon"))); 300 center = Projections.project(centerLL); 301 } catch (NumberFormatException ex) {} 302 } 303 if (center != null) { 304 Element scaleEl = getElementByTagName(viewportEl, "scale"); 305 if (scaleEl != null && scaleEl.hasAttribute("meter-per-pixel")) { 306 try { 307 Double meterPerPixel = Double.parseDouble(scaleEl.getAttribute("meter-per-pixel")); 308 Projection proj = Main.getProjection(); 309 // Get a "typical" distance in east/north units that 310 // corresponds to a couple of pixels. Shouldn't be too 311 // large, to keep it within projection bounds and 312 // not too small to avoid rounding errors. 313 double dist = 0.01 * proj.getDefaultZoomInPPD(); 314 LatLon ll1 = proj.eastNorth2latlon(new EastNorth(center.east() - dist, center.north())); 315 LatLon ll2 = proj.eastNorth2latlon(new EastNorth(center.east() + dist, center.north())); 316 double meterPerEasting = ll1.greatCircleDistance(ll2) / dist / 2; 317 double scale = meterPerPixel / meterPerEasting; // unit: easting per pixel 318 viewport = new ViewportData(center, scale); 319 } catch (NumberFormatException ex) {} 320 } 321 } 322 } 323 324 Element layersEl = getElementByTagName(root, "layers"); 325 if (layersEl == null) return; 283 326 284 327 MultiMap<Integer, Integer> deps = new MultiMap<Integer, Integer>(); … … 532 575 } 533 576 577 private static Element getElementByTagName(Element root, String name) { 578 NodeList els = root.getElementsByTagName(name); 579 if (els.getLength() == 0) return null; 580 return (Element) els.item(0); 581 } 582 534 583 } -
trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
r5551 r5670 28 28 import javax.xml.transform.stream.StreamResult; 29 29 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.data.coor.EastNorth; 32 import org.openstreetmap.josm.data.coor.LatLon; 33 import org.openstreetmap.josm.data.projection.Projections; 30 34 import org.openstreetmap.josm.gui.layer.GpxLayer; 31 35 import org.openstreetmap.josm.gui.layer.Layer; … … 161 165 root.setAttribute("version", "0.1"); 162 166 doc.appendChild(root); 167 168 Element viewportEl = doc.createElement("viewport"); 169 root.appendChild(viewportEl); 170 Element centerEl = doc.createElement("center"); 171 viewportEl.appendChild(centerEl); 172 EastNorth center = Main.map.mapView.getCenter(); 173 LatLon centerLL = Projections.inverseProject(center); 174 centerEl.setAttribute("lat", Double.toString(centerLL.lat())); 175 centerEl.setAttribute("lon", Double.toString(centerLL.lon())); 176 Element scale = doc.createElement("scale"); 177 viewportEl.appendChild(scale); 178 double dist100px = Main.map.mapView.getDist100Pixel(); 179 scale.setAttribute("meter-per-pixel", Double.toString(dist100px / 100)); 163 180 164 181 Element layersEl = doc.createElement("layers");
Note:
See TracChangeset
for help on using the changeset viewer.