Changeset 11792 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-03-29T22:50:22+02:00 (7 years ago)
Author:
bastiK
Message:

fixed #14590 - WMTS: Show layer title, not layer identifier in layer selection dialog

Location:
trunk/src/org/openstreetmap/josm/data/imagery
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java

    r11747 r11792  
    6464    static final QName QN_OWS_OPERATIONS_METADATA = new QName(OWS_NS_URL, "OperationsMetadata");
    6565    static final QName QN_OWS_SUPPORTED_CRS       = new QName(OWS_NS_URL, "SupportedCRS");
     66    static final QName QN_OWS_TITLE               = new QName(OWS_NS_URL, "Title");
    6667    static final QName QN_OWS_VALUE               = new QName(OWS_NS_URL, "Value");
    6768    // CHECKSTYLE.ON: SingleSpaceSeparator
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r11791 r11792  
    144144    private static class Layer {
    145145        private String format;
    146         private String name;
     146        private String identifier;
     147        private String title;
    147148        private TileMatrixSet tileMatrixSet;
    148149        private String baseUrl;
     
    153154            Objects.requireNonNull(l);
    154155            format = l.format;
    155             name = l.name;
     156            identifier = l.identifier;
     157            title = l.title;
    156158            baseUrl = l.baseUrl;
    157159            style = l.style;
     
    160162
    161163        Layer() {
     164        }
     165
     166        /**
     167         * Get title of the layer for user display.
     168         *
     169         * This is either the content of the Title element (if available) or
     170         * the layer identifier (as fallback)
     171         * @return title of the layer for user display
     172         */
     173        public String getUserTitle() {
     174            return title != null ? title : identifier;
    162175        }
    163176    }
     
    179192                                return SelectLayerDialog.this.layers.get(rowIndex).getValue()
    180193                                        .stream()
    181                                         .map(x -> x.name)
     194                                        .map(x -> x.getUserTitle())
    182195                                        .collect(Collectors.joining(", ")); //this should be only one
    183196                            case 1:
     
    231244            }
    232245            Layer selectedLayer = layers.get(index).getValue().get(0);
    233             return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier);
     246            return new WMTSDefaultLayer(selectedLayer.identifier, selectedLayer.tileMatrixSet.identifier);
    234247        }
    235248    }
     
    269282     */
    270283    public DefaultLayer userSelectLayer() {
    271         Map<String, List<Layer>> layerByName = layers.stream().collect(
    272                 Collectors.groupingBy(x -> x.name));
    273         if (layerByName.size() == 1) { // only one layer
    274             List<Layer> ls = layerByName.entrySet().iterator().next().getValue()
     284        Map<String, List<Layer>> layerById = layers.stream().collect(
     285                Collectors.groupingBy(x -> x.identifier));
     286        if (layerById.size() == 1) { // only one layer
     287            List<Layer> ls = layerById.entrySet().iterator().next().getValue()
    275288                    .stream().filter(
    276289                            u -> u.tileMatrixSet.crs.equals(Main.getProjection().toCode()))
     
    279292                // only one tile matrix set with matching projection - no point in asking
    280293                Layer selectedLayer = ls.get(0);
    281                 return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier);
     294                return new WMTSDefaultLayer(selectedLayer.identifier, selectedLayer.tileMatrixSet.identifier);
    282295            }
    283296        }
     
    304317    private static List<Entry<String, List<Layer>>> groupLayersByNameAndTileMatrixSet(Collection<Layer> layers) {
    305318        Map<String, List<Layer>> layerByName = layers.stream().collect(
    306                 Collectors.groupingBy(x -> x.name + '\u001c' + x.tileMatrixSet.identifier));
     319                Collectors.groupingBy(x -> x.identifier + '\u001c' + x.tileMatrixSet.identifier));
    307320        return layerByName.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList());
    308321    }
     
    412425                        }
    413426                    } else if (GetCapabilitiesParseHelper.QN_OWS_IDENTIFIER.equals(reader.getName())) {
    414                         layer.name = reader.getElementText();
     427                        layer.identifier = reader.getElementText();
     428                    } else if (GetCapabilitiesParseHelper.QN_OWS_TITLE.equals(reader.getName())) {
     429                        layer.title = reader.getElementText();
    415430                    } else if (QN_RESOURCE_URL.equals(reader.getName()) &&
    416431                            "tile".equals(reader.getAttributeValue("", "resourceType"))) {
     
    444459            // no format found - it's mandatory parameter - can't use this layer
    445460            Main.warn(tr("Can''t use layer {0} because no supported formats where found. Layer is available in formats: {1}",
    446                     layer.name,
     461                    layer.getUserTitle(),
    447462                    String.join(", ", unsupportedFormats)));
    448463            return null;
     
    581596        // so we will not ask the user again to chose the layer, if he just changes projection
    582597        Collection<Layer> candidates = getLayers(
    583                 currentLayer != null ? new WMTSDefaultLayer(currentLayer.name, currentLayer.tileMatrixSet.identifier) : defaultLayer,
     598                currentLayer != null ? new WMTSDefaultLayer(currentLayer.identifier, currentLayer.tileMatrixSet.identifier) : defaultLayer,
    584599                proj.toCode());
    585600
     
    602617        } else if (candidates.size() > 1) {
    603618            Main.warn("More than one layer WMTS available: {0} for projection {1} and name {2}. Do not know which to process",
    604                     candidates.stream().map(x -> x.name + ": " + x.tileMatrixSet.identifier).collect(Collectors.joining(", ")),
     619                    candidates.stream().map(x -> x.getUserTitle() + ": " + x.tileMatrixSet.identifier).collect(Collectors.joining(", ")),
    605620                    proj.toCode(),
    606                     currentLayer != null ? currentLayer.name : defaultLayer
     621                    currentLayer != null ? currentLayer.getUserTitle() : defaultLayer
    607622                    );
    608623        }
     
    621636            for (Layer layer: this.layers) {
    622637                if ((searchLayer == null || (// if it's null, then accept all layers
    623                         searchLayer.getLayerName().equals(layer.name)))
     638                        searchLayer.getLayerName().equals(layer.identifier)))
    624639                        && (projectionCode == null || // if it's null, then accept any projection
    625640                        projectionCode.equals(layer.tileMatrixSet.crs))) {
     
    673688        }
    674689
    675         return url.replaceAll("\\{layer\\}", this.currentLayer.name)
     690        return url.replaceAll("\\{layer\\}", this.currentLayer.identifier)
    676691                .replaceAll("\\{format\\}", this.currentLayer.format)
    677692                .replaceAll("\\{TileMatrixSet\\}", this.currentTileMatrixSet.identifier)
     
    845860        } else {
    846861            for (Layer layer: this.layers) {
    847                 if (currentLayer.name.equals(layer.name)) {
     862                if (currentLayer.identifier.equals(layer.identifier)) {
    848863                    ret.add(layer.tileMatrixSet.crs);
    849864                }
Note: See TracChangeset for help on using the changeset viewer.