Changeset 8542 in josm


Ignore:
Timestamp:
2015-06-30T13:57:53+02:00 (8 years ago)
Author:
wiktorn
Message:

Add warnings about supported projections for WMS layers

Location:
trunk
Files:
4 edited

Legend:

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

    r8540 r8542  
    139139    public AbstractTileSourceLayer(ImageryInfo info) {
    140140        super(info);
    141 
    142         if (!isProjectionSupported(Main.getProjection())) {
    143             JOptionPane.showMessageDialog(Main.parent,
    144                     tr("This layer do not support the projection {0}.\n{1}\n"
    145                             + "Change the projection or remove the layer.",
    146                             Main.getProjection().toCode(), nameSupportedProjections()),
    147                             tr("Warning"),
    148                             JOptionPane.WARNING_MESSAGE);
    149         }
    150141        setBackgroundLayer(true);
    151142        this.setVisible(true);
    152 
    153         initTileSource(getTileSource(info));
    154143        MapView.addZoomChangeListener(this);
    155144    }
     
    462451    @Override
    463452    public void hookUpMapView() {
     453        initTileSource(getTileSource(info));
     454        projectionChanged(null, Main.getProjection()); // check if projection is supported
     455
    464456        // keep them final here, so we avoid namespace clutter in the class
    465457        final JPopupMenu tileOptionMenu = new JPopupMenu();
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r8510 r8542  
    447447        if (!isProjectionSupported(newValue)) {
    448448            JOptionPane.showMessageDialog(Main.parent,
    449                     tr("The layer {0} does not support the new projection {1}.\n{2}\n"
     449                    tr("The layer {0} does not support the new projection {1}.\n"
     450                            + "Supported projections are: {2}\n"
    450451                            + "Change the projection again or remove the layer.",
    451452                            getName(), newValue.toCode(), nameSupportedProjections()),
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r8530 r8542  
    1717import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
    1818import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    19 import org.openstreetmap.josm.Main;
    2019import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;
    2120import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    2827import org.openstreetmap.josm.data.preferences.IntegerProperty;
    2928import org.openstreetmap.josm.data.projection.Projection;
    30 import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    31 import org.openstreetmap.josm.gui.MapView;
    32 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    3329
    3430/**
     
    4238    /** should WMS layer autozoom in default mode */
    4339    public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty("imagery.wms.default_autozoom", true);
     40    private List<String> supportedProjections;
    4441
    4542    /**
     
    4744     * @param info ImageryInfo description of the layer
    4845     */
     46
     47
    4948    public WMSLayer(ImageryInfo info) {
    5049        super(info);
    51     }
    52 
    53     @Override
    54     public void hookUpMapView() {
    55         super.hookUpMapView();
    56         final ProjectionChangeListener listener = new ProjectionChangeListener() {
    57             @Override
    58             public void projectionChanged(Projection oldValue, Projection newValue) {
    59                 if (!oldValue.equals(newValue) && tileSource instanceof TemplatedWMSTileSource) {
    60                     ((TemplatedWMSTileSource) tileSource).initProjection(newValue);
    61                 }
    62 
    63             }
    64         };
    65         Main.addProjectionChangeListener(listener);
    66 
    67         MapView.addLayerChangeListener(new LayerChangeListener() {
    68             @Override
    69             public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    70                 // empty
    71             }
    72 
    73             @Override
    74             public void layerAdded(Layer newLayer) {
    75                 // empty
    76             }
    77 
    78             @Override
    79             public void layerRemoved(Layer oldLayer) {
    80                 if (oldLayer == WMSLayer.this) {
    81                     Main.removeProjectionChangeListener(listener);
    82                 }
    83             }
    84         });
     50        this.supportedProjections = info.getServerProjections();
    8551    }
    8652
     
    155121        return null;
    156122    }
     123
     124    @Override
     125    public boolean isProjectionSupported(Projection proj) {
     126        return supportedProjections == null || supportedProjections.isEmpty() || supportedProjections.contains(proj.toCode());
     127    }
     128
     129    @Override
     130    public String nameSupportedProjections() {
     131        StringBuffer ret = new StringBuffer();
     132        for (String e: supportedProjections) {
     133            ret.append(e).append(", ");
     134        }
     135        String appendix = "";
     136        if (supportedProjections.contains("EPSG:4326")) {
     137            appendix = ". " + tr("JOSM will use EPSG:4326 to query the server, but results may vary "
     138                    + "depending on the WMS server");
     139        }
     140        return ret.substring(0, ret.length()-2);
     141    }
     142
     143    @Override
     144    public void projectionChanged(Projection oldValue, Projection newValue) {
     145        super.projectionChanged(oldValue, newValue);
     146
     147        if (!newValue.equals(oldValue) && tileSource instanceof TemplatedWMSTileSource) {
     148            ((TemplatedWMSTileSource) tileSource).initProjection(newValue);
     149        }
     150
     151    }
     152
    157153}
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java

    r8530 r8542  
    4848            }
    4949        }
     50        verifyTileSquarness(source, 2270, 1323, 12);
    5051        verifyLocation(source, new LatLon(53.5937132, 19.5652017));
    5152        verifyLocation(source, new LatLon(53.501565692302854, 18.54455233898721));
     
    6263        verifyTileSquarness(source, 2, 2, 2);
    6364        verifyTileSquarness(source, 150, 20, 18);
     65        verifyTileSquarness(source, 2270, 1323, 12);
    6466    }
    6567
     
    7476        verifyTileSquarness(source, 2, 2, 2);
    7577        verifyTileSquarness(source, 150, 20, 18);
    76 
     78        verifyTileSquarness(source, 2270, 1323, 12);
    7779    }
    7880
     
    112114    private void verifyTileSquarness(TemplatedWMSTileSource source, int x, int y, int z) {
    113115        Projection proj = Main.getProjection();
    114         EastNorth min = proj.latlon2eastNorth(getTileLatLon(source, x, y, z));
    115         EastNorth max = proj.latlon2eastNorth(getTileLatLon(source, x + 1, y + 1, z));
    116         double y_size = Math.abs(min.getY() - max.getY());
    117         double x_size = Math.abs(min.getX() - max.getX());
     116        /**
     117         * t1 | t2
     118         * -------
     119         * t3 | t4
     120         */
     121        EastNorth t1 = proj.latlon2eastNorth(getTileLatLon(source, x, y, z));
     122        EastNorth t2 = proj.latlon2eastNorth(getTileLatLon(source, x + 1, y, z));
     123        EastNorth t3 = proj.latlon2eastNorth(getTileLatLon(source, x, y + 1, z));
     124        EastNorth t4 = proj.latlon2eastNorth(getTileLatLon(source, x + 1, y + 1, z));
     125        double y_size = Math.abs(t1.getY() - t4.getY());
     126        double x_size = Math.abs(t1.getX() - t4.getX());
    118127        assertEquals(x_size, y_size, 1e-05);
     128        assertEquals(y_size, Math.abs(t1.getY() - t3.getY()), 1e-05);
     129        assertEquals(x_size, Math.abs(t1.getX() - t2.getX()), 1e-05);
     130
     131        t1 = source.getTileEastNorth(x, y, z);
     132        t2 = source.getTileEastNorth(x + 1, y, z);
     133        t3 = source.getTileEastNorth(x, y + 1, z);
     134        t4 = source.getTileEastNorth(x + 1, y + 1, z);
     135        y_size = Math.abs(t1.getY() - t4.getY());
     136        x_size = Math.abs(t1.getX() - t4.getX());
     137        assertEquals(x_size, y_size, 1e-05);
     138        assertEquals(y_size, Math.abs(t1.getY() - t3.getY()), 1e-05);
     139        assertEquals(x_size, Math.abs(t1.getX() - t2.getX()), 1e-05);
    119140    }
    120141
Note: See TracChangeset for help on using the changeset viewer.