Ticket #7508: possible_fix_7508.2.patch

File possible_fix_7508.2.patch, 3.0 KB (added by xeen, 14 years ago)

The actual reason for this is the following: GPX Layers do not remember their download bounds, because they are generally not required. When there is no OSM layer and no GPX data to derive the bounds from, MapView zooms in in (0,0). If a map view is visible, the download dialog takes the visible bounds instead of the one it remembered. Thus it appears as if the download dialog remebered (0,0). Closing the empty GPX layer before opening the download dialog will have it display the correct coordinates. I can think of two solutions: if the GPX layer is the first layer, popup a warning message and don’t create a new layer. The other is implemented in the patch: if there is no GPX data and this is the first layer, zoom to the download bounds instead. I’m not very happy with either approach, so I’ll only attach the patch here but won’t commit it for now.

  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

     
    106106            GpxLayer layer = new GpxLayer(rawData, name);
    107107            Layer x = findMergeLayer();
    108108            if (newLayer || x == null) {
     109                final boolean isDisplayingMapView = Main.isDisplayingMapView();
    109110                Main.main.addLayer(layer);
     111                // if the GPX layer is the only one and no data is available, prevent
     112                // the MapView from zooming in on (0,0), which makes starting another
     113                // download unnecessarily difficult. See #7508.
     114                if(!isDisplayingMapView && rawData.isEmpty() && reader instanceof BoundingBoxDownloader) {
     115                    Bounds b = ((BoundingBoxDownloader) reader).getBounds();
     116                    Main.map.mapView.zoomTo(b);
     117                }
    110118            } else {
    111119                x.mergeFrom(layer);
    112120                Main.map.repaint();
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

     
    311311        EastNorth e1 = getProjection().latlon2eastNorth(l1);
    312312        EastNorth e2 = getProjection().latlon2eastNorth(l2);
    313313        double d = e2.north() - e1.north();
    314         if(d < height*newScale)
    315         {
    316             double newScaleH = d/height;
     314        if(d < height*newScale && height != 0 && width != 0) {
    317315            e1 = getProjection().latlon2eastNorth(new LatLon(lat, b.getMin().lon()));
    318316            e2 = getProjection().latlon2eastNorth(new LatLon(lat, b.getMax().lon()));
    319317            d = e2.east() - e1.east();
    320318            if(d < width*newScale) {
    321                 newScale = Math.max(newScaleH, d/width);
     319                newScale = Math.max(d/height, d/width);
    322320            }
    323         }
    324         else
    325         {
     321        } else if (height != 0) {
    326322            d = d/(l1.greatCircleDistance(l2)*height*10);
    327323            if(newScale < d) {
    328324                newScale = d;
  • src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

     
    3131        this.crosses180th = downloadArea.crosses180thMeridian();
    3232    }
    3333
     34    public Bounds getBounds() {
     35        return new Bounds(lat1, lon1, lat2, lon2);
     36    }
     37
    3438    private GpxData downloadRawGps(String url, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException {
    3539        boolean done = false;
    3640        GpxData result = null;