Changeset 11257 in josm for trunk/src/org


Ignore:
Timestamp:
2016-11-15T21:46:24+01:00 (3 years ago)
Author:
wiktorn
Message:

Make DefaultLayer a type that can have layerName and tileMatrixSet

As WMTS specification gives possibility to have many tileMatrixSet's for
one layer and projection, default layer must specify both - layerName
and tileMatrixSet.

Accommodate to that fact layer selection dialogs and internal
computations in WMTS TileSource.

Closes: #13975

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  
    2323
    2424import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.data.imagery.DefaultLayer;
    2526import org.openstreetmap.josm.data.imagery.ImageryInfo;
    2627import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
     
    8283            case WMTS:
    8384                // specify which layer to use
    84                 String layerId = new WMTSTileSource(info).userSelectLayer();
     85                DefaultLayer layerId = new WMTSTileSource(info).userSelectLayer();
    8586                if (layerId != null) {
    8687                    ImageryInfo copy = new ImageryInfo(info);
    87                     Collection<String> defaultLayers = new ArrayList<>(1);
     88                    Collection<DefaultLayer> defaultLayers = new ArrayList<>(1);
    8889                    defaultLayers.add(layerId);
    8990                    copy.setDefaultLayers(defaultLayers);
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r11217 r11257  
    195195    private boolean isEpsg4326To3857Supported;
    196196    /** which layers should be activated by default on layer addition. **/
    197     private Collection<String> defaultLayers = Collections.emptyList();
     197    private Collection<DefaultLayer> defaultLayers = Collections.emptyList();
    198198    // when adding a field, also adapt the ImageryInfo(ImageryInfo)
    199199    // and ImageryInfo(ImageryPreferenceEntry) constructor, equals method, and ImageryPreferenceEntry
     
    11561156     * @return Collection of the layer names
    11571157     */
    1158     public Collection<String> getDefaultLayers() {
     1158    public Collection<DefaultLayer> getDefaultLayers() {
    11591159        return defaultLayers;
    11601160    }
     
    11641164     * @param layers set the list of default layers
    11651165     */
    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        }
    11671172        this.defaultLayers = layers;
    11681173    }
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r11218 r11257  
    174174                            switch (columnIndex) {
    175175                            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
    177180                            case 1:
    178181                                return SelectLayerDialog.this.layers.get(rowIndex).getValue()
     
    184187                                        .stream()
    185188                                        .map(x -> x.tileMatrixSet.identifier)
    186                                         .collect(Collectors.joining(", "));
     189                                        .collect(Collectors.joining(", ")); //this should be only one
    187190                            default:
    188191                                throw new IllegalArgumentException();
     
    224227        }
    225228
    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() {
    232230            int index = list.getSelectedRow();
    233231            if (index < 0) {
    234232                return null; //nothing selected
    235233            }
    236             return layers.get(index).getKey();
     234            Layer selectedLayer = layers.get(index).getValue().iterator().next();
     235            return new WMTSDefaultLayer(selectedLayer.name, selectedLayer.tileMatrixSet.identifier);
    237236        }
    238237    }
     
    247246    private ScaleList nativeScaleList;
    248247
    249     private final String defaultLayer;
     248    private final WMTSDefaultLayer defaultLayer;
     249
    250250
    251251    /**
     
    261261        this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl(handleTemplate(info.getUrl()));
    262262        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();
    264264        if (this.layers.isEmpty())
    265265            throw new IllegalArgumentException(tr("No layers defined by getCapabilities document: {0}", info.getUrl()));
     
    270270     * @return Name of selected layer
    271271     */
    272     public String userSelectLayer() {
    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);;
    274274
    275275        // 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        }
    278280
    279281        final SelectLayerDialog layerSelection = new SelectLayerDialog(layers);
     
    294296        matcher.appendTail(output);
    295297        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());
    296304    }
    297305
     
    555563        // getLayers will return only layers matching the name, if the user already choose the layer
    556564        // 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
    558569        if (candidates.size() == 1) {
    559 
    560570            Layer newLayer = candidates.iterator().next();
    561571            if (newLayer != null) {
     
    580590    /**
    581591     *
    582      * @param name of the layer to match
     592     * @param searchLayer which layer do we look for
    583593     * @param projectionCode projection code to match
    584594     * @return Collection of layers matching the name of the layer and projection, or only projection if name is not provided
    585595     */
    586     private Collection<Layer> getLayers(String name, String projectionCode) {
     596    private Collection<Layer> getLayers(WMTSDefaultLayer searchLayer, String projectionCode) {
    587597        Collection<Layer> ret = new ArrayList<>();
    588598        if (this.layers != null) {
    589599            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))) {
    591605                    ret.add(layer);
    592606                }
Note: See TracChangeset for help on using the changeset viewer.