Tag transform improvements (#678)
This commit is contained in:
parent
4162d9b488
commit
207993a6e2
@ -303,10 +303,10 @@
|
||||
|
||||
<!-- tag-transform element -->
|
||||
<xs:complexType name="tag-transform">
|
||||
<xs:attribute name="match-k" type="xs:string" use="required" />
|
||||
<xs:attribute name="match-v" type="xs:string" use="optional" />
|
||||
<xs:attribute name="output-k" type="xs:string" use="required" />
|
||||
<xs:attribute name="output-v" type="xs:string" use="optional" />
|
||||
<xs:attribute name="k" type="xs:string" use="required" />
|
||||
<xs:attribute name="v" type="xs:string" use="optional" />
|
||||
<xs:attribute name="k-lib" type="xs:string" use="required" />
|
||||
<xs:attribute name="v-lib" type="xs:string" use="optional" />
|
||||
</xs:complexType>
|
||||
|
||||
<!-- rendertheme element -->
|
||||
|
@ -252,12 +252,22 @@ public class RenderTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformKey(String key) {
|
||||
public String transformBackwardKey(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformTag(Tag tag) {
|
||||
public String transformForwardKey(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformBackwardTag(Tag tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformForwardTag(Tag tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -48,12 +48,22 @@ public class DebugTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformKey(String key) {
|
||||
public String transformBackwardKey(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformTag(Tag tag) {
|
||||
public String transformForwardKey(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformBackwardTag(Tag tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformForwardTag(Tag tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -3,16 +3,16 @@
|
||||
version="1" xmlns="http://opensciencemap.org/rendertheme"
|
||||
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
|
||||
|
||||
<!--<tag-transform match-k="building" match-v="yes" output-k="kind" output-v="building" />-->
|
||||
<!--<tag-transform match-k="building:part" match-v="yes" output-k="kind" output-v="building_part" />-->
|
||||
<tag-transform match-k="ref" output-k="root_id" />
|
||||
<!--<tag-transform k="kind" v="building" k-lib="building" v-lib="yes" />-->
|
||||
<!--<tag-transform k="kind" v="building_part" k-lib="building:part" v-lib="yes" />-->
|
||||
<tag-transform k="root_id" k-lib="ref" />
|
||||
|
||||
<tag-transform match-k="roof:colour" output-k="roof_color" />
|
||||
<tag-transform match-k="roof:direction" output-k="roof_direction" />
|
||||
<tag-transform match-k="roof:height" output-k="roof_height" />
|
||||
<tag-transform match-k="roof:material" output-k="roof_material" />
|
||||
<tag-transform match-k="roof:orientation" output-k="roof_orientation" />
|
||||
<tag-transform match-k="roof:shape" output-k="roof_shape" />
|
||||
<tag-transform k="roof_color" k-lib="roof:colour" />
|
||||
<tag-transform k="roof_direction" k-lib="roof:direction" />
|
||||
<tag-transform k="roof_height" k-lib="roof:height" />
|
||||
<tag-transform k="roof_material" k-lib="roof:material" />
|
||||
<tag-transform k="roof_orientation" k-lib="roof:orientation" />
|
||||
<tag-transform k="roof_shape" k-lib="roof:shape" />
|
||||
|
||||
<!-- base style for fixed width lines -->
|
||||
<style-line cap="butt" fix="true" id="fix" width="1.0" />
|
||||
|
@ -3,10 +3,10 @@
|
||||
version="1" xmlns="http://opensciencemap.org/rendertheme"
|
||||
xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
|
||||
|
||||
<tag-transform match-k="height" output-k="render_height" />
|
||||
<tag-transform match-k="min_height" output-k="render_min_height" />
|
||||
<!--<tag-transform match-k="building" match-v="yes" output-k="layer" output-v="building" />-->
|
||||
<!--<tag-transform match-k="building:part" match-v="yes" output-k="layer" output-v="building:part" />-->
|
||||
<tag-transform k="render_height" k-lib="height" />
|
||||
<tag-transform k="render_min_height" k-lib="min_height" />
|
||||
<!--<tag-transform k="layer" v="building" k-lib="building" v-lib="yes" />-->
|
||||
<!--<tag-transform k="layer" v="building:part" k-lib="building:part" v-lib="yes" />-->
|
||||
|
||||
<!--###### TEXT styles ######-->
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
* Copyright 2016 Andrey Novikov
|
||||
* Copyright 2017-2018 Gustl22
|
||||
* Copyright 2017-2019 Gustl22
|
||||
* Copyright 2018 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@ -66,7 +66,7 @@ public class MapElement extends GeometryBuffer {
|
||||
* @return height in meters, if present
|
||||
*/
|
||||
public Float getHeight(IRenderTheme theme) {
|
||||
String res = theme != null ? theme.transformKey(Tag.KEY_HEIGHT) : Tag.KEY_HEIGHT;
|
||||
String res = theme != null ? theme.transformBackwardKey(Tag.KEY_HEIGHT) : Tag.KEY_HEIGHT;
|
||||
String v = tags.getValue(res != null ? res : Tag.KEY_HEIGHT);
|
||||
if (v != null)
|
||||
return Float.parseFloat(v);
|
||||
@ -77,7 +77,7 @@ public class MapElement extends GeometryBuffer {
|
||||
* @return minimum height in meters, if present
|
||||
*/
|
||||
public Float getMinHeight(IRenderTheme theme) {
|
||||
String res = theme != null ? theme.transformKey(Tag.KEY_MIN_HEIGHT) : Tag.KEY_MIN_HEIGHT;
|
||||
String res = theme != null ? theme.transformBackwardKey(Tag.KEY_MIN_HEIGHT) : Tag.KEY_MIN_HEIGHT;
|
||||
String v = tags.getValue(res != null ? res : Tag.KEY_MIN_HEIGHT);
|
||||
if (v != null)
|
||||
return Float.parseFloat(v);
|
||||
|
@ -273,7 +273,7 @@ public class BuildingLayer extends Layer implements TileLoaderThemeHook, ZoomLim
|
||||
protected String getKeyOrDefault(String key) {
|
||||
if (mTileLayer.getTheme() == null)
|
||||
return key;
|
||||
String res = mTileLayer.getTheme().transformKey(key);
|
||||
String res = mTileLayer.getTheme().transformBackwardKey(key);
|
||||
return res != null ? res : key;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2017 devemux86
|
||||
* Copyright 2018 Gustl22
|
||||
* Copyright 2018-2019 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -66,14 +66,35 @@ public interface IRenderTheme {
|
||||
void scaleTextSize(float scaleFactor);
|
||||
|
||||
/**
|
||||
* @return the transformed tag key of this RenderTheme.
|
||||
* Transform internal key to tile source key.
|
||||
* e.g. for lazy fetched tag values via tile source key.
|
||||
* Use when tile source and internal keys have 1-1 relation.
|
||||
*
|
||||
* @return the backwards transformed tag key.
|
||||
*/
|
||||
String transformKey(String key);
|
||||
String transformBackwardKey(String key);
|
||||
|
||||
/**
|
||||
* @return the transformed tag of this RenderTheme.
|
||||
* Transform tile source key to internal key.
|
||||
*
|
||||
* @return the forward transformed tag key.
|
||||
*/
|
||||
Tag transformTag(Tag tag);
|
||||
String transformForwardKey(String key);
|
||||
|
||||
/**
|
||||
* Transform internal tag to tile source tag.
|
||||
* Use when tile source and internal tags have 1-1 relation.
|
||||
*
|
||||
* @return the backwards transformed tag.
|
||||
*/
|
||||
Tag transformBackwardTag(Tag tag);
|
||||
|
||||
/**
|
||||
* Transform tile source tag to internal tag.
|
||||
*
|
||||
* @return the forward transformed tag.
|
||||
*/
|
||||
Tag transformForwardTag(Tag tag);
|
||||
|
||||
class ThemeException extends IllegalArgumentException {
|
||||
public ThemeException(String string) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2017 Longri
|
||||
* Copyright 2017 devemux86
|
||||
* Copyright 2018 Gustl22
|
||||
* Copyright 2018-2019 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -26,6 +26,7 @@ import org.oscim.theme.rule.Rule;
|
||||
import org.oscim.theme.rule.Rule.Element;
|
||||
import org.oscim.theme.rule.Rule.RuleVisitor;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.utils.ArrayUtils;
|
||||
import org.oscim.utils.LRUCache;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -47,8 +48,8 @@ public class RenderTheme implements IRenderTheme {
|
||||
private final Rule[] mRules;
|
||||
private final boolean mMapsforgeTheme;
|
||||
|
||||
private final Map<String, String> mTransformKeyMap;
|
||||
private final Map<Tag, Tag> mTransformTagMap;
|
||||
private final Map<String, String> mTransformBackwardKeyMap, mTransformForwardKeyMap;
|
||||
private final Map<Tag, Tag> mTransformBackwardTagMap, mTransformForwardTagMap;
|
||||
|
||||
class RenderStyleCache {
|
||||
final int matchType;
|
||||
@ -105,8 +106,10 @@ public class RenderTheme implements IRenderTheme {
|
||||
mRules = rules;
|
||||
mMapsforgeTheme = mapsforgeTheme;
|
||||
|
||||
mTransformKeyMap = transformKeyMap;
|
||||
mTransformTagMap = transformTagMap;
|
||||
mTransformForwardKeyMap = transformKeyMap;
|
||||
mTransformBackwardKeyMap = ArrayUtils.swap(transformKeyMap);
|
||||
mTransformForwardTagMap = transformTagMap;
|
||||
mTransformBackwardTagMap = ArrayUtils.swap(transformTagMap);
|
||||
|
||||
mStyleCache = new RenderStyleCache[3];
|
||||
mStyleCache[0] = new RenderStyleCache(Element.NODE);
|
||||
@ -292,16 +295,30 @@ public class RenderTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformKey(String key) {
|
||||
if (mTransformKeyMap != null)
|
||||
return mTransformKeyMap.get(key);
|
||||
public String transformBackwardKey(String key) {
|
||||
if (mTransformBackwardKeyMap != null)
|
||||
return mTransformBackwardKeyMap.get(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformTag(Tag tag) {
|
||||
if (mTransformTagMap != null)
|
||||
return mTransformTagMap.get(tag);
|
||||
public String transformForwardKey(String key) {
|
||||
if (mTransformForwardKeyMap != null)
|
||||
return mTransformForwardKeyMap.get(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformBackwardTag(Tag tag) {
|
||||
if (mTransformBackwardTagMap != null)
|
||||
return mTransformBackwardTagMap.get(tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag transformForwardTag(Tag tag) {
|
||||
if (mTransformForwardTagMap != null)
|
||||
return mTransformForwardTagMap.get(tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Copyright 2016-2019 devemux86
|
||||
* Copyright 2016-2017 Longri
|
||||
* Copyright 2016 Andrey Novikov
|
||||
* Copyright 2018 Gustl22
|
||||
* Copyright 2018-2019 Gustl22
|
||||
* Copyright 2018 Izumi Kawashima
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@ -1268,40 +1268,40 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
}
|
||||
|
||||
private void tagTransform(String localName, Attributes attributes) {
|
||||
String matchKey, matchValue, outputKey, outputValue;
|
||||
matchKey = matchValue = outputKey = outputValue = null;
|
||||
String k, v, libK, libV;
|
||||
k = v = libK = libV = null;
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
String name = attributes.getLocalName(i);
|
||||
String value = attributes.getValue(i);
|
||||
|
||||
switch (name) {
|
||||
case "match-k":
|
||||
matchKey = value;
|
||||
case "k":
|
||||
k = value;
|
||||
break;
|
||||
case "match-v":
|
||||
matchValue = value;
|
||||
case "v":
|
||||
v = value;
|
||||
break;
|
||||
case "output-k":
|
||||
outputKey = value;
|
||||
case "k-lib":
|
||||
libK = value;
|
||||
break;
|
||||
case "output-v":
|
||||
outputValue = value;
|
||||
case "v-lib":
|
||||
libV = value;
|
||||
break;
|
||||
default:
|
||||
logUnknownAttribute(localName, name, value, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (matchKey == null || matchKey.isEmpty() || outputKey == null || outputKey.isEmpty()) {
|
||||
if (k == null || k.isEmpty() || libK == null || libK.isEmpty()) {
|
||||
log.debug("empty key in element " + localName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchValue == null && outputValue == null) {
|
||||
mTransformKeyMap.put(matchKey, outputKey);
|
||||
if (v == null && libV == null) {
|
||||
mTransformKeyMap.put(k, libK);
|
||||
} else {
|
||||
mTransformTagMap.put(new Tag(matchKey, matchValue), new Tag(outputKey, outputValue));
|
||||
mTransformTagMap.put(new Tag(k, v), new Tag(libK, libV));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.oscim.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ArrayUtils {
|
||||
|
||||
public static <T> void reverse(T[] data) {
|
||||
@ -189,6 +192,18 @@ public class ArrayUtils {
|
||||
return neg ? -val : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Map with swapped keys and values
|
||||
*/
|
||||
public static <K, V> Map<V, K> swap(Map<K, V> map) {
|
||||
if (map == null)
|
||||
return null;
|
||||
Map<V, K> swap = new HashMap<>();
|
||||
for (Map.Entry<K, V> entry : map.entrySet())
|
||||
swap.put(entry.getValue(), entry.getKey());
|
||||
return swap;
|
||||
}
|
||||
|
||||
public static boolean withinRange(float[] vec, float min, float max) {
|
||||
for (int i = 0, n = vec.length; i < n; i++) {
|
||||
float v = vec[i];
|
||||
|
Loading…
x
Reference in New Issue
Block a user