Changeset 11791 in josm


Ignore:
Timestamp:
2017-03-29T22:07:06+02:00 (7 months ago)
Author:
bastiK
Message:

WMTS: don't show layer selection dialog if there is only one layer with one tile matrix set that matches the current projection (see #10623)

File:
1 edited

Legend:

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

    r11790 r11791  
    2525import java.util.TreeSet;
    2626import java.util.concurrent.ConcurrentHashMap;
    27 import java.util.function.Predicate;
    2827import java.util.regex.Matcher;
    2928import java.util.regex.Pattern;
     
    170169        SelectLayerDialog(Collection<Layer> layers) {
    171170            super(Main.parent, tr("Select WMTS layer"), new String[]{tr("Add layers"), tr("Cancel")});
    172             this.layers = groupLayersByName(layers);
     171            this.layers = groupLayersByNameAndTileMatrixSet(layers);
    173172            //getLayersTable(layers, Main.getProjection())
    174173            this.list = new JTable(
     
    270269     */
    271270    public DefaultLayer userSelectLayer() {
    272         Collection<Entry<String, List<Layer>>> grouppedLayers = groupLayersByName(layers);
    273 
    274         // if there is only one layer name no point in asking
    275         if (grouppedLayers.size() == 1) {
    276             Layer selectedLayer = grouppedLayers.iterator().next().getValue().get(0);
    277             return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier);
     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()
     275                    .stream().filter(
     276                            u -> u.tileMatrixSet.crs.equals(Main.getProjection().toCode()))
     277                    .collect(Collectors.toList());
     278            if (ls.size() == 1) {
     279                // only one tile matrix set with matching projection - no point in asking
     280                Layer selectedLayer = ls.get(0);
     281                return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier);
     282            }
    278283        }
    279284
     
    297302    }
    298303
    299     private static List<Entry<String, List<Layer>>> groupLayersByName(Collection<Layer> layers) {
     304    private static List<Entry<String, List<Layer>>> groupLayersByNameAndTileMatrixSet(Collection<Layer> layers) {
    300305        Map<String, List<Layer>> layerByName = layers.stream().collect(
    301306                Collectors.groupingBy(x -> x.name + '\u001c' + x.tileMatrixSet.identifier));
Note: See TracChangeset for help on using the changeset viewer.