From 8ee91875f60f8b2180b2356c4c0be86bd0de48e4 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sun, 30 Sep 2018 22:51:22 +0100
Subject: [PATCH v1 3/4] SlippyMapBBoxChooser: also gather TileSources from
current imagery layers
this should catch imagery sources that were added through means other than the imagery menu (e.g. remotecontrol)
---
.../josm/gui/bbox/SlippyMapBBoxChooser.java | 34 ++++++++++++++++++----
.../josm/gui/dialogs/MinimapDialogTest.java | 34 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java b/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
index 4b322854d..821065de6 100644
|
a
|
b
|
import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
| 54 | 54 | import org.openstreetmap.josm.data.preferences.StringProperty; |
| 55 | 55 | import org.openstreetmap.josm.gui.MainApplication; |
| 56 | 56 | import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; |
| | 57 | import org.openstreetmap.josm.gui.layer.ImageryLayer; |
| 57 | 58 | import org.openstreetmap.josm.gui.layer.MainLayerManager; |
| 58 | 59 | import org.openstreetmap.josm.gui.layer.TMSLayer; |
| 59 | 60 | import org.openstreetmap.josm.spi.preferences.Config; |
| … |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, Cha
|
| 76 | 77 | List<TileSource> getTileSources(); |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | | /** |
| 80 | | * TMS TileSource provider for the slippymap chooser |
| 81 | | */ |
| 82 | | public static class TMSTileSourceProvider implements TileSourceProvider { |
| | 80 | public abstract static class AbstractImageryInfoBasedTileSourceProvider implements TileSourceProvider { |
| | 81 | public abstract List<ImageryInfo> getImageryInfos(); |
| 83 | 82 | |
| 84 | 83 | @Override |
| 85 | 84 | public List<TileSource> getTileSources() { |
| 86 | 85 | if (!TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get()) return Collections.<TileSource>emptyList(); |
| 87 | 86 | List<TileSource> sources = new ArrayList<>(); |
| 88 | | for (ImageryInfo info : ImageryLayerInfo.instance.getLayers()) { |
| | 87 | for (ImageryInfo info : this.getImageryInfos()) { |
| 89 | 88 | try { |
| 90 | 89 | TileSource source = TMSLayer.getTileSourceStatic(info); |
| 91 | 90 | if (source != null) { |
| … |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, Cha
|
| 105 | 104 | } |
| 106 | 105 | |
| 107 | 106 | /** |
| | 107 | * TileSource provider for the slippymap chooser - providing sources from imagery sources menu |
| | 108 | */ |
| | 109 | public static class TMSTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider { |
| | 110 | @Override |
| | 111 | public List<ImageryInfo> getImageryInfos() { |
| | 112 | return ImageryLayerInfo.instance.getLayers(); |
| | 113 | } |
| | 114 | } |
| | 115 | |
| | 116 | /** |
| | 117 | * TileSource provider for the slippymap chooser - providing sources from current layers |
| | 118 | */ |
| | 119 | public static class CurrentLayersTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider { |
| | 120 | @Override |
| | 121 | public List<ImageryInfo> getImageryInfos() { |
| | 122 | return MainApplication.getLayerManager().getLayers().stream().filter( |
| | 123 | layer -> layer instanceof ImageryLayer |
| | 124 | ).map( |
| | 125 | layer -> ((ImageryLayer) layer).getInfo() |
| | 126 | ).collect(Collectors.toList()); |
| | 127 | } |
| | 128 | } |
| | 129 | |
| | 130 | /** |
| 108 | 131 | * Plugins that wish to add custom tile sources to slippy map choose should call this method |
| 109 | 132 | * @param tileSourceProvider new tile source provider |
| 110 | 133 | */ |
| … |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, Cha
|
| 116 | 139 | static { |
| 117 | 140 | addTileSourceProvider(() -> Arrays.<TileSource>asList(new OsmTileSource.Mapnik())); |
| 118 | 141 | addTileSourceProvider(new TMSTileSourceProvider()); |
| | 142 | addTileSourceProvider(new CurrentLayersTileSourceProvider()); |
| 119 | 143 | } |
| 120 | 144 | |
| 121 | 145 | private static final StringProperty PROP_MAPSTYLE = new StringProperty("slippy_map_chooser.mapstyle", "Mapnik"); |
diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
index 9d9fa63e3..8d33d3f2a 100644
|
a
|
b
|
import org.openstreetmap.josm.TestUtils;
|
| 30 | 30 | import org.openstreetmap.josm.data.Bounds; |
| 31 | 31 | import org.openstreetmap.josm.data.DataSource; |
| 32 | 32 | import org.openstreetmap.josm.data.osm.DataSet; |
| | 33 | import org.openstreetmap.josm.data.imagery.ImageryInfo; |
| 33 | 34 | import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; |
| 34 | 35 | import org.openstreetmap.josm.data.projection.ProjectionRegistry; |
| 35 | 36 | import org.openstreetmap.josm.data.projection.Projections; |
| … |
… |
import org.openstreetmap.josm.gui.MainApplication;
|
| 37 | 38 | import org.openstreetmap.josm.gui.MapView; |
| 38 | 39 | import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; |
| 39 | 40 | import org.openstreetmap.josm.gui.bbox.SourceButton; |
| | 41 | import org.openstreetmap.josm.gui.layer.ImageryLayer; |
| 40 | 42 | import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer; |
| 41 | 43 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
| 42 | 44 | import org.openstreetmap.josm.gui.util.GuiHelper; |
| … |
… |
public class MinimapDialogTest {
|
| 292 | 294 | } |
| 293 | 295 | |
| 294 | 296 | /** |
| | 297 | * Tests the tile source list includes sources only present in the LayerManager |
| | 298 | * @throws Exception if any error occurs |
| | 299 | */ |
| | 300 | @Test |
| | 301 | public void testTileSourcesFromCurrentLayers() throws Exception { |
| | 302 | // relevant prefs starting out empty, should choose the first (ImageryLayerInfo) source and have shown download area enabled |
| | 303 | // (not that there's a data layer for it to use) |
| | 304 | |
| | 305 | // first we will remove "Green Tiles" from ImageryLayerInfo |
| | 306 | final ImageryInfo greenTilesInfo = ImageryLayerInfo.instance.getLayers().stream().filter( |
| | 307 | i -> i.getName().equals("Green Tiles") |
| | 308 | ).findAny().get(); |
| | 309 | ImageryLayerInfo.instance.remove(greenTilesInfo); |
| | 310 | |
| | 311 | GuiHelper.runInEDT(() -> MainApplication.getLayerManager().addLayer(ImageryLayer.create(greenTilesInfo))); |
| | 312 | |
| | 313 | this.setUpMiniMap(); |
| | 314 | |
| | 315 | this.clickSourceMenuItemByLabel("Green Tiles"); |
| | 316 | this.assertSingleSelectedSourceLabel("Green Tiles"); |
| | 317 | |
| | 318 | // call paint to trigger new tile fetch |
| | 319 | this.paintSlippyMap(); |
| | 320 | |
| | 321 | Awaitility.await().atMost(1000, MILLISECONDS).until(this.slippyMapTasksFinished); |
| | 322 | |
| | 323 | this.paintSlippyMap(); |
| | 324 | |
| | 325 | assertEquals(0xff00ff00, paintedSlippyMap.getRGB(0, 0)); |
| | 326 | } |
| | 327 | |
| | 328 | /** |
| 295 | 329 | * Tests minimap obeys a saved "mapstyle" preference on startup. |
| 296 | 330 | * @throws Exception if any error occurs |
| 297 | 331 | */ |