Changeset 8542 in josm
- Timestamp:
- 2015-06-30T13:57:53+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r8540 r8542 139 139 public AbstractTileSourceLayer(ImageryInfo info) { 140 140 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 }150 141 setBackgroundLayer(true); 151 142 this.setVisible(true); 152 153 initTileSource(getTileSource(info));154 143 MapView.addZoomChangeListener(this); 155 144 } … … 462 451 @Override 463 452 public void hookUpMapView() { 453 initTileSource(getTileSource(info)); 454 projectionChanged(null, Main.getProjection()); // check if projection is supported 455 464 456 // keep them final here, so we avoid namespace clutter in the class 465 457 final JPopupMenu tileOptionMenu = new JPopupMenu(); -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r8510 r8542 447 447 if (!isProjectionSupported(newValue)) { 448 448 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" 450 451 + "Change the projection again or remove the layer.", 451 452 getName(), newValue.toCode(), nameSupportedProjections()), -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r8530 r8542 17 17 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 18 18 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 19 import org.openstreetmap.josm.Main;20 19 import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory; 21 20 import org.openstreetmap.josm.data.imagery.ImageryInfo; … … 28 27 import org.openstreetmap.josm.data.preferences.IntegerProperty; 29 28 import 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;33 29 34 30 /** … … 42 38 /** should WMS layer autozoom in default mode */ 43 39 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty("imagery.wms.default_autozoom", true); 40 private List<String> supportedProjections; 44 41 45 42 /** … … 47 44 * @param info ImageryInfo description of the layer 48 45 */ 46 47 49 48 public WMSLayer(ImageryInfo info) { 50 49 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(); 85 51 } 86 52 … … 155 121 return null; 156 122 } 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 157 153 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java
r8530 r8542 48 48 } 49 49 } 50 verifyTileSquarness(source, 2270, 1323, 12); 50 51 verifyLocation(source, new LatLon(53.5937132, 19.5652017)); 51 52 verifyLocation(source, new LatLon(53.501565692302854, 18.54455233898721)); … … 62 63 verifyTileSquarness(source, 2, 2, 2); 63 64 verifyTileSquarness(source, 150, 20, 18); 65 verifyTileSquarness(source, 2270, 1323, 12); 64 66 } 65 67 … … 74 76 verifyTileSquarness(source, 2, 2, 2); 75 77 verifyTileSquarness(source, 150, 20, 18); 76 78 verifyTileSquarness(source, 2270, 1323, 12); 77 79 } 78 80 … … 112 114 private void verifyTileSquarness(TemplatedWMSTileSource source, int x, int y, int z) { 113 115 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()); 118 127 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); 119 140 } 120 141
Note: See TracChangeset
for help on using the changeset viewer.