Changeset 11858 in josm for trunk/src/org/openstreetmap/josm/data/imagery
- Timestamp:
- 2017-04-09T11:08:10+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java
r11830 r11858 11 11 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 12 12 import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; 13 import org.openstreetmap.josm.Main;14 13 import org.openstreetmap.josm.data.Bounds; 15 14 import org.openstreetmap.josm.data.ProjectionBounds; … … 32 31 private double[] degreesPerTile; 33 32 private static final float SCALE_DENOMINATOR_ZOOM_LEVEL_1 = 559082264.0287178f; 33 private Projection tileProjection; 34 34 35 35 /** 36 36 * Constructs a new {@code AbstractWMSTileSource}. 37 37 * @param info tile source info 38 * @param tileProjection the tile projection 38 39 */ 39 public AbstractWMSTileSource(TileSourceInfo info ) {40 public AbstractWMSTileSource(TileSourceInfo info, Projection tileProjection) { 40 41 super(info); 42 this.tileProjection = tileProjection; 41 43 } 42 44 … … 48 50 } 49 51 52 public void setTileProjection(Projection tileProjection) { 53 this.tileProjection = tileProjection; 54 initProjection(); 55 } 56 57 public Projection getTileProjection() { 58 return this.tileProjection; 59 } 60 50 61 /** 51 62 * Initializes class with current projection in JOSM. This call is needed every time projection changes. 52 63 */ 53 64 public void initProjection() { 54 initProjection( Main.getProjection());65 initProjection(this.tileProjection); 55 66 } 56 67 … … 99 110 @Override 100 111 public ICoordinate tileXYToLatLon(int x, int y, int zoom) { 101 return Main.getProjection().eastNorth2latlon(getTileEastNorth(x, y, zoom)).toCoordinate();112 return tileProjection.eastNorth2latlon(getTileEastNorth(x, y, zoom)).toCoordinate(); 102 113 } 103 114 … … 112 123 @Override 113 124 public TileXY latLonToTileXY(double lat, double lon, int zoom) { 114 EastNorth enPoint = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));125 EastNorth enPoint = tileProjection.latlon2eastNorth(new LatLon(lat, lon)); 115 126 return eastNorthToTileXY(enPoint, zoom); 116 127 } … … 144 155 public Point latLonToXY(double lat, double lon, int zoom) { 145 156 double scale = getDegreesPerTile(zoom) / getTileSize(); 146 EastNorth point = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));157 EastNorth point = tileProjection.latlon2eastNorth(new LatLon(lat, lon)); 147 158 return new Point( 148 159 (int) Math.round((point.east() - anchorPosition.east()) / scale), … … 164 175 public ICoordinate xyToLatLon(int x, int y, int zoom) { 165 176 double scale = getDegreesPerTile(zoom) / getTileSize(); 166 Projection proj = Main.getProjection();167 177 EastNorth ret = new EastNorth( 168 178 anchorPosition.east() + x * scale, 169 179 anchorPosition.north() - y * scale 170 180 ); 171 return proj.eastNorth2latlon(ret).toCoordinate();181 return tileProjection.eastNorth2latlon(ret).toCoordinate(); 172 182 } 173 183 … … 197 207 @Override 198 208 public String getServerCRS() { 199 return Main.getProjection().toCode();209 return this.tileProjection.toCode(); 200 210 } 201 211 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r11848 r11858 204 204 /** is the geo reference correct - don't offer offset handling */ 205 205 private boolean isGeoreferenceValid; 206 /** does the EPSG:4326 to mercator woraround work as expected */207 private boolean isEpsg4326To3857Supported;208 206 /** which layers should be activated by default on layer addition. **/ 209 207 private Collection<DefaultLayer> defaultLayers = Collections.emptyList(); … … 244 242 @pref boolean valid_georeference; 245 243 @pref boolean bestMarked; 246 @pref boolean supports_epsg_4326_to_3857_conversion;247 244 // TODO: disabled until change of layers is implemented 248 245 // @pref String default_layers; … … 309 306 310 307 valid_georeference = i.isGeoreferenceValid(); 311 supports_epsg_4326_to_3857_conversion = i.isEpsg4326To3857Supported();312 308 // TODO disabled until change of layers is implemented 313 309 // default_layers = i.defaultLayers.stream().collect(Collectors.joining(",")); … … 439 435 setTileSize(e.tileSize); 440 436 metadataHeaders = e.metadataHeaders; 441 isEpsg4326To3857Supported = e.supports_epsg_4326_to_3857_conversion;442 437 isGeoreferenceValid = e.valid_georeference; 443 438 // TODO disabled until change of layers is implemented … … 476 471 this.noTileChecksums = i.noTileChecksums; 477 472 this.metadataHeaders = i.metadataHeaders; 478 this.isEpsg4326To3857Supported = i.isEpsg4326To3857Supported;479 473 this.isGeoreferenceValid = i.isGeoreferenceValid; 480 474 this.defaultLayers = i.defaultLayers; … … 506 500 Objects.equals(this.url, other.url) && 507 501 Objects.equals(this.bestMarked, other.bestMarked) && 508 Objects.equals(this.isEpsg4326To3857Supported, other.isEpsg4326To3857Supported) &&509 502 Objects.equals(this.isGeoreferenceValid, other.isGeoreferenceValid) && 510 503 Objects.equals(this.cookies, other.cookies) && … … 1141 1134 this.metadataHeaders = metadataHeaders; 1142 1135 } 1143 }1144 1145 /**1146 * Gets the flag if epsg 4326 to 3857 is supported1147 * @return The flag.1148 */1149 public boolean isEpsg4326To3857Supported() {1150 return isEpsg4326To3857Supported;1151 }1152 1153 /**1154 * Sets the flag that epsg 4326 to 3857 is supported1155 * @param isEpsg4326To3857Supported The flag.1156 */1157 public void setEpsg4326To3857Supported(boolean isEpsg4326To3857Supported) {1158 this.isEpsg4326To3857Supported = isEpsg4326To3857Supported;1159 1136 } 1160 1137 -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r11843 r11858 46 46 private static final LongProperty MAXIMUM_EXPIRES = new LongProperty("imagery.generic.maximum_expires", TimeUnit.DAYS.toMillis(30)); 47 47 private static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1)); 48 pr ivatefinal Tile tile;48 protected final Tile tile; 49 49 private volatile URL url; 50 50 -
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r10990 r11858 19 19 import org.openstreetmap.josm.data.coor.EastNorth; 20 20 import org.openstreetmap.josm.data.coor.LatLon; 21 import org.openstreetmap.josm.data.projection.Projection; 21 22 import org.openstreetmap.josm.gui.layer.WMSLayer; 22 23 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 54 55 * Creates a tile source based on imagery info 55 56 * @param info imagery info 57 * @param tileProjection the tile projection 56 58 */ 57 public TemplatedWMSTileSource(ImageryInfo info ) {58 super(info );59 public TemplatedWMSTileSource(ImageryInfo info, Projection tileProjection) { 60 super(info, tileProjection); 59 61 this.serverProjections = new TreeSet<>(info.getServerProjections()); 60 62 handleTemplate(); … … 69 71 @Override 70 72 public String getTileUrl(int zoom, int tilex, int tiley) { 71 String myProjCode = Main.getProjection().toCode();73 String myProjCode = getServerCRS(); 72 74 73 75 EastNorth nw = getTileEastNorth(tilex, tiley, zoom); … … 79 81 double s = se.getY(); 80 82 double e = se.getX(); 81 82 if (!serverProjections.contains(myProjCode) && serverProjections.contains("EPSG:4326") && "EPSG:3857".equals(myProjCode)) {83 LatLon swll = Main.getProjection().eastNorth2latlon(new EastNorth(w, s));84 LatLon nell = Main.getProjection().eastNorth2latlon(new EastNorth(e, n));85 myProjCode = "EPSG:4326";86 s = swll.lat();87 w = swll.lon();88 n = nell.lat();89 e = nell.lon();90 }91 83 92 84 if ("EPSG:4326".equals(myProjCode) && !serverProjections.contains(myProjCode) && serverProjections.contains("CRS:84")) { -
trunk/src/org/openstreetmap/josm/data/imagery/WMSCachedTileLoaderJob.java
r8624 r11858 8 8 import org.openstreetmap.gui.jmapviewer.Tile; 9 9 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 12 11 … … 40 39 String key = super.getCacheKey(); 41 40 if (key != null) { 42 return key + Main.getProjection().toCode();41 return key + tile.getSource().getServerCRS(); 43 42 } 44 43 return null; -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r11830 r11858 14 14 import java.util.Collection; 15 15 import java.util.Collections; 16 import java.util. HashSet;16 import java.util.LinkedHashSet; 17 17 import java.util.List; 18 18 import java.util.Map; … … 20 20 import java.util.Objects; 21 21 import java.util.Optional; 22 import java.util.Set;23 22 import java.util.SortedSet; 24 23 import java.util.Stack; … … 62 61 63 62 /** 64 * Tile Source handling WM S providers63 * Tile Source handling WMTS providers 65 64 * 66 65 * @author Wiktor Niesiobędzki … … 269 268 private final WMTSDefaultLayer defaultLayer; 270 269 270 private Projection tileProjection; 271 271 272 /** 272 273 * Creates a tile source based on imagery info … … 598 599 */ 599 600 public void initProjection(Projection proj) { 600 // getLayers will return only layers matching the name, if the user already choose the layer 601 // so we will not ask the user again to chose the layer, if he just changes projection 602 Collection<Layer> candidates = getLayers( 603 currentLayer != null ? new WMTSDefaultLayer(currentLayer.identifier, currentLayer.tileMatrixSet.identifier) : defaultLayer, 604 proj.toCode()); 605 606 if (candidates.size() > 1 && defaultLayer != null) { 607 candidates = candidates.stream() 608 .filter(t -> t.tileMatrixSet.identifier.equals(defaultLayer.getTileMatrixSet())) 609 .collect(Collectors.toList()); 610 } 611 if (candidates.size() == 1) { 612 Layer newLayer = candidates.iterator().next(); 613 if (newLayer != null) { 614 this.currentTileMatrixSet = newLayer.tileMatrixSet; 615 this.currentLayer = newLayer; 616 Collection<Double> scales = new ArrayList<>(currentTileMatrixSet.tileMatrix.size()); 617 for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) { 618 scales.add(tileMatrix.scaleDenominator * 0.28e-03); 619 } 620 this.nativeScaleList = new ScaleList(scales); 621 } 622 } else if (candidates.size() > 1) { 623 Main.warn("More than one layer WMTS available: {0} for projection {1} and name {2}. Do not know which to process", 624 candidates.stream().map(x -> x.getUserTitle() + ": " + x.tileMatrixSet.identifier).collect(Collectors.joining(", ")), 625 proj.toCode(), 626 currentLayer != null ? currentLayer.getUserTitle() : defaultLayer 627 ); 628 } 629 this.crsScale = getTileSize() * 0.28e-03 / proj.getMetersPerUnit(); 601 if (proj.equals(tileProjection)) 602 return; 603 List<Layer> matchingLayers = layers.stream().filter( 604 l -> l.identifier.equals(defaultLayer.layerName) && l.tileMatrixSet.crs.equals(proj.toCode())) 605 .collect(Collectors.toList()); 606 if (matchingLayers.size() > 1) { 607 this.currentLayer = matchingLayers.stream().filter( 608 l -> l.tileMatrixSet.identifier.equals(defaultLayer.getTileMatrixSet())) 609 .findFirst().orElse(null); 610 this.tileProjection = proj; 611 } else if (matchingLayers.size() == 1) { 612 this.currentLayer = matchingLayers.get(0); 613 this.tileProjection = proj; 614 } else { 615 // no tile matrix sets with current projection 616 if (this.currentLayer == null) { 617 this.tileProjection = null; 618 for (Layer layer : layers) { 619 if (!layer.identifier.equals(defaultLayer.layerName)) { 620 continue; 621 } 622 Projection pr = Projections.getProjectionByCode(layer.tileMatrixSet.crs); 623 if (pr != null) { 624 this.currentLayer = layer; 625 this.tileProjection = pr; 626 break; 627 } 628 } 629 if (this.currentLayer == null) 630 return; 631 } // else: keep currentLayer and tileProjection as is 632 } 633 this.currentTileMatrixSet = this.currentLayer.tileMatrixSet; 634 Collection<Double> scales = new ArrayList<>(currentTileMatrixSet.tileMatrix.size()); 635 for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) { 636 scales.add(tileMatrix.scaleDenominator * 0.28e-03); 637 } 638 this.nativeScaleList = new ScaleList(scales); 639 this.crsScale = getTileSize() * 0.28e-03 / this.tileProjection.getMetersPerUnit(); 630 640 } 631 641 … … 655 665 // no support for non-square tiles (tileHeight != tileWidth) 656 666 // and for different tile sizes at different zoom levels 657 Collection<Layer> projLayers = getLayers(null, Main.getProjection().toCode());667 Collection<Layer> projLayers = getLayers(null, tileProjection.toCode()); 658 668 if (!projLayers.isEmpty()) { 659 669 return projLayers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight; … … 736 746 TileMatrix matrix = getTileMatrix(zoom); 737 747 if (matrix == null) { 738 return Main.getProjection().getWorldBoundsLatLon().getCenter().toCoordinate();748 return tileProjection.getWorldBoundsLatLon().getCenter().toCoordinate(); 739 749 } 740 750 double scale = matrix.scaleDenominator * this.crsScale; 741 751 EastNorth ret = new EastNorth(matrix.topLeftCorner.east() + x * scale, matrix.topLeftCorner.north() - y * scale); 742 return Main.getProjection().eastNorth2latlon(ret).toCoordinate();752 return tileProjection.eastNorth2latlon(ret).toCoordinate(); 743 753 } 744 754 … … 750 760 } 751 761 752 Projection proj = Main.getProjection(); 753 EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon)); 762 EastNorth enPoint = tileProjection.latlon2eastNorth(new LatLon(lat, lon)); 754 763 double scale = matrix.scaleDenominator * this.crsScale; 755 764 return new TileXY( … … 766 775 @Override 767 776 public int getTileXMax(int zoom) { 768 return getTileXMax(zoom, Main.getProjection());777 return getTileXMax(zoom, tileProjection); 769 778 } 770 779 771 780 @Override 772 781 public int getTileYMax(int zoom) { 773 return getTileYMax(zoom, Main.getProjection());782 return getTileYMax(zoom, tileProjection); 774 783 } 775 784 … … 781 790 } 782 791 double scale = matrix.scaleDenominator * this.crsScale; 783 EastNorth point = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));792 EastNorth point = tileProjection.latlon2eastNorth(new LatLon(lat, lon)); 784 793 return new Point( 785 794 (int) Math.round((point.east() - matrix.topLeftCorner.east()) / scale), … … 805 814 } 806 815 double scale = matrix.scaleDenominator * this.crsScale; 807 Projection proj = Main.getProjection();808 816 EastNorth ret = new EastNorth( 809 817 matrix.topLeftCorner.east() + x * scale, 810 818 matrix.topLeftCorner.north() - y * scale 811 819 ); 812 LatLon ll = proj.eastNorth2latlon(ret);820 LatLon ll = tileProjection.eastNorth2latlon(ret); 813 821 return new Coordinate(ll.lat(), ll.lon()); 814 822 } … … 857 865 * @return set of projection codes that this TileSource supports 858 866 */ 859 public Set<String> getSupportedProjections() {860 Set<String> ret = newHashSet<>();867 public Collection<String> getSupportedProjections() { 868 Collection<String> ret = new LinkedHashSet<>(); 861 869 if (currentLayer == null) { 862 870 for (Layer layer: this.layers) { … … 910 918 public ScaleList getNativeScales() { 911 919 return nativeScaleList; 920 } 921 922 public Projection getTileProjection() { 923 return tileProjection; 912 924 } 913 925 … … 978 990 @Override 979 991 public String getServerCRS() { 980 return Main.getProjection().toCode();992 return tileProjection.toCode(); 981 993 } 982 994 }
Note:
See TracChangeset
for help on using the changeset viewer.