Symbol scale option (#790)
This commit is contained in:
parent
cde5d898c7
commit
3043173814
@ -6,6 +6,8 @@
|
|||||||
- Mapsforge: map stream support [#784](https://github.com/mapsforge/vtm/pull/784)
|
- Mapsforge: map stream support [#784](https://github.com/mapsforge/vtm/pull/784)
|
||||||
- Render theme from Android content providers [#783](https://github.com/mapsforge/vtm/pull/783)
|
- Render theme from Android content providers [#783](https://github.com/mapsforge/vtm/pull/783)
|
||||||
- Render theme xml pull parser [#786](https://github.com/mapsforge/vtm/pull/786)
|
- Render theme xml pull parser [#786](https://github.com/mapsforge/vtm/pull/786)
|
||||||
|
- Symbol scale option [#790](https://github.com/mapsforge/vtm/pull/790)
|
||||||
|
- `Parameters.SYMBOL_SCALING`
|
||||||
- Many other minor improvements and bug fixes
|
- Many other minor improvements and bug fixes
|
||||||
- [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aclosed+milestone%3A0.15.0)
|
- [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aclosed+milestone%3A0.15.0)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016-2018 devemux86
|
* Copyright 2016-2020 devemux86
|
||||||
* Copyright 2017 Longri
|
* Copyright 2017 Longri
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
@ -59,6 +59,11 @@ public abstract class CanvasAdapter {
|
|||||||
*/
|
*/
|
||||||
public static Platform platform = Platform.UNKNOWN;
|
public static Platform platform = Platform.UNKNOWN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The symbol scale.
|
||||||
|
*/
|
||||||
|
public static float symbolScale = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The text scale.
|
* The text scale.
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +50,7 @@ import org.oscim.theme.styles.SymbolStyle.SymbolBuilder;
|
|||||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.IOUtils;
|
import org.oscim.utils.IOUtils;
|
||||||
|
import org.oscim.utils.Parameters;
|
||||||
import org.oscim.utils.Utils;
|
import org.oscim.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -61,10 +62,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static java.lang.Boolean.parseBoolean;
|
|
||||||
import static java.lang.Float.parseFloat;
|
|
||||||
import static java.lang.Integer.parseInt;
|
|
||||||
|
|
||||||
public class XmlThemeBuilder {
|
public class XmlThemeBuilder {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(XmlThemeBuilder.class);
|
private static final Logger log = LoggerFactory.getLogger(XmlThemeBuilder.class);
|
||||||
@ -565,7 +562,7 @@ public class XmlThemeBuilder {
|
|||||||
b.color(value);
|
b.color(value);
|
||||||
|
|
||||||
else if ("width".equals(name) || "stroke-width".equals(name)) {
|
else if ("width".equals(name) || "stroke-width".equals(name)) {
|
||||||
b.strokeWidth = parseFloat(value) * mScale * mStrokeScale;
|
b.strokeWidth = Float.parseFloat(value) * mScale * mStrokeScale;
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
if (!isOutline)
|
if (!isOutline)
|
||||||
validateNonNegative("width", b.strokeWidth);
|
validateNonNegative("width", b.strokeWidth);
|
||||||
@ -579,16 +576,16 @@ public class XmlThemeBuilder {
|
|||||||
b.cap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
|
b.cap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||||
|
|
||||||
else if ("fix".equals(name))
|
else if ("fix".equals(name))
|
||||||
b.fixed = parseBoolean(value);
|
b.fixed = Boolean.parseBoolean(value);
|
||||||
|
|
||||||
else if ("stipple".equals(name))
|
else if ("stipple".equals(name))
|
||||||
b.stipple = Math.round(parseInt(value) * mScale * mStrokeScale);
|
b.stipple = Math.round(Integer.parseInt(value) * mScale * mStrokeScale);
|
||||||
|
|
||||||
else if ("stipple-stroke".equals(name))
|
else if ("stipple-stroke".equals(name))
|
||||||
b.stippleColor(value);
|
b.stippleColor(value);
|
||||||
|
|
||||||
else if ("stipple-width".equals(name))
|
else if ("stipple-width".equals(name))
|
||||||
b.stippleWidth = parseFloat(value);
|
b.stippleWidth = Float.parseFloat(value);
|
||||||
|
|
||||||
else if ("fade".equals(name))
|
else if ("fade".equals(name))
|
||||||
b.fadeScale = Integer.parseInt(value);
|
b.fadeScale = Integer.parseInt(value);
|
||||||
@ -597,7 +594,7 @@ public class XmlThemeBuilder {
|
|||||||
; //min = Float.parseFloat(value);
|
; //min = Float.parseFloat(value);
|
||||||
|
|
||||||
else if ("blur".equals(name))
|
else if ("blur".equals(name))
|
||||||
b.blur = parseFloat(value);
|
b.blur = Float.parseFloat(value);
|
||||||
|
|
||||||
else if ("style".equals(name))
|
else if ("style".equals(name))
|
||||||
; // ignore
|
; // ignore
|
||||||
@ -667,8 +664,10 @@ public class XmlThemeBuilder {
|
|||||||
b.stippleWidth = 1;
|
b.stippleWidth = 1;
|
||||||
b.stippleColor = b.fillColor;
|
b.stippleColor = b.fillColor;
|
||||||
} else {
|
} else {
|
||||||
if (src != null)
|
if (src != null) {
|
||||||
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
float symbolScale = Parameters.SYMBOL_SCALING == Parameters.SymbolScaling.ALL ? CanvasAdapter.symbolScale : 1;
|
||||||
|
b.texture = Utils.loadTexture(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * symbolScale));
|
||||||
|
}
|
||||||
|
|
||||||
if (b.texture != null && hasSymbol) {
|
if (b.texture != null && hasSymbol) {
|
||||||
// Line symbol
|
// Line symbol
|
||||||
@ -1063,7 +1062,7 @@ public class XmlThemeBuilder {
|
|||||||
|
|
||||||
else if ("dy".equals(name))
|
else if ("dy".equals(name))
|
||||||
// NB: minus..
|
// NB: minus..
|
||||||
b.dy = -Float.parseFloat(value) * mScale;
|
b.dy = -Float.parseFloat(value) * mScale * CanvasAdapter.symbolScale;
|
||||||
|
|
||||||
else if ("symbol".equals(name))
|
else if ("symbol".equals(name))
|
||||||
symbol = value;
|
symbol = value;
|
||||||
@ -1088,7 +1087,7 @@ public class XmlThemeBuilder {
|
|||||||
if (b.dy == 0) {
|
if (b.dy == 0) {
|
||||||
value = "above".equals(value) ? "20" : "-20";
|
value = "above".equals(value) ? "20" : "-20";
|
||||||
// NB: minus..
|
// NB: minus..
|
||||||
b.dy = -Float.parseFloat(value) * mScale;
|
b.dy = -Float.parseFloat(value) * mScale * CanvasAdapter.symbolScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
@ -1103,7 +1102,7 @@ public class XmlThemeBuilder {
|
|||||||
String lowValue = symbol.toLowerCase(Locale.ENGLISH);
|
String lowValue = symbol.toLowerCase(Locale.ENGLISH);
|
||||||
if (lowValue.endsWith(".png") || lowValue.endsWith(".svg")) {
|
if (lowValue.endsWith(".png") || lowValue.endsWith(".svg")) {
|
||||||
try {
|
try {
|
||||||
b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * CanvasAdapter.symbolScale));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("{}: {}", symbol, e.getMessage());
|
log.error("{}: {}", symbol, e.getMessage());
|
||||||
}
|
}
|
||||||
@ -1247,7 +1246,17 @@ public class XmlThemeBuilder {
|
|||||||
String lowSrc = b.src.toLowerCase(Locale.ENGLISH);
|
String lowSrc = b.src.toLowerCase(Locale.ENGLISH);
|
||||||
if (lowSrc.endsWith(".png") || lowSrc.endsWith(".svg")) {
|
if (lowSrc.endsWith(".png") || lowSrc.endsWith(".svg")) {
|
||||||
try {
|
try {
|
||||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), b.src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
float symbolScale = 1;
|
||||||
|
switch (Parameters.SYMBOL_SCALING) {
|
||||||
|
case ALL:
|
||||||
|
symbolScale = CanvasAdapter.symbolScale;
|
||||||
|
break;
|
||||||
|
case POI:
|
||||||
|
if (!b.repeat)
|
||||||
|
symbolScale = CanvasAdapter.symbolScale;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), b.src, b.symbolWidth, b.symbolHeight, (int) (b.symbolPercent * symbolScale));
|
||||||
if (bitmap != null)
|
if (bitmap != null)
|
||||||
return buildSymbol(b, b.src, bitmap);
|
return buildSymbol(b, b.src, bitmap);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -16,6 +16,8 @@ package org.oscim.utils;
|
|||||||
|
|
||||||
public final class Parameters {
|
public final class Parameters {
|
||||||
|
|
||||||
|
public enum SymbolScaling {ALL, POI}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true the <code>Animator2</code> will be used instead of default <code>Animator</code>.
|
* If true the <code>Animator2</code> will be used instead of default <code>Animator</code>.
|
||||||
*/
|
*/
|
||||||
@ -73,6 +75,11 @@ public final class Parameters {
|
|||||||
*/
|
*/
|
||||||
public static int SIMPLIFICATION_TOLERANCE = 0;
|
public static int SIMPLIFICATION_TOLERANCE = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbol scaling mode.
|
||||||
|
*/
|
||||||
|
public static SymbolScaling SYMBOL_SCALING = SymbolScaling.POI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Texture atlas in themes.
|
* Texture atlas in themes.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user