Render themes: symbol styles (#769)
This commit is contained in:
parent
1156976ea5
commit
635d5bacdd
@ -233,7 +233,11 @@
|
||||
|
||||
<xs:complexType name="symbol">
|
||||
<xs:attribute name="cat" type="xs:string" use="optional" />
|
||||
<xs:attribute name="src" type="tns:src" use="required" />
|
||||
|
||||
<xs:attribute name="id" default="0" type="xs:string" use="optional" />
|
||||
<xs:attribute name="use" default="0" type="xs:string" use="optional" />
|
||||
|
||||
<xs:attribute name="src" type="tns:src" use="optional" />
|
||||
<xs:attribute name="symbol-width" type="xs:positiveInteger" use="optional" />
|
||||
<xs:attribute name="symbol-height" type="xs:positiveInteger" use="optional" />
|
||||
<xs:attribute name="symbol-percent" type="xs:positiveInteger" use="optional" />
|
||||
@ -332,6 +336,7 @@
|
||||
<xs:sequence maxOccurs="256" minOccurs="0">
|
||||
<xs:choice maxOccurs="unbounded" minOccurs="0">
|
||||
<xs:element name="style-text" type="tns:text" />
|
||||
<xs:element name="style-symbol" type="tns:symbol" />
|
||||
<xs:element name="style-area" type="tns:area" />
|
||||
<xs:element name="style-line" type="tns:line" />
|
||||
<!-- <xs:element name="style-outline" type="tns:line" /> -->
|
||||
|
@ -165,6 +165,11 @@
|
||||
<style-line cap="butt" fix="true" id="water" stroke="#a4bbcc" width="1.0" />
|
||||
<style-line fix="false" id="river" stroke="#a4bbcc" use="water" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
@ -1079,7 +1084,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="highway">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -129,6 +129,9 @@
|
||||
<style-line fade="15" id="building" stroke="#eeb7b6b3" use="fix" />
|
||||
<style-area fade="15" fill="#f2f0eb" id="building" />
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
<m closed="yes" e="way" k="layer" v="water">
|
||||
<area mesh="true" use="water" />
|
||||
</m>
|
||||
@ -1038,7 +1041,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="kind_detail">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -118,6 +118,11 @@
|
||||
<style-line cap="butt" id="water:outline" stroke="#647b8c" width="1.0" />
|
||||
<style-line cap="butt" id="water" stroke="#cca4bbcc" width="0.6" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
@ -1080,7 +1085,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="highway">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -162,6 +162,11 @@
|
||||
<!-- <style-line id="building" stroke="#d0cec8" width="1.0" fix="true" cap="butt" fade="15"/> -->
|
||||
<style-line fade="15" id="building" stroke="#eeb7b6b3" use="fix" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
@ -332,7 +337,7 @@
|
||||
|
||||
<m k="oneway" v="1" zoom-min="16">
|
||||
<m k="class" v="motorway|trunk|primary|secondary|tertiary|minor">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -52,6 +52,11 @@
|
||||
<style-line id="secondary" stroke="#c6c6c6" width="1.4" />
|
||||
<style-line id="tertiary" stroke="#f7f7f7" width="1.15" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
@ -959,7 +964,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="highway">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -52,6 +52,11 @@
|
||||
<style-line id="secondary" stroke="#fdbf6f" width="1.4" />
|
||||
<style-line id="tertiary" stroke="#ffff90" width="1.15" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
@ -959,7 +964,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="highway">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -119,6 +119,11 @@
|
||||
<style-line cap="butt" id="water:outline" stroke="#a4bbcc" width="1.0" />
|
||||
<style-line cap="butt" id="water" stroke="#cca4bbcc" width="0.6" />
|
||||
|
||||
<!--###### SYMBOL styles ######-->
|
||||
|
||||
<!-- oneway -->
|
||||
<style-symbol id="oneway" repeat="true" src="assets:symbols/oneway.svg" />
|
||||
|
||||
<!--###### ASSIGNMENT ######-->
|
||||
|
||||
<m e="way" k="natural" v="issea|sea">
|
||||
@ -1073,7 +1078,7 @@
|
||||
<m k="area" v="~|false|no">
|
||||
<m k="highway">
|
||||
<m k="oneway" v="yes|true" zoom-min="16">
|
||||
<symbol repeat="true" src="assets:symbols/oneway.svg" />
|
||||
<symbol use="oneway" />
|
||||
</m>
|
||||
</m>
|
||||
</m>
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2019 devemux86
|
||||
* Copyright 2016-2017 Longri
|
||||
* Copyright 2016 Andrey Novikov
|
||||
* Copyright 2016-2020 Andrey Novikov
|
||||
* Copyright 2018-2019 Gustl22
|
||||
* Copyright 2018 Izumi Kawashima
|
||||
* Copyright 2019 Murray Hughes
|
||||
@ -140,6 +140,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
private final HashMap<String, RenderStyle> mStyles = new HashMap<>(10);
|
||||
|
||||
private final HashMap<String, TextStyle.TextBuilder<?>> mTextStyles = new HashMap<>(10);
|
||||
private final HashMap<String, SymbolStyle.SymbolBuilder<?>> mSymbolStyles = new HashMap<>(10);
|
||||
|
||||
private final AreaBuilder<?> mAreaBuilder = AreaStyle.builder();
|
||||
private final CircleBuilder<?> mCircleBuilder = CircleStyle.builder();
|
||||
@ -196,6 +197,8 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
|
||||
mRulesList.clear();
|
||||
mStyles.clear();
|
||||
mTextStyles.clear();
|
||||
mSymbolStyles.clear();
|
||||
mRuleStack.clear();
|
||||
mElementStack.clear();
|
||||
|
||||
@ -261,6 +264,10 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
checkState(localName, Element.STYLE);
|
||||
handleTextElement(localName, attributes, true, false);
|
||||
|
||||
} else if ("style-symbol".equals(localName)) {
|
||||
checkState(localName, Element.STYLE);
|
||||
handleSymbolElement(localName, attributes, true);
|
||||
|
||||
} else if ("style-area".equals(localName)) {
|
||||
checkState(localName, Element.STYLE);
|
||||
handleAreaElement(localName, attributes, true);
|
||||
@ -298,9 +305,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
|
||||
} else if ("symbol".equals(localName)) {
|
||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||
SymbolStyle symbol = createSymbol(localName, attributes);
|
||||
if (symbol != null && isVisible(symbol))
|
||||
mCurrentRule.addStyle(symbol);
|
||||
handleSymbolElement(localName, attributes, false);
|
||||
|
||||
} else if ("outline".equals(localName)) {
|
||||
checkState(localName, Element.RENDERING_INSTRUCTION);
|
||||
@ -1134,23 +1139,59 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
return b.build();
|
||||
}
|
||||
|
||||
private void handleSymbolElement(String localName, Attributes attributes, boolean isStyle)
|
||||
throws SAXException {
|
||||
|
||||
String style = attributes.getValue("use");
|
||||
SymbolBuilder<?> ps = null;
|
||||
|
||||
if (style != null) {
|
||||
ps = mSymbolStyles.get(style);
|
||||
if (ps == null) {
|
||||
log.debug("missing symbol style: " + style);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SymbolBuilder<?> b = createSymbol(localName, attributes, ps);
|
||||
if (isStyle) {
|
||||
log.debug("put style {}", b.style);
|
||||
mSymbolStyles.put(b.style, SymbolStyle.builder().from(b));
|
||||
} else {
|
||||
SymbolStyle symbol = buildSymbol(b);
|
||||
if (symbol != null && isVisible(symbol))
|
||||
mCurrentRule.addStyle(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new Symbol with the given rendering attributes.
|
||||
*/
|
||||
private SymbolStyle createSymbol(String elementName, Attributes attributes) {
|
||||
SymbolBuilder<?> b = mSymbolBuilder.reset();
|
||||
String src = null;
|
||||
private SymbolBuilder<?> createSymbol(String elementName, Attributes attributes,
|
||||
SymbolBuilder<?> style) {
|
||||
SymbolBuilder<?> b;
|
||||
if (style == null)
|
||||
b = mSymbolBuilder.reset();
|
||||
else
|
||||
b = mSymbolBuilder.from(style);
|
||||
b.themeCallback(mThemeCallback);
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
String name = attributes.getLocalName(i);
|
||||
String value = attributes.getValue(i);
|
||||
|
||||
if ("src".equals(name))
|
||||
src = value;
|
||||
if ("id".equals(name))
|
||||
b.style = value;
|
||||
|
||||
else if ("src".equals(name))
|
||||
b.src(value);
|
||||
|
||||
else if ("cat".equals(name))
|
||||
b.cat(value);
|
||||
|
||||
else if ("use".equals(name))
|
||||
;// ignore
|
||||
|
||||
else if ("symbol-width".equals(name))
|
||||
b.symbolWidth = (int) (Integer.parseInt(value) * mScale);
|
||||
|
||||
@ -1182,20 +1223,24 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
logUnknownAttribute(elementName, name, value, i);
|
||||
}
|
||||
|
||||
validateExists("src", src, elementName);
|
||||
validateExists("src", b.src, elementName);
|
||||
|
||||
String lowSrc = src.toLowerCase(Locale.ENGLISH);
|
||||
return b;
|
||||
}
|
||||
|
||||
private SymbolStyle buildSymbol(SymbolBuilder<?> b) {
|
||||
String lowSrc = b.src.toLowerCase(Locale.ENGLISH);
|
||||
if (lowSrc.endsWith(".png") || lowSrc.endsWith(".svg")) {
|
||||
try {
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
Bitmap bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), b.src, b.symbolWidth, b.symbolHeight, b.symbolPercent);
|
||||
if (bitmap != null)
|
||||
return buildSymbol(b, src, bitmap);
|
||||
return buildSymbol(b, b.src, bitmap);
|
||||
} catch (Exception e) {
|
||||
log.error("{}: {}", src, e.getMessage());
|
||||
log.error("{}: {}", b.src, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return b.texture(getAtlasRegion(src)).build();
|
||||
return b.texture(getAtlasRegion(b.src)).build();
|
||||
}
|
||||
|
||||
SymbolStyle buildSymbol(SymbolBuilder<?> b, String src, Bitmap bitmap) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2019 devemux86
|
||||
* Copyright 2017 Longri
|
||||
* Copyright 2020 Andrey Novikov
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -118,6 +119,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
public Bitmap bitmap;
|
||||
public TextureRegion texture;
|
||||
public int hash;
|
||||
public String src;
|
||||
|
||||
public int symbolWidth;
|
||||
public int symbolHeight;
|
||||
@ -133,6 +135,27 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
public SymbolBuilder() {
|
||||
}
|
||||
|
||||
public T from(SymbolBuilder<?> other) {
|
||||
this.cat = other.cat;
|
||||
|
||||
this.bitmap = other.bitmap;
|
||||
this.texture = other.texture;
|
||||
this.hash = other.hash;
|
||||
this.src = other.src;
|
||||
|
||||
this.symbolWidth = other.symbolWidth;
|
||||
this.symbolHeight = other.symbolHeight;
|
||||
this.symbolPercent = other.symbolPercent;
|
||||
|
||||
this.billboard = other.billboard;
|
||||
this.repeat = other.repeat;
|
||||
this.repeatStart = other.repeatStart;
|
||||
this.repeatGap = other.repeatGap;
|
||||
this.rotate = other.rotate;
|
||||
|
||||
return self();
|
||||
}
|
||||
|
||||
public T set(SymbolStyle symbol) {
|
||||
if (symbol == null)
|
||||
return reset();
|
||||
@ -171,6 +194,11 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
return self();
|
||||
}
|
||||
|
||||
public T src(String src) {
|
||||
this.src = src;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T symbolWidth(int symbolWidth) {
|
||||
this.symbolWidth = symbolWidth;
|
||||
return self();
|
||||
@ -217,6 +245,7 @@ public final class SymbolStyle extends RenderStyle<SymbolStyle> {
|
||||
bitmap = null;
|
||||
texture = null;
|
||||
hash = 0;
|
||||
src = null;
|
||||
|
||||
symbolWidth = 0;
|
||||
symbolHeight = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user