Changeset 14495 in josm for trunk/src/org/openstreetmap/josm/gui/bbox
- Timestamp:
- 2018-12-02T17:37:47+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r14330 r14495 13 13 import java.awt.geom.Path2D; 14 14 import java.util.ArrayList; 15 import java.util.Arrays;16 15 import java.util.Collections; 17 16 import java.util.HashMap; … … 90 89 public List<TileSource> getTileSources() { 91 90 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()); 107 110 } 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); 109 120 } 110 121 } … … 136 147 } 137 148 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 138 169 /** 139 170 * Plugins that wish to add custom tile sources to slippy map choose should call this method … … 146 177 private static CopyOnWriteArrayList<TileSourceProvider> providers = new CopyOnWriteArrayList<>(); 147 178 static { 148 addTileSourceProvider( () -> Arrays.<TileSource>asList(new OsmTileSource.Mapnik()));179 addTileSourceProvider(new DefaultOsmTileSourceProvider()); 149 180 addTileSourceProvider(new TMSTileSourceProvider()); 150 181 addTileSourceProvider(new CurrentLayersTileSourceProvider());
Note:
See TracChangeset
for help on using the changeset viewer.