Changeset 11257 in josm for trunk/src/org
- Timestamp:
- 2016-11-15T21:46:24+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 3 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 }
Note:
See TracChangeset
for help on using the changeset viewer.