diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java index 15e9e10..57b9373 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java @@ -17,7 +17,7 @@ import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; /** - * The category for a MapWithAI source + * The category for a MapWithAI source (i.e., buildings/highways/addresses/etc.) * * @author Taylor Smock * @@ -29,7 +29,7 @@ public enum MapWithAICategory implements ISourceCategory { ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")), POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", "presets", marktr("Presets")), FEATURED("presets/service/network-wireless.svg", "featured", marktr("Featured")), - OTHER(null, "other", marktr("Other")); + PREVIEW("presets/misc/fixme", "preview", marktr("Preview")), OTHER(null, "other", marktr("Other")); private static final Map> iconCache = Collections .synchronizedMap(new EnumMap<>(ImageSizes.class)); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 4536b3c..ccd7fb9 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -17,9 +17,11 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import org.openstreetmap.josm.data.StructUtils; import org.openstreetmap.josm.data.imagery.ImageryInfo; +import org.openstreetmap.josm.data.preferences.BooleanProperty; import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.PleaseWaitRunnable; import org.openstreetmap.josm.gui.util.GuiHelper; @@ -38,6 +40,10 @@ import org.openstreetmap.josm.tools.Utils; * Manages the list of imagery entries that are shown in the imagery menu. */ public class MapWithAILayerInfo { + /** + * A boolean preference used to determine if preview datasets should be shown + */ + private static final BooleanProperty SHOW_PREVIEW = new BooleanProperty("mapwithai.sources.preview", false); /** List of all usable layers */ private final List layers = Collections.synchronizedList(new ArrayList<>()); @@ -456,7 +462,7 @@ public class MapWithAILayerInfo { * @return unmodifiable list containing usable layers */ public List getLayers() { - return Collections.unmodifiableList(layers); + return Collections.unmodifiableList(filterPreview(layers)); } /** @@ -465,7 +471,7 @@ public class MapWithAILayerInfo { * @return unmodifiable list containing available default layers */ public List getDefaultLayers() { - return Collections.unmodifiableList(defaultLayers); + return Collections.unmodifiableList(filterPreview(defaultLayers)); } /** @@ -475,7 +481,24 @@ public class MapWithAILayerInfo { * @since 11570 */ public List getAllDefaultLayers() { - return Collections.unmodifiableList(allDefaultLayers); + return Collections.unmodifiableList(filterPreview(allDefaultLayers)); + } + + /** + * Remove preview layers, if {@link SHOW_PREVIEW} is not {@code true} + * + * @param layers The layers to filter + * @return The layers without any preview layers, if {@link SHOW_PREVIEW} is not + * {@code true}. + */ + private static List filterPreview(List layers) { + if (SHOW_PREVIEW.get()) { + return layers; + } + return layers.stream() + .filter(i -> i.getCategory() != MapWithAICategory.PREVIEW + && !i.getAdditionalCategories().contains(MapWithAICategory.PREVIEW)) + .collect(Collectors.toList()); } public static void addLayer(MapWithAIInfo info) {