Ignore:
Timestamp:
2018-12-02T17:37:47+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #17054 - prefer JOSM imagery entry "OpenStreetMap Carto (Standard)" over jmapviewer tile source "Mapnik"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r14330 r14495  
    1313import java.awt.geom.Path2D;
    1414import java.util.ArrayList;
    15 import java.util.Arrays;
    1615import java.util.Collections;
    1716import java.util.HashMap;
     
    9089        public List<TileSource> getTileSources() {
    9190            if (!TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get()) return Collections.<TileSource>emptyList();
    92             List<TileSource> sources = new ArrayList<>();
    93             for (ImageryInfo info : this.getImageryInfos()) {
    94                 try {
    95                     TileSource source = TMSLayer.getTileSourceStatic(info);
    96                     if (source != null) {
    97                         sources.add(source);
    98                     }
    99                 } catch (IllegalArgumentException ex) {
    100                     Logging.warn(ex);
    101                     if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
    102                         JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    103                                 ex.getMessage(), tr("Warning"),
    104                                 JOptionPane.WARNING_MESSAGE);
    105                     }
    106                 }
     91            return imageryInfosToTileSources(getImageryInfos());
     92        }
     93    }
     94
     95    /**
     96     * TileSource provider for the slippymap chooser - providing default OSM tile source
     97     * @since 14495
     98     */
     99    public static class DefaultOsmTileSourceProvider implements TileSourceProvider {
     100
     101        protected static final StringProperty DEFAULT_OSM_TILE_URL = new StringProperty(
     102                "default.osm.tile.source.url", "https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png");
     103
     104        @Override
     105        public List<TileSource> getTileSources() {
     106            List<TileSource> result = imageryInfosToTileSources(ImageryLayerInfo.instance.getLayers().stream()
     107                   .filter(l -> l.getUrl().equals(DEFAULT_OSM_TILE_URL.get())).collect(Collectors.toList()));
     108            if (result.isEmpty()) {
     109                result.add(new OsmTileSource.Mapnik());
    107110            }
    108             return sources;
     111            return result;
     112        }
     113
     114        /**
     115         * Returns the default OSM tile source.
     116         * @return the default OSM tile source
     117         */
     118        public static TileSource get() {
     119            return new DefaultOsmTileSourceProvider().getTileSources().get(0);
    109120        }
    110121    }
     
    136147    }
    137148
     149    static List<TileSource> imageryInfosToTileSources(List<ImageryInfo> imageryInfos) {
     150        List<TileSource> sources = new ArrayList<>();
     151        for (ImageryInfo info : imageryInfos) {
     152            try {
     153                TileSource source = TMSLayer.getTileSourceStatic(info);
     154                if (source != null) {
     155                    sources.add(source);
     156                }
     157            } catch (IllegalArgumentException ex) {
     158                Logging.warn(ex);
     159                if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
     160                    JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
     161                            ex.getMessage(), tr("Warning"),
     162                            JOptionPane.WARNING_MESSAGE);
     163                }
     164            }
     165        }
     166        return sources;
     167    }
     168
    138169    /**
    139170     * Plugins that wish to add custom tile sources to slippy map choose should call this method
     
    146177    private static CopyOnWriteArrayList<TileSourceProvider> providers = new CopyOnWriteArrayList<>();
    147178    static {
    148         addTileSourceProvider(() -> Arrays.<TileSource>asList(new OsmTileSource.Mapnik()));
     179        addTileSourceProvider(new DefaultOsmTileSourceProvider());
    149180        addTileSourceProvider(new TMSTileSourceProvider());
    150181        addTileSourceProvider(new CurrentLayersTileSourceProvider());
Note: See TracChangeset for help on using the changeset viewer.