Allow users to toggle paintstyle automatically based off of layer

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-31 15:53:34 -06:00
rodzic a181a4d446
commit f0898f5a5d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 79 dodań i 4 usunięć

Wyświetl plik

@ -24,6 +24,7 @@ import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
import org.openstreetmap.josm.gui.mappaint.StyleSource;
import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
@ -82,6 +83,14 @@ public final class MapWithAIDataUtils {
.forEach(MapPaintStyles::removeStyle);
}
/**
* @return get the MapWithAI Paint style
*/
public static StyleSource getMapWithAIPaintStyle() {
return MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> PAINT_STYLE_RESOURCE_URL.equals(source.url)).findAny().orElse(null);
}
/**
* Add primitives and their children to a collection
*

Wyświetl plik

@ -18,14 +18,21 @@ import javax.swing.SwingConstants;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.DownloadPolicy;
import org.openstreetmap.josm.data.osm.UploadPolicy;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
import org.openstreetmap.josm.gui.mappaint.StyleSource;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.GBC;
/**
* @author Taylor Smock
*
*/
public class MapWithAILayer extends OsmDataLayer {
public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeListener {
private Integer maximumAddition = null;
private String url = null;
private Boolean switchLayers = null;
@ -43,6 +50,7 @@ public class MapWithAILayer extends OsmDataLayer {
data.setUploadPolicy(UploadPolicy.BLOCKED);
data.setDownloadPolicy(DownloadPolicy.BLOCKED);
lock = new MapLock();
MainApplication.getLayerManager().addActiveLayerChangeListener(this);
}
// @Override TODO remove comment on 2020-01-01
@ -132,4 +140,31 @@ public class MapWithAILayer extends OsmDataLayer {
}
}
}
@Override
public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
if (checkIfToggleLayer()) {
StyleSource style = MapWithAIDataUtils.getMapWithAIPaintStyle();
if (style.active != this.equals(MainApplication.getLayerManager().getActiveLayer())) {
MapPaintStyles.toggleStyleActive(MapPaintStyles.getStyles().getStyleSources().indexOf(style));
}
}
}
private boolean checkIfToggleLayer() {
List<String> keys = Config.getPref().getKeySet().parallelStream()
.filter(string -> string.contains(MapWithAIPlugin.NAME) && string.contains("boolean:toggle_with_layer"))
.collect(Collectors.toList());
boolean toggle = false;
if (keys.size() == 1) {
toggle = Config.getPref().getBoolean(keys.get(0), false);
}
return toggle;
}
@Override
public synchronized void destroy() {
super.destroy();
MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
}
}

Wyświetl plik

@ -7,16 +7,47 @@ meta
min-josm-version: "15229";
}
/*******************************************
/***************************************************
* Set .mapwithai for all known MapWithAI datasets *
*******************************************/
way[source=~/^(?i)(microsoft|digitalglobe)$/] {
***************************************************/
settings::show_all {
label: tr("Show possible MapWithAI objects");
}
setting::show_new {
type: boolean;
label: tr("New");
default: true;
group: "show_all";
}
setting::show_modified {
type: boolean;
label: tr("Modified");
default: false;
group: "show_all";
}
setting::show_old {
type: boolean;
label: tr("Pre-existing");
default: false;
group: "show_all";
}
/* This requires support in the plugin (will read key for mapwithai.mapcss:boolean:toggle_with_layer) */
setting::toggle_with_layer {
type: boolean;
label: tr("Toggle paintstyle on/off with layer");
default: false;
}
way[source=~/^(?i)(microsoft|digitalglobe)$/][setting("show_old")]!:new!:modified,
way[source=~/^(?i)(microsoft|digitalglobe)$/][setting("show_new")]:new,
way[source=~/^(?i)(microsoft|digitalglobe)$/][setting("show_modified")]:modified {
set .mapwithai;
}
way.mapwithai {
color: mapwithai#FF00FF;
}
way.mapwithai:closed2 {
fill-color: mapwithai#FF00FF;
}