- Timestamp:
- 2016-02-18T21:41:08+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r9818 r9825 47 47 import org.openstreetmap.josm.data.projection.Projections; 48 48 import org.openstreetmap.josm.gui.ExtendedDialog; 49 import org.openstreetmap.josm.gui.layer.NativeScaleLayer.Scale;50 49 import org.openstreetmap.josm.gui.layer.NativeScaleLayer.ScaleList; 51 50 import org.openstreetmap.josm.io.CachedFile; … … 246 245 private TransferMode transferMode; 247 246 247 private ScaleList nativeScaleList; 248 248 249 /** 249 250 * Creates a tile source based on imagery info … … 631 632 632 633 this.crsScale = getTileSize() * 0.28e-03 / proj.getMetersPerUnit(); 634 635 Collection<Double> scales = new ArrayList<>(currentTileMatrixSet.tileMatrix.size()); 636 if (currentTileMatrixSet != null) { 637 for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) { 638 scales.add(tileMatrix.scaleDenominator * 0.28e-03); 639 } 640 } 641 this.nativeScaleList = new ScaleList(scales); 633 642 } 634 643 … … 919 928 */ 920 929 public ScaleList getNativeScales() { 921 ScaleList scales = new ScaleList(); 922 if (currentTileMatrixSet != null) { 923 for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) { 924 scales.add(new Scale(tileMatrix.scaleDenominator * 0.28e-03)); 925 } 926 } 927 return scales; 930 return nativeScaleList; 928 931 } 929 932 -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r9818 r9825 156 156 public NavigatableComponent() { 157 157 setLayout(null); 158 PROP_ZOOM_RATIO.get(); // make sure it is available in preferences159 158 } 160 159 … … 208 207 } 209 208 Scale scale = scaleList.scaleZoomTimes(getScale(), PROP_ZOOM_RATIO.get(), times); 210 return scale. scale;209 return scale.getScale(); 211 210 } else { 212 211 return getScale() * Math.pow(PROP_ZOOM_RATIO.get(), times); … … 245 244 if (nativeScaleLayer != null) { 246 245 ScaleList scaleList = nativeScaleLayer.getNativeScales(); 247 return scaleList.getSnapScale(scale, PROP_ZOOM_RATIO.get(), floor). scale;246 return scaleList.getSnapScale(scale, PROP_ZOOM_RATIO.get(), floor).getScale(); 248 247 } else { 249 248 return scale; -
trunk/src/org/openstreetmap/josm/gui/layer/NativeScaleLayer.java
r9818 r9825 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collection; 6 import java.util.List; 5 7 6 8 import org.openstreetmap.josm.gui.NavigatableComponent; … … 25 27 * Scale factor, same unit as in {@link NavigatableComponent} 26 28 */ 27 p ublicdouble scale;29 private double scale; 28 30 29 31 /** 30 32 * True if this scale is native resolution for data source. 31 33 */ 32 p ublicboolean isNative;34 private boolean isNative; 33 35 34 36 private int index; … … 37 39 * Constructs a new Scale with given scale, native defaults to true. 38 40 * @param scale as defined in WMTS (scaleDenominator) 39 */ 40 public Scale(double scale) { 41 * @param index zoom index for this scale 42 */ 43 public Scale(double scale, int index) { 41 44 this.scale = scale; 42 45 this.isNative = true; 43 } 44 45 /** 46 * Constructs a new Scale with given scale and native values. 47 * @param scale as defined in WMTS (scaleDenominator) 48 * @param isNative is this scale native to the source or not 49 */ 50 public Scale(double scale, boolean isNative) { 51 this.scale = scale; 52 this.isNative = isNative; 46 this.index = index; 53 47 } 54 48 … … 77 71 return index; 78 72 } 73 74 public double getScale() { 75 return scale; 76 } 79 77 } 80 78 … … 83 81 * between native resolutions 84 82 */ 85 class ScaleList extends ArrayList<Scale> { 83 class ScaleList { 84 private List<Scale> scales = new ArrayList<>(); 85 86 protected ScaleList(double[] scales) { 87 for (int i = 0; i < scales.length; i++) { 88 this.scales.add(new Scale(scales[i], i)); 89 } 90 } 91 92 protected ScaleList() { 93 } 94 95 public ScaleList(Collection<Double> scales) { 96 int i = 0; 97 for (Double scale: scales) { 98 this.scales.add(new Scale(scale, i++)); 99 } 100 } 101 102 protected void addScale(Scale scale) { 103 scales.add(scale); 104 } 86 105 87 106 /** … … 94 113 ScaleList result = new ScaleList(); 95 114 Scale previous = null; 96 for (Scale current: this ) {115 for (Scale current: this.scales) { 97 116 if (previous != null) { 98 117 double step = previous.scale / current.scale; … … 102 121 for (int j = 1; j < steps; j++) { 103 122 double intermediate = previous.scale / Math.pow(smallStep, j); 104 result.add (new Scale(intermediate, false));123 result.addScale(new Scale(intermediate, false, current.index)); 105 124 } 106 125 } 107 result.add (current);126 result.addScale(current); 108 127 previous = current; 109 128 } 110 129 return result; 130 } 131 132 /** 133 * Get a scale from this ScaleList or a new scale if zoomed outside. 134 * @param scale previous scale 135 * @param floor use floor instead of round, set true when fitting view to objects 136 * @return new {@link Scale} 137 */ 138 public Scale getSnapScale(double scale, boolean floor) { 139 return getSnapScale(scale, NavigatableComponent.PROP_ZOOM_RATIO.get(), floor); 111 140 } 112 141 … … 119 148 */ 120 149 public Scale getSnapScale(double scale, double ratio, boolean floor) { 121 int size = size(); 122 Scale first = get(0); 123 Scale last = get(size-1); 150 int size = scales.size(); 151 Scale first = scales.get(0); 152 Scale last = scales.get(size-1); 153 124 154 if (scale > first.scale) { 125 155 double step = scale / first.scale; … … 143 173 Scale previous = null; 144 174 for (int i = 0; i < size; i++) { 145 Scale current = this. get(i);175 Scale current = this.scales.get(i); 146 176 if (previous != null) { 147 177 if (scale <= previous.scale && scale >= current.scale) { … … 207 237 public String toString() { 208 238 StringBuilder stringBuilder = new StringBuilder(); 209 for (Scale s: this ) {239 for (Scale s: this.scales) { 210 240 stringBuilder.append(s + "\n"); 211 241 } … … 215 245 private Scale getNextIn(Scale scale, double ratio) { 216 246 int nextIndex = scale.getIndex() + 1; 217 if (nextIndex <= 0 || nextIndex > size()-1) {247 if (nextIndex <= 0 || nextIndex > this.scales.size()-1) { 218 248 return new Scale(scale.scale / ratio, nextIndex == 0, nextIndex); 219 249 } else { 220 Scale nextScale = get(nextIndex);250 Scale nextScale = this.scales.get(nextIndex); 221 251 return new Scale(nextScale.scale, nextScale.isNative, nextIndex); 222 252 } … … 225 255 private Scale getNextOut(Scale scale, double ratio) { 226 256 int nextIndex = scale.getIndex() - 1; 227 if (nextIndex < 0 || nextIndex >= size()-1) {228 return new Scale(scale.scale * ratio, nextIndex == size()-1, nextIndex);257 if (nextIndex < 0 || nextIndex >= this.scales.size()-1) { 258 return new Scale(scale.scale * ratio, nextIndex == this.scales.size()-1, nextIndex); 229 259 } else { 230 Scale nextScale = get(nextIndex);260 Scale nextScale = this.scales.get(nextIndex); 231 261 return new Scale(nextScale.scale, nextScale.isNative, nextIndex); 232 262 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r9818 r9825 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.util.ArrayList; 7 import java.util.Collection; 5 8 6 9 import org.apache.commons.jcs.access.CacheAccess; … … 45 48 true); 46 49 50 private ScaleList nativeScaleList; 51 47 52 /** 48 53 * Create a layer based on ImageryInfo … … 51 56 public TMSLayer(ImageryInfo info) { 52 57 super(info); 58 Collection<Double> scales = new ArrayList<>(info.getMaxZoom()); 59 for (int zoom = info.getMinZoom(); zoom <= info.getMaxZoom(); zoom++) { 60 double scale = OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, zoom) / OsmMercator.DEFAUL_TILE_SIZE; 61 scales.add(scale); 62 } 63 this.nativeScaleList = new ScaleList(scales); 53 64 } 54 65 … … 149 160 @Override 150 161 public ScaleList getNativeScales() { 151 ScaleList scales = new ScaleList(); 152 for (int zoom = info.getMinZoom(); zoom <= info.getMaxZoom(); zoom++) { 153 double scale = OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, zoom) / OsmMercator.DEFAUL_TILE_SIZE; 154 scales.add(new Scale(scale)); 155 } 156 return scales; 162 return nativeScaleList; 157 163 } 158 }164 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java
r9818 r9825 62 62 protected int getBestZoom() { 63 63 if (!Main.isDisplayingMapView()) return 0; 64 ScaleList scaleList = getNativeScales(); 65 for (int i = scaleList.size()-1; i >= 0; i--) { 66 Scale scale = scaleList.get(i); 67 if (scale.scale >= Main.map.mapView.getScale()) { 68 return i; 69 } 70 } 71 return 0; 72 } 73 74 @Override 75 protected int getMaxZoomLvl() { 76 return getNativeScales().size()-1; 64 return Math.max( 65 getMinZoomLvl(), 66 Math.min( 67 getNativeScales().getSnapScale(Main.map.mapView.getScale(), false).getIndex(), 68 getMaxZoomLvl() 69 ) 70 ); 77 71 } 78 72
Note:
See TracChangeset
for help on using the changeset viewer.