Ignore:
Timestamp:
2018-04-24T21:32:50+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16219 - smarter selection of WMS projection

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r13387 r13674  
    12081208
    12091209        protected void sanitize() {
    1210             if (minX < tileSource.getTileXMin(zoom)) {
    1211                 minX = tileSource.getTileXMin(zoom);
    1212             }
    1213             if (minY < tileSource.getTileYMin(zoom)) {
    1214                 minY = tileSource.getTileYMin(zoom);
    1215             }
    1216             if (maxX > tileSource.getTileXMax(zoom)) {
    1217                 maxX = tileSource.getTileXMax(zoom);
    1218             }
    1219             if (maxY > tileSource.getTileYMax(zoom)) {
    1220                 maxY = tileSource.getTileYMax(zoom);
    1221             }
     1210            minX = Utils.clamp(minX, tileSource.getTileXMin(zoom), tileSource.getTileXMax(zoom));
     1211            maxX = Utils.clamp(maxX, tileSource.getTileXMin(zoom), tileSource.getTileXMax(zoom));
     1212            minY = Utils.clamp(minY, tileSource.getTileYMin(zoom), tileSource.getTileYMax(zoom));
     1213            maxY = Utils.clamp(maxY, tileSource.getTileYMin(zoom), tileSource.getTileYMax(zoom));
    12221214        }
    12231215
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r13206 r13674  
    1818import org.openstreetmap.josm.Main;
    1919import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
     20import org.openstreetmap.josm.data.coor.LatLon;
    2021import org.openstreetmap.josm.data.imagery.AbstractWMSTileSource;
    2122import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    2829import org.openstreetmap.josm.data.projection.Projection;
    2930import org.openstreetmap.josm.data.projection.Projections;
     31import org.openstreetmap.josm.gui.MainApplication;
    3032import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
    3133import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    130132            return requested;
    131133        } else {
     134            LatLon center = MainApplication.isDisplayingMapView() ?
     135                    requested.eastNorth2latlon(MainApplication.getMap().mapView.getCenter()) : null;
     136            Projection firstNonNullproj = null;
     137            Projection firstProjInBounds = null;
    132138            for (String code : serverProjections) {
    133139                Projection proj = Projections.getProjectionByCode(code);
    134140                if (proj != null) {
    135                     Logging.info(tr("Reprojecting layer {0} from {1} to {2}. For best image quality and performance,"
    136                             + " switch to one of the supported projections: {3}",
    137                             getName(), proj.toCode(), Main.getProjection().toCode(), Utils.join(", ", getNativeProjections())));
    138                     return proj;
     141                    if (firstNonNullproj == null) {
     142                        firstNonNullproj = proj;
     143                    }
     144                    if (center != null && proj.getWorldBoundsLatLon().contains(center)) {
     145                        firstProjInBounds = proj;
     146                        break;
     147                    }
    139148                }
     149            }
     150            if (firstProjInBounds != null) {
     151                return selectProjection(firstProjInBounds);
     152            } else if (firstNonNullproj != null) {
     153                return selectProjection(firstNonNullproj);
    140154            }
    141155            Logging.warn(tr("Unable to find supported projection for layer {0}. Using {1}.", getName(), requested.toCode()));
    142156            return requested;
    143157        }
     158    }
     159
     160    private Projection selectProjection(Projection proj) {
     161        Logging.info(tr("Reprojecting layer {0} from {1} to {2}. For best image quality and performance,"
     162                + " switch to one of the supported projections: {3}",
     163                getName(), proj.toCode(), Main.getProjection().toCode(), Utils.join(", ", getNativeProjections())));
     164        return proj;
    144165    }
    145166
Note: See TracChangeset for help on using the changeset viewer.