Skip to content

Commit 69fe547

Browse files
author
stoecker
committed
fix #24678 - Possibility to specify custom MapPaintSettings for MapCSS rendering - patch by zkir
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19549 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent da5e0ee commit 69fe547

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ private MapPaintSettings() {
7171
Config.getPref().addPreferenceChangeListener(this);
7272
}
7373

74+
/**
75+
* Creates MapPaintSettings with most neutral settings, that do not override MapCSS.
76+
* Useful for MapCSS CLI/Plugin rendering, via {@link org.openstreetmap.josm.gui.mappaint.RenderingHelper}
77+
* @return a new MapPaintSettings instance with neutral values.
78+
* @since 19549
79+
*/
80+
public static MapPaintSettings createNeutralSettings() {
81+
MapPaintSettings neutralSettings = new MapPaintSettings();
82+
neutralSettings.useRealWidth = false; // Real width is not used (at least currently)
83+
neutralSettings.showDirectionArrow = false; // Direction arrows are turned off
84+
neutralSettings.showOnewayArrow = false; // One way arrows are disabled
85+
neutralSettings.showNamesDistance = 0; // Forced labels are turned off
86+
neutralSettings.showOrderNumber = false;
87+
neutralSettings.showOrderNumberOnSelectedWay = false;
88+
neutralSettings.outlineOnly = false;
89+
return neutralSettings;
90+
}
91+
7492
private void load() {
7593
showDirectionArrow = Config.getPref().getBoolean("draw.segment.direction", false);
7694
showOnewayArrow = Config.getPref().getBoolean("draw.oneway", true);

src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,24 @@ public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInacti
382382
this.styles = MapPaintStyles.getStyles();
383383
}
384384

385+
/**
386+
* Constructs a new {@code StyledMapRenderer} with custom map paint settings.
387+
*
388+
* @param g the graphics context. Must not be null.
389+
* @param nc the map viewport. Must not be null.
390+
* @param isInactiveMode if true, the paint visitor shall render OSM objects such that they
391+
* look inactive. Example: rendering of data in an inactive layer using light gray as color only.
392+
* @param paintSettings the map paint settings to use. Must not be null.
393+
* @throws IllegalArgumentException if {@code g} is null
394+
* @throws IllegalArgumentException if {@code nc} is null
395+
* @throws IllegalArgumentException if {@code paintSettings} is null
396+
* @since 19549
397+
*/
398+
public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode, MapPaintSettings paintSettings) {
399+
this(g, nc, isInactiveMode);
400+
this.paintSettings = paintSettings;
401+
}
402+
385403
/**
386404
* Set the {@link ElemStyles} instance to use for this renderer.
387405
* @param styles the {@code ElemStyles} instance to use
@@ -1410,7 +1428,9 @@ public void getColors() {
14101428
@Override
14111429
public void getSettings(boolean virtual) {
14121430
super.getSettings(virtual);
1413-
paintSettings = MapPaintSettings.INSTANCE;
1431+
if (paintSettings == null) {
1432+
paintSettings = MapPaintSettings.INSTANCE;
1433+
}
14141434

14151435
circum = nc.getDist100Pixel();
14161436
scale = nc.getScale();

src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openstreetmap.josm.gui.NavigatableComponent;
2727
import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
2828
import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
29+
import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
2930
import org.openstreetmap.josm.io.IllegalDataException;
3031
import org.openstreetmap.josm.tools.CheckParameterUtil;
3132
import org.openstreetmap.josm.tools.Logging;
@@ -183,7 +184,7 @@ public Point getLocationOnScreen() {
183184
g.setColor(Optional.ofNullable(backgroundColor).orElse(elemStyles.getBackgroundColor()));
184185
g.fillRect(0, 0, imgDimPx.width, imgDimPx.height);
185186
}
186-
StyledMapRenderer smr = new StyledMapRenderer(g, nc, false);
187+
StyledMapRenderer smr = new StyledMapRenderer(g, nc, false, MapPaintSettings.createNeutralSettings());
187188
smr.setStyles(elemStyles);
188189
smr.render(ds, false, bounds);
189190

0 commit comments

Comments
 (0)