Changeset 14495 in josm for trunk/src/org


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"

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 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());
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r14463 r14495  
    1919import org.openstreetmap.gui.jmapviewer.JMapViewer;
    2020import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
    21 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;
    2221import org.openstreetmap.josm.data.coor.LatLon;
    2322import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;
     
    2524import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    2625import org.openstreetmap.josm.gui.NavigatableComponent;
     26import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    2727import org.openstreetmap.josm.gui.util.GuiHelper;
    2828import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     
    323323        MapViewer(HistoryBrowserModel model) {
    324324            this.updater = new Updater(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
    325             setTileSource(new OsmTileSource.Mapnik()); // for attribution
     325            setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution
    326326            setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    327327            addMouseListener(new MouseAdapter() {
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r14390 r14495  
    5353import org.openstreetmap.gui.jmapviewer.interfaces.MapPolygon;
    5454import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle;
    55 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;
    5655import org.openstreetmap.josm.data.coor.EastNorth;
    5756import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    6362import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    6463import org.openstreetmap.josm.gui.MainApplication;
     64import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    6565import org.openstreetmap.josm.gui.download.DownloadDialog;
    6666import org.openstreetmap.josm.gui.help.HelpUtil;
     
    356356            // Add default item map
    357357            defaultMap = new JMapViewer();
    358             defaultMap.setTileSource(new OsmTileSource.Mapnik()); // for attribution
     358            defaultMap.setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution
    359359            defaultMap.addMouseListener(new MouseAdapter() {
    360360                @Override
Note: See TracChangeset for help on using the changeset viewer.