Changeset 11257 in josm
- Timestamp:
- 2016-11-15T21:46:24+01:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r11219 r11257 23 23 24 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.data.imagery.DefaultLayer; 25 26 import org.openstreetmap.josm.data.imagery.ImageryInfo; 26 27 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; … … 82 83 case WMTS: 83 84 // specify which layer to use 84 StringlayerId = new WMTSTileSource(info).userSelectLayer();85 DefaultLayer layerId = new WMTSTileSource(info).userSelectLayer(); 85 86 if (layerId != null) { 86 87 ImageryInfo copy = new ImageryInfo(info); 87 Collection< String> defaultLayers = new ArrayList<>(1);88 Collection<DefaultLayer> defaultLayers = new ArrayList<>(1); 88 89 defaultLayers.add(layerId); 89 90 copy.setDefaultLayers(defaultLayers); -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r11217 r11257 195 195 private boolean isEpsg4326To3857Supported; 196 196 /** which layers should be activated by default on layer addition. **/ 197 private Collection< String> defaultLayers = Collections.emptyList();197 private Collection<DefaultLayer> defaultLayers = Collections.emptyList(); 198 198 // when adding a field, also adapt the ImageryInfo(ImageryInfo) 199 199 // and ImageryInfo(ImageryPreferenceEntry) constructor, equals method, and ImageryPreferenceEntry … … 1156 1156 * @return Collection of the layer names 1157 1157 */ 1158 public Collection< String> getDefaultLayers() {1158 public Collection<DefaultLayer> getDefaultLayers() { 1159 1159 return defaultLayers; 1160 1160 } … … 1164 1164 * @param layers set the list of default layers 1165 1165 */ 1166 public void setDefaultLayers(Collection<String> layers) { 1166 public void setDefaultLayers(Collection<DefaultLayer> layers) { 1167 if (ImageryType.WMTS.equals(this.imageryType)) { 1168 CheckParameterUtil.ensureThat(layers == null || 1169 layers.isEmpty() || 1170 layers.iterator().next() instanceof WMTSDefaultLayer, "Incorrect default layer"); 1171 } 1167 1172 this.defaultLayers = layers; 1168 1173 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r11218 r11257 174 174 switch (columnIndex) { 175 175 case 0: 176 return SelectLayerDialog.this.layers.get(rowIndex).getKey(); 176 return SelectLayerDialog.this.layers.get(rowIndex).getValue() 177 .stream() 178 .map(x -> x.name) 179 .collect(Collectors.joining(", ")); //this should be only one 177 180 case 1: 178 181 return SelectLayerDialog.this.layers.get(rowIndex).getValue() … … 184 187 .stream() 185 188 .map(x -> x.tileMatrixSet.identifier) 186 .collect(Collectors.joining(", ")); 189 .collect(Collectors.joining(", ")); //this should be only one 187 190 default: 188 191 throw new IllegalArgumentException(); … … 224 227 } 225 228 226 private static List<Entry<String, List<Layer>>> groupLayersByName(Collection<Layer> layers) { 227 Map<String, List<Layer>> layerByName = layers.stream().collect(Collectors.groupingBy(x -> x.name)); 228 return layerByName.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()); 229 } 230 231 public String getSelectedLayer() { 229 public DefaultLayer getSelectedLayer() { 232 230 int index = list.getSelectedRow(); 233 231 if (index < 0) { 234 232 return null; //nothing selected 235 233 } 236 return layers.get(index).getKey(); 234 Layer selectedLayer = layers.get(index).getValue().iterator().next(); 235 return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier); 237 236 } 238 237 } … … 247 246 private ScaleList nativeScaleList; 248 247 249 private final String defaultLayer; 248 private final WMTSDefaultLayer defaultLayer; 249 250 250 251 251 /** … … 261 261 this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl(handleTemplate(info.getUrl())); 262 262 this.layers = getCapabilities(); 263 this.defaultLayer = info.getDefaultLayers().isEmpty() ? null : info.getDefaultLayers().iterator().next();263 this.defaultLayer = info.getDefaultLayers().isEmpty() ? null : (WMTSDefaultLayer) info.getDefaultLayers().iterator().next(); 264 264 if (this.layers.isEmpty()) 265 265 throw new IllegalArgumentException(tr("No layers defined by getCapabilities document: {0}", info.getUrl())); … … 270 270 * @return Name of selected layer 271 271 */ 272 public StringuserSelectLayer() {273 Collection< String> layerNames = layers.stream().map(x -> x.name).collect(Collectors.toSet());272 public DefaultLayer userSelectLayer() { 273 Collection<Entry<String, List<Layer>>> grouppedLayers = groupLayersByName(layers);; 274 274 275 275 // if there is only one layer name no point in asking 276 if (layerNames.size() == 1) 277 return layerNames.iterator().next(); 276 if (grouppedLayers.size() == 1) { 277 Layer selectedLayer = grouppedLayers.iterator().next().getValue().iterator().next(); 278 return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier); 279 } 278 280 279 281 final SelectLayerDialog layerSelection = new SelectLayerDialog(layers); … … 294 296 matcher.appendTail(output); 295 297 return output.toString(); 298 } 299 300 private static List<Entry<String, List<Layer>>> groupLayersByName(Collection<Layer> layers) { 301 Map<String, List<Layer>> layerByName = layers.stream().collect( 302 Collectors.groupingBy(x -> x.name + '\u001c' + x.tileMatrixSet.identifier)); 303 return layerByName.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()); 296 304 } 297 305 … … 555 563 // getLayers will return only layers matching the name, if the user already choose the layer 556 564 // so we will not ask the user again to chose the layer, if he just changes projection 557 Collection<Layer> candidates = getLayers(currentLayer != null ? currentLayer.name : defaultLayer, proj.toCode()); 565 Collection<Layer> candidates = getLayers( 566 currentLayer != null ? new WMTSDefaultLayer(currentLayer.name, currentLayer.tileMatrixSet.identifier) : defaultLayer, 567 proj.toCode()); 568 558 569 if (candidates.size() == 1) { 559 560 570 Layer newLayer = candidates.iterator().next(); 561 571 if (newLayer != null) { … … 580 590 /** 581 591 * 582 * @param name of the layer to match592 * @param searchLayer which layer do we look for 583 593 * @param projectionCode projection code to match 584 594 * @return Collection of layers matching the name of the layer and projection, or only projection if name is not provided 585 595 */ 586 private Collection<Layer> getLayers( String name, String projectionCode) {596 private Collection<Layer> getLayers(WMTSDefaultLayer searchLayer, String projectionCode) { 587 597 Collection<Layer> ret = new ArrayList<>(); 588 598 if (this.layers != null) { 589 599 for (Layer layer: this.layers) { 590 if ((name == null || name.equals(layer.name)) && (projectionCode == null || projectionCode.equals(layer.tileMatrixSet.crs))) { 600 if ((searchLayer == null || (// if it's null, then accept all layers 601 searchLayer.getLayerName().equals(layer.name) && 602 searchLayer.getTileMatrixSet().equals(layer.tileMatrixSet.identifier))) 603 && (projectionCode == null || // if it's null, then accept any projection 604 projectionCode.equals(layer.tileMatrixSet.crs))) { 591 605 ret.add(layer); 592 606 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r10945 r11257 8 8 import java.io.IOException; 9 9 import java.net.MalformedURLException; 10 import java.util.ArrayList; 11 import java.util.Collection; 10 12 11 13 import org.junit.Ignore; … … 38 40 private ImageryInfo testDuplicateTags = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12573-wmts-identifier.xml"); 39 41 private ImageryInfo testMissingStyleIdentifer = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12573-wmts-missing-style-identifier.xml"); 42 private ImageryInfo testMultipleTileMatrixForLayer = getImagery(TestUtils.getTestDataRoot() + 43 "wmts/bug13975-multiple-tile-matrices-for-one-layer-projection.xml"); 40 44 41 45 /** … … 263 267 } 264 268 269 @Test 270 public void testForMultipleTileMatricesForOneLayerProjection() throws Exception { 271 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); 272 ImageryInfo copy = new ImageryInfo(testMultipleTileMatrixForLayer); 273 Collection<DefaultLayer> defaultLayers = new ArrayList<>(1); 274 defaultLayers.add(new WMTSDefaultLayer("Mashhad_BaseMap_1", "default028mm")); 275 copy.setDefaultLayers(defaultLayers); 276 WMTSTileSource testSource = new WMTSTileSource(copy); 277 testSource.initProjection(Main.getProjection()); 278 assertEquals( 279 "http://188.253.0.155:6080/arcgis/rest/services/Mashhad_BaseMap_1/MapServer/WMTS/tile/1.0.0/Mashhad_BaseMap_1" 280 + "/default/default028mm/1/3/2", 281 testSource.getTileUrl(1, 2, 3) 282 ); 283 } 284 265 285 private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) { 266 286 LatLon ll = new LatLon(source.tileXYToLatLon(x, y, z)); … … 277 297 LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z)); 278 298 LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z + zoomOffset)); 279 //System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " + expected.toDisplayString());280 299 assertEquals("Longitude", LatLon.normalizeLon(expected.lon() - result.lon()), 0.0, 1e-04); 281 300 assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
Note:
See TracChangeset
for help on using the changeset viewer.