Implement rendering rule search request
This commit is contained in:
parent
cfd20fe776
commit
cfa7138ed0
7 changed files with 458 additions and 126 deletions
|
@ -1,105 +0,0 @@
|
|||
package net.osmand.render;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultRenderingRuleProperties {
|
||||
|
||||
private static final String TEXT_LENGTH = "textLength";
|
||||
private static final String REF = "ref";
|
||||
private static final String TEXT_SHIELD = "textShield";
|
||||
private static final String SHADOW_RADIUS = "shadowRadius";
|
||||
private static final String SHADOW_COLOR = "shadowColor";
|
||||
private static final String SHADER = "shader";
|
||||
private static final String CAP_3 = "cap_3";
|
||||
private static final String CAP_2 = "cap_2";
|
||||
private static final String CAP = "cap";
|
||||
private static final String PATH_EFFECT_3 = "pathEffect_3";
|
||||
private static final String PATH_EFFECT_2 = "pathEffect_2";
|
||||
private static final String PATH_EFFECT = "pathEffect";
|
||||
private static final String STROKE_WIDTH_3 = "strokeWidth_3";
|
||||
private static final String STROKE_WIDTH_2 = "strokeWidth_2";
|
||||
private static final String STROKE_WIDTH = "strokeWidth";
|
||||
private static final String COLOR_3 = "color_3";
|
||||
private static final String COLOR = "color";
|
||||
private static final String COLOR_2 = "color_2";
|
||||
private static final String TEXT_BOLD = "textBold";
|
||||
private static final String TEXT_ORDER = "textOrder";
|
||||
private static final String TEXT_MIN_DISTANCE = "textMinDistance";
|
||||
private static final String TEXT_ON_PATH = "textOnPath";
|
||||
private static final String ICON = "icon";
|
||||
private static final String LAYER = "layer";
|
||||
private static final String ORDER = "order";
|
||||
private static final String ORDER_TYPE = "order_type";
|
||||
public static final String TAG = "tag";
|
||||
public static final String VALUE = "value";
|
||||
public static final String MINZOOM = "minzoom";
|
||||
public static final String MAXZOOM = "maxzoom";
|
||||
public static final String NIGHT_MODE = "nightMode";
|
||||
public static final String TEXT_DY = "textDy";
|
||||
public static final String TEXT_SIZE = "textSize";
|
||||
public static final String TEXT_COLOR = "textColor";
|
||||
public static final String TEXT_HALO_RADIUS = "textHaloRadius";
|
||||
public static final String TEXT_WRAP_WIDTH = "textWrapWidth";
|
||||
|
||||
public static Map<String, RenderingRuleProperty> createDefaultRenderingRuleProperties() {
|
||||
Map<String, RenderingRuleProperty> map = new LinkedHashMap<String, RenderingRuleProperty>();
|
||||
registerRule(map, RenderingRuleProperty.createInputStringProperty(TAG));
|
||||
registerRule(map, RenderingRuleProperty.createInputStringProperty(VALUE));
|
||||
registerRule(map, RenderingRuleProperty.createInputGreaterIntProperty(MINZOOM));
|
||||
registerRule(map, RenderingRuleProperty.createInputLessIntProperty(MAXZOOM));
|
||||
registerRule(map, RenderingRuleProperty.createInputBooleanProperty(NIGHT_MODE));
|
||||
registerRule(map, RenderingRuleProperty.createInputIntProperty(LAYER));
|
||||
|
||||
// order - no sense to make it float
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(ORDER));
|
||||
registerRule(map, RenderingRuleProperty.createInputStringProperty(ORDER_TYPE));
|
||||
|
||||
// text properties
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_WRAP_WIDTH));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_DY));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_HALO_RADIUS));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_SIZE));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_MIN_DISTANCE));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(TEXT_LENGTH));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(REF));
|
||||
|
||||
|
||||
|
||||
registerRule(map, RenderingRuleProperty.createOutputColorProperty(TEXT_COLOR));
|
||||
|
||||
registerRule(map, RenderingRuleProperty.createOutputBooleanProperty(TEXT_BOLD));
|
||||
registerRule(map, RenderingRuleProperty.createOutputBooleanProperty(TEXT_ON_PATH));
|
||||
|
||||
// point
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(ICON));
|
||||
|
||||
// polygon/way
|
||||
registerRule(map, RenderingRuleProperty.createOutputColorProperty(COLOR));
|
||||
registerRule(map, RenderingRuleProperty.createOutputColorProperty(COLOR_2));
|
||||
registerRule(map, RenderingRuleProperty.createOutputColorProperty(COLOR_3));
|
||||
registerRule(map, RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH));
|
||||
registerRule(map, RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH_2));
|
||||
registerRule(map, RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH_3));
|
||||
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT_2));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT_3));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(CAP));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(CAP_2));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(CAP_3));
|
||||
registerRule(map, RenderingRuleProperty.createOutputStringProperty(SHADER));
|
||||
|
||||
registerRule(map, RenderingRuleProperty.createOutputColorProperty(SHADOW_COLOR));
|
||||
registerRule(map, RenderingRuleProperty.createOutputIntProperty(SHADOW_RADIUS));
|
||||
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void registerRule(Map<String, RenderingRuleProperty> map, RenderingRuleProperty p) {
|
||||
map.put(p.getAttrName(), p);
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ public class RenderingRule {
|
|||
Iterator<Entry<String, String>> it = attributes.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> e = it.next();
|
||||
RenderingRuleProperty property = storage.getProperty(e.getKey());
|
||||
RenderingRuleProperty property = storage.PROPS.get(e.getKey());
|
||||
if (property != null) {
|
||||
properties.add(property);
|
||||
|
||||
|
@ -94,6 +94,14 @@ public class RenderingRule {
|
|||
return -1;
|
||||
}
|
||||
|
||||
protected int getIntProp(int ind){
|
||||
return intProperties[ind];
|
||||
}
|
||||
|
||||
protected float getFloatProp(int ind){
|
||||
return floatProperties[ind];
|
||||
}
|
||||
|
||||
public List<RenderingRuleProperty> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.render;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
|
||||
|
@ -22,11 +21,13 @@ public class RenderingRuleProperty {
|
|||
protected final int type;
|
||||
protected final boolean input;
|
||||
protected final String attrName;
|
||||
|
||||
protected int id = -1;
|
||||
|
||||
// use for custom rendering rule properties
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected List<String> possibleValues;
|
||||
protected String[] possibleValues;
|
||||
|
||||
private RenderingRuleProperty(String attrName, int type, boolean input){
|
||||
this.attrName = attrName;
|
||||
|
@ -42,10 +43,33 @@ public class RenderingRuleProperty {
|
|||
return !input;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
if (this.id != -1) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAttrName() {
|
||||
return attrName;
|
||||
}
|
||||
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
protected void setPossibleValues(String[] possibleValues) {
|
||||
this.possibleValues = possibleValues;
|
||||
}
|
||||
|
||||
public boolean isFloat() {
|
||||
return type == FLOAT_TYPE;
|
||||
}
|
||||
|
@ -80,6 +104,12 @@ public class RenderingRuleProperty {
|
|||
return ruleValue == renderingProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "#RenderingRuleProperty " + getAttrName();
|
||||
}
|
||||
|
||||
|
||||
public int parseIntValue(String value){
|
||||
if(type == INT_TYPE){
|
||||
try {
|
||||
|
@ -160,7 +190,7 @@ public class RenderingRuleProperty {
|
|||
return new RenderingRuleProperty(name, INT_TYPE, true) {
|
||||
@Override
|
||||
public boolean accept(int ruleValue, int renderingProperty) {
|
||||
if((type != INT_TYPE || type != STRING_TYPE) && input){
|
||||
if(!isIntParse() || !input){
|
||||
return false;
|
||||
}
|
||||
return ruleValue >= renderingProperty;
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
package net.osmand.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RenderingRuleSearchRequest {
|
||||
|
||||
private final RenderingRulesStorage storage;
|
||||
RenderingRuleProperty[] props;
|
||||
int[] values;
|
||||
float[] fvalues;
|
||||
|
||||
int[] savedValues;
|
||||
float[] savedFvalues;
|
||||
|
||||
private List<RenderingRule> searchedScope = new ArrayList<RenderingRule>();
|
||||
|
||||
public RenderingRuleSearchRequest(RenderingRulesStorage storage) {
|
||||
this.storage = storage;
|
||||
props = storage.PROPS.getPoperties();
|
||||
values = new int[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (!props[i].isColor()) {
|
||||
values[i] = -1;
|
||||
}
|
||||
}
|
||||
fvalues = new float[props.length];
|
||||
saveState();
|
||||
}
|
||||
|
||||
public void setStringFilter(RenderingRuleProperty p, String filter) {
|
||||
assert p.isInputProperty();
|
||||
values[p.getId()] = storage.getDictionaryValue(filter);
|
||||
}
|
||||
|
||||
public void setIntFilter(RenderingRuleProperty p, int filter) {
|
||||
assert p.isInputProperty();
|
||||
values[p.getId()] = filter;
|
||||
}
|
||||
|
||||
public void setBooleanFilter(RenderingRuleProperty p, boolean filter) {
|
||||
assert p.isInputProperty();
|
||||
values[p.getId()] = filter ? RenderingRuleProperty.TRUE_VALUE : RenderingRuleProperty.FALSE_VALUE;
|
||||
}
|
||||
|
||||
public void saveState() {
|
||||
savedValues = new int[values.length];
|
||||
savedFvalues = new float[fvalues.length];
|
||||
System.arraycopy(values, 0, savedValues, 0, values.length);
|
||||
System.arraycopy(fvalues, 0, savedFvalues, 0, fvalues.length);
|
||||
}
|
||||
|
||||
public void clearState() {
|
||||
System.arraycopy(savedValues, 0, values, 0, values.length);
|
||||
System.arraycopy(savedFvalues, 0, fvalues, 0, fvalues.length);
|
||||
}
|
||||
|
||||
public boolean isFound() {
|
||||
return searchedScope.size() > 0;
|
||||
}
|
||||
|
||||
public boolean search(int state) {
|
||||
int tagKey = values[storage.PROPS.R_TAG.getId()];
|
||||
int valueKey = values[storage.PROPS.R_VALUE.getId()];
|
||||
boolean result = search(state, tagKey, valueKey);
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
result = search(state, tagKey, 0);
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
result = search(state, 0, 0);
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean search(int state, int tagKey, int valueKey) {
|
||||
searchedScope.clear();
|
||||
values[storage.PROPS.R_TAG.getId()] = tagKey;
|
||||
values[storage.PROPS.R_VALUE.getId()] = valueKey;
|
||||
RenderingRule accept = storage.getRule(state, tagKey, valueKey);
|
||||
if (accept == null) {
|
||||
return false;
|
||||
}
|
||||
boolean match = visitRule(accept);
|
||||
return match;
|
||||
}
|
||||
|
||||
private boolean visitRule(RenderingRule rule) {
|
||||
boolean empty = true;
|
||||
int ind = 0;
|
||||
for(RenderingRuleProperty rp : rule.getProperties()){
|
||||
if(rp.isInputProperty()){
|
||||
boolean match;
|
||||
if(rp.isFloat()){
|
||||
match = rp.accept(rule.getFloatProp(ind), fvalues[rp.getId()]);
|
||||
} else {
|
||||
match = rp.accept(rule.getIntProp(ind), values[rp.getId()]);
|
||||
}
|
||||
if(!match){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ind ++;
|
||||
}
|
||||
// accept it
|
||||
ind = 0;
|
||||
for(RenderingRuleProperty rp : rule.getProperties()){
|
||||
if(rp.isOutputProperty()){
|
||||
empty = false;
|
||||
if(rp.isFloat()){
|
||||
fvalues[rp.getId()] = rule.getFloatProp(ind);
|
||||
} else {
|
||||
values[rp.getId()] = rule.getIntProp(ind);
|
||||
}
|
||||
}
|
||||
ind++;
|
||||
}
|
||||
if(!empty) {
|
||||
searchedScope.add(rule);
|
||||
}
|
||||
|
||||
for (RenderingRule rr : rule.getIfElseChildren()) {
|
||||
boolean match = visitRule(rr);
|
||||
if (match) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(RenderingRule rr : rule.getIfChildren()){
|
||||
visitRule(rr);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public boolean isSpecified(RenderingRuleProperty property){
|
||||
if(property.isFloat()){
|
||||
return fvalues[property.getId()] != 0;
|
||||
} else {
|
||||
int val = values[property.getId()];
|
||||
if(property.isColor()){
|
||||
return val != 0;
|
||||
} else {
|
||||
return val != -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RenderingRuleProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public String getStringPropertyValue(RenderingRuleProperty property) {
|
||||
int val = values[property.getId()];
|
||||
if(val < 0){
|
||||
return null;
|
||||
}
|
||||
return storage.getStringValue(val);
|
||||
}
|
||||
|
||||
public float getFloatPropertyValue(RenderingRuleProperty property) {
|
||||
return fvalues[property.getId()];
|
||||
}
|
||||
|
||||
public String getColorStringPropertyValue(RenderingRuleProperty property) {
|
||||
return RenderingRuleProperty.colorToString(values[property.getId()]);
|
||||
}
|
||||
|
||||
public int getIntPropertyValue(RenderingRuleProperty property) {
|
||||
return values[property.getId()];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package net.osmand.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RenderingRuleStorageProperties {
|
||||
|
||||
public static final String TEXT_LENGTH = "textLength";
|
||||
public static final String REF = "ref";
|
||||
public static final String TEXT_SHIELD = "textShield";
|
||||
public static final String SHADOW_RADIUS = "shadowRadius";
|
||||
public static final String SHADOW_COLOR = "shadowColor";
|
||||
public static final String SHADER = "shader";
|
||||
public static final String CAP_3 = "cap_3";
|
||||
public static final String CAP_2 = "cap_2";
|
||||
public static final String CAP = "cap";
|
||||
public static final String PATH_EFFECT_3 = "pathEffect_3";
|
||||
public static final String PATH_EFFECT_2 = "pathEffect_2";
|
||||
public static final String PATH_EFFECT = "pathEffect";
|
||||
public static final String STROKE_WIDTH_3 = "strokeWidth_3";
|
||||
public static final String STROKE_WIDTH_2 = "strokeWidth_2";
|
||||
public static final String STROKE_WIDTH = "strokeWidth";
|
||||
public static final String COLOR_3 = "color_3";
|
||||
public static final String COLOR = "color";
|
||||
public static final String COLOR_2 = "color_2";
|
||||
public static final String TEXT_BOLD = "textBold";
|
||||
public static final String TEXT_ORDER = "textOrder";
|
||||
public static final String TEXT_MIN_DISTANCE = "textMinDistance";
|
||||
public static final String TEXT_ON_PATH = "textOnPath";
|
||||
public static final String ICON = "icon";
|
||||
public static final String LAYER = "layer";
|
||||
public static final String ORDER = "order";
|
||||
public static final String ORDER_TYPE = "orderType";
|
||||
public static final String TAG = "tag";
|
||||
public static final String VALUE = "value";
|
||||
public static final String MINZOOM = "minzoom";
|
||||
public static final String MAXZOOM = "maxzoom";
|
||||
public static final String NIGHT_MODE = "nightMode";
|
||||
public static final String TEXT_DY = "textDy";
|
||||
public static final String TEXT_SIZE = "textSize";
|
||||
public static final String TEXT_COLOR = "textColor";
|
||||
public static final String TEXT_HALO_RADIUS = "textHaloRadius";
|
||||
public static final String TEXT_WRAP_WIDTH = "textWrapWidth";
|
||||
|
||||
public RenderingRuleProperty R_TEXT_LENGTH;
|
||||
public RenderingRuleProperty R_REF;
|
||||
public RenderingRuleProperty R_TEXT_SHIELD;
|
||||
public RenderingRuleProperty R_SHADOW_RADIUS;
|
||||
public RenderingRuleProperty R_SHADOW_COLOR;
|
||||
public RenderingRuleProperty R_SHADER;
|
||||
public RenderingRuleProperty R_CAP_3;
|
||||
public RenderingRuleProperty R_CAP_2;
|
||||
public RenderingRuleProperty R_CAP;
|
||||
public RenderingRuleProperty R_PATH_EFFECT_3;
|
||||
public RenderingRuleProperty R_PATH_EFFECT_2;
|
||||
public RenderingRuleProperty R_PATH_EFFECT;
|
||||
public RenderingRuleProperty R_STROKE_WIDTH_3;
|
||||
public RenderingRuleProperty R_STROKE_WIDTH_2;
|
||||
public RenderingRuleProperty R_STROKE_WIDTH;
|
||||
public RenderingRuleProperty R_COLOR_3;
|
||||
public RenderingRuleProperty R_COLOR;
|
||||
public RenderingRuleProperty R_COLOR_2;
|
||||
public RenderingRuleProperty R_TEXT_BOLD;
|
||||
public RenderingRuleProperty R_TEXT_ORDER;
|
||||
public RenderingRuleProperty R_TEXT_MIN_DISTANCE;
|
||||
public RenderingRuleProperty R_TEXT_ON_PATH;
|
||||
public RenderingRuleProperty R_ICON;
|
||||
public RenderingRuleProperty R_LAYER;
|
||||
public RenderingRuleProperty R_ORDER;
|
||||
public RenderingRuleProperty R_ORDER_TYPE;
|
||||
public RenderingRuleProperty R_TAG;
|
||||
public RenderingRuleProperty R_VALUE;
|
||||
public RenderingRuleProperty R_MINZOOM;
|
||||
public RenderingRuleProperty R_MAXZOOM;
|
||||
public RenderingRuleProperty R_NIGHT_MODE;
|
||||
public RenderingRuleProperty R_TEXT_DY;
|
||||
public RenderingRuleProperty R_TEXT_SIZE;
|
||||
public RenderingRuleProperty R_TEXT_COLOR;
|
||||
public RenderingRuleProperty R_TEXT_HALO_RADIUS;
|
||||
public RenderingRuleProperty R_TEXT_WRAP_WIDTH;
|
||||
|
||||
final Map<String, RenderingRuleProperty> properties = new LinkedHashMap<String, RenderingRuleProperty>();
|
||||
final java.util.List<RenderingRuleProperty> rules = new ArrayList<RenderingRuleProperty>();
|
||||
|
||||
public RenderingRuleStorageProperties() {
|
||||
createDefaultRenderingRuleProperties();
|
||||
}
|
||||
|
||||
public void createDefaultRenderingRuleProperties() {
|
||||
R_TAG = registerRule(RenderingRuleProperty.createInputStringProperty(TAG));
|
||||
R_VALUE = registerRule(RenderingRuleProperty.createInputStringProperty(VALUE));
|
||||
R_MINZOOM = registerRule(RenderingRuleProperty.createInputGreaterIntProperty(MINZOOM));
|
||||
R_MAXZOOM = registerRule(RenderingRuleProperty.createInputLessIntProperty(MAXZOOM));
|
||||
R_NIGHT_MODE = registerRule(RenderingRuleProperty.createInputBooleanProperty(NIGHT_MODE));
|
||||
R_LAYER = registerRule(RenderingRuleProperty.createInputIntProperty(LAYER));
|
||||
R_ORDER_TYPE = registerRule(RenderingRuleProperty.createInputStringProperty(ORDER_TYPE));
|
||||
|
||||
// order - no sense to make it float
|
||||
R_ORDER = registerRule(RenderingRuleProperty.createOutputIntProperty(ORDER));
|
||||
|
||||
|
||||
// text properties
|
||||
R_TEXT_WRAP_WIDTH = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_WRAP_WIDTH));
|
||||
R_TEXT_DY = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_DY));
|
||||
R_TEXT_HALO_RADIUS = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_HALO_RADIUS));
|
||||
R_TEXT_SIZE = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_SIZE));
|
||||
R_TEXT_ORDER = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER));
|
||||
R_TEXT_MIN_DISTANCE = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_MIN_DISTANCE));
|
||||
R_TEXT_LENGTH = registerRule(RenderingRuleProperty.createOutputIntProperty(TEXT_LENGTH));
|
||||
R_TEXT_SHIELD = registerRule(RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD));
|
||||
R_REF = registerRule(RenderingRuleProperty.createOutputStringProperty(REF));
|
||||
|
||||
R_TEXT_COLOR = registerRule(RenderingRuleProperty.createOutputColorProperty(TEXT_COLOR));
|
||||
|
||||
R_TEXT_BOLD = registerRule(RenderingRuleProperty.createOutputBooleanProperty(TEXT_BOLD));
|
||||
R_TEXT_ON_PATH = registerRule(RenderingRuleProperty.createOutputBooleanProperty(TEXT_ON_PATH));
|
||||
|
||||
// point
|
||||
R_ICON = registerRule(RenderingRuleProperty.createOutputStringProperty(ICON));
|
||||
|
||||
// polygon/way
|
||||
R_COLOR = registerRule(RenderingRuleProperty.createOutputColorProperty(COLOR));
|
||||
R_COLOR_2 = registerRule(RenderingRuleProperty.createOutputColorProperty(COLOR_2));
|
||||
R_COLOR_3 = registerRule(RenderingRuleProperty.createOutputColorProperty(COLOR_3));
|
||||
R_STROKE_WIDTH = registerRule(RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH));
|
||||
R_STROKE_WIDTH_2 = registerRule(RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH_2));
|
||||
R_STROKE_WIDTH_3 = registerRule(RenderingRuleProperty.createOutputFloatProperty(STROKE_WIDTH_3));
|
||||
|
||||
R_PATH_EFFECT = registerRule(RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT));
|
||||
R_PATH_EFFECT_2 = registerRule(RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT_2));
|
||||
R_PATH_EFFECT_3 = registerRule(RenderingRuleProperty.createOutputStringProperty(PATH_EFFECT_3));
|
||||
R_CAP = registerRule(RenderingRuleProperty.createOutputStringProperty(CAP));
|
||||
R_CAP_2 = registerRule(RenderingRuleProperty.createOutputStringProperty(CAP_2));
|
||||
R_CAP_3 = registerRule(RenderingRuleProperty.createOutputStringProperty(CAP_3));
|
||||
R_SHADER = registerRule(RenderingRuleProperty.createOutputStringProperty(SHADER));
|
||||
|
||||
R_SHADOW_COLOR = registerRule(RenderingRuleProperty.createOutputColorProperty(SHADOW_COLOR));
|
||||
R_SHADOW_RADIUS = registerRule(RenderingRuleProperty.createOutputIntProperty(SHADOW_RADIUS));
|
||||
}
|
||||
|
||||
public RenderingRuleProperty get(String name) {
|
||||
return properties.get(name);
|
||||
}
|
||||
|
||||
public RenderingRuleProperty[] getPoperties() {
|
||||
return rules.toArray(new RenderingRuleProperty[rules.size()]);
|
||||
|
||||
}
|
||||
|
||||
public RenderingRuleProperty registerRule(RenderingRuleProperty p) {
|
||||
properties.put(p.getAttrName(), p);
|
||||
p.setId(rules.size());
|
||||
rules.add(p);
|
||||
return p;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@ public class RenderingRulesStorage {
|
|||
|
||||
private final static Log log = LogUtil.getLog(RenderingRulesStorage.class);
|
||||
|
||||
|
||||
public final static int POINT_RULES = 1;
|
||||
public final static int LINE_RULES = 2;
|
||||
public final static int POLYGON_RULES = 3;
|
||||
|
@ -39,10 +38,11 @@ public class RenderingRulesStorage {
|
|||
|
||||
List<String> dictionary = new ArrayList<String>();
|
||||
Map<String, Integer> dictionaryMap = new LinkedHashMap<String, Integer>();
|
||||
final Map<String, RenderingRuleProperty> properties;
|
||||
|
||||
public final RenderingRuleStorageProperties PROPS = new RenderingRuleStorageProperties();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private TIntObjectHashMap<RenderingRule>[] tagValueGlobalRules = new TIntObjectHashMap[LENGTH_RULES];
|
||||
protected TIntObjectHashMap<RenderingRule>[] tagValueGlobalRules = new TIntObjectHashMap[LENGTH_RULES];
|
||||
|
||||
private int bgColor = 0;
|
||||
private int bgNightColor = 0;
|
||||
|
@ -53,7 +53,6 @@ public class RenderingRulesStorage {
|
|||
public RenderingRulesStorage(){
|
||||
// register empty string as 0
|
||||
getDictionaryValue("");
|
||||
properties = DefaultRenderingRuleProperties.createDefaultRenderingRuleProperties();
|
||||
}
|
||||
|
||||
public int getDictionaryValue(String val) {
|
||||
|
@ -71,9 +70,6 @@ public class RenderingRulesStorage {
|
|||
return dictionary.get(i);
|
||||
}
|
||||
|
||||
public RenderingRuleProperty getProperty(String name){
|
||||
return properties.get(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return renderingName;
|
||||
|
@ -111,11 +107,11 @@ public class RenderingRulesStorage {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void registerGlobalRule(RenderingRule rr, int state, Map<String, String> attrsMap) throws SAXException {
|
||||
int tag = rr.getIntPropertyValue(DefaultRenderingRuleProperties.TAG);
|
||||
int tag = rr.getIntPropertyValue(RenderingRuleStorageProperties.TAG);
|
||||
if(tag == -1){
|
||||
throw new SAXException("Attribute tag should be specified for root filter " + attrsMap.toString());
|
||||
}
|
||||
int value = rr.getIntPropertyValue(DefaultRenderingRuleProperties.VALUE);
|
||||
int value = rr.getIntPropertyValue(RenderingRuleStorageProperties.VALUE);
|
||||
if(value == -1){
|
||||
throw new SAXException("Attribute tag should be specified for root filter " + attrsMap.toString());
|
||||
}
|
||||
|
@ -123,8 +119,12 @@ public class RenderingRulesStorage {
|
|||
RenderingRule toInsert = rr;
|
||||
RenderingRule previous = tagValueGlobalRules[state].get(key);
|
||||
if(previous != null){
|
||||
toInsert = new RenderingRule(Collections.EMPTY_MAP, RenderingRulesStorage.this);
|
||||
toInsert.addIfElseChildren(previous);
|
||||
if(previous.getProperties().size() != 0){
|
||||
toInsert = new RenderingRule(Collections.EMPTY_MAP, RenderingRulesStorage.this);
|
||||
toInsert.addIfElseChildren(previous);
|
||||
} else {
|
||||
toInsert = previous;
|
||||
}
|
||||
toInsert.addIfElseChildren(rr);
|
||||
}
|
||||
tagValueGlobalRules[state].put(key, toInsert);
|
||||
|
@ -195,6 +195,7 @@ public class RenderingRulesStorage {
|
|||
stack.push(renderingRule);
|
||||
} else if("groupFilter".equals(name)){ //$NON-NLS-1$
|
||||
attrsMap.clear();
|
||||
parseAttributes(attributes, attrsMap);
|
||||
RenderingRule renderingRule = new RenderingRule(attrsMap, RenderingRulesStorage.this);
|
||||
if (stack.size() > 0 && stack.peek() instanceof GroupRules) {
|
||||
GroupRules parent = ((GroupRules) stack.peek());
|
||||
|
@ -229,6 +230,23 @@ public class RenderingRulesStorage {
|
|||
} else if("polygon".equals(name)){ //$NON-NLS-1$
|
||||
state = POLYGON_RULES;
|
||||
stateChanged = true;
|
||||
} else if("renderingProperty".equals(name)){ //$NON-NLS-1$
|
||||
String attr = attributes.getValue("attr");
|
||||
RenderingRuleProperty prop;
|
||||
String type = attributes.getValue("type");
|
||||
if("boolean".equalsIgnoreCase(type)){
|
||||
prop = RenderingRuleProperty.createInputBooleanProperty(attr);
|
||||
} else if("string".equalsIgnoreCase(type)){
|
||||
prop = RenderingRuleProperty.createInputStringProperty(attr);
|
||||
} else {
|
||||
prop = RenderingRuleProperty.createInputIntProperty(attr);
|
||||
}
|
||||
prop.setDescription(attributes.getValue("description"));
|
||||
prop.setName(attributes.getValue("name"));
|
||||
if(attributes.getValue("possibleValues") != null){
|
||||
prop.setPossibleValues(attributes.getValue("possibleValues").split(","));
|
||||
}
|
||||
PROPS.registerRule(prop);
|
||||
} else if("renderingStyle".equals(name)){ //$NON-NLS-1$
|
||||
String dc = attributes.getValue("defaultColor");
|
||||
int defaultColor = 0;
|
||||
|
@ -294,8 +312,15 @@ public class RenderingRulesStorage {
|
|||
return getStringValue(tagValueKey >> SHIFT_TAG_VAL);
|
||||
}
|
||||
|
||||
protected RenderingRule getRule(int state, int itag, int ivalue){
|
||||
if(tagValueGlobalRules[state] != null){
|
||||
return tagValueGlobalRules[state].get((itag << SHIFT_TAG_VAL) | ivalue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void printDebug(int state, PrintStream out){
|
||||
|
||||
public void printDebug(int state, PrintStream out){
|
||||
for(int key : tagValueGlobalRules[state].keys()) {
|
||||
RenderingRule rr = tagValueGlobalRules[state].get(key);
|
||||
out.print("\n\n"+getTagString(key) + " : " + getValueString(key));
|
||||
|
@ -303,7 +328,7 @@ public class RenderingRulesStorage {
|
|||
}
|
||||
}
|
||||
|
||||
private void printRenderingRule(String indent, RenderingRule rr, PrintStream out){
|
||||
private static void printRenderingRule(String indent, RenderingRule rr, PrintStream out){
|
||||
indent += " ";
|
||||
out.print("\n"+indent);
|
||||
for(RenderingRuleProperty p : rr.getProperties()){
|
||||
|
@ -324,9 +349,46 @@ public class RenderingRulesStorage {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws SAXException, IOException {
|
||||
RenderingRulesStorage storage = new RenderingRulesStorage();
|
||||
storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("new_default.render.xml"));
|
||||
storage.printDebug(TEXT_RULES, System.out);
|
||||
// storage.printDebug(TEXT_RULES, System.out);
|
||||
|
||||
RenderingRuleSearchRequest searchRequest = new RenderingRuleSearchRequest(storage);
|
||||
searchRequest.setStringFilter(storage.PROPS.R_TAG, "highway");
|
||||
searchRequest.setStringFilter(storage.PROPS.R_VALUE, "motorway");
|
||||
searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1);
|
||||
searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 14);
|
||||
searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 14);
|
||||
searchRequest.setStringFilter(storage.PROPS.R_ORDER_TYPE, "line");
|
||||
searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true);
|
||||
// searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true);
|
||||
|
||||
searchRequest.search(LINE_RULES);
|
||||
printResult(searchRequest, System.out);
|
||||
}
|
||||
|
||||
private static void printResult(RenderingRuleSearchRequest searchRequest, PrintStream out) {
|
||||
if(searchRequest.isFound()){
|
||||
out.print(" Found : ");
|
||||
for (RenderingRuleProperty rp : searchRequest.getProperties()) {
|
||||
if(rp.isOutputProperty() && searchRequest.isSpecified(rp)){
|
||||
out.print(" " + rp.getAttrName() + "= ");
|
||||
if(rp.isString()){
|
||||
out.print("\"" + searchRequest.getStringPropertyValue(rp) + "\"");
|
||||
} else if(rp.isFloat()){
|
||||
out.print(searchRequest.getFloatPropertyValue(rp));
|
||||
} else if(rp.isColor()){
|
||||
out.print(searchRequest.getColorStringPropertyValue(rp));
|
||||
} else if(rp.isIntParse()){
|
||||
out.print(searchRequest.getIntPropertyValue(rp));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.println("Not found");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,10 @@
|
|||
laundry, copyshop
|
||||
-->
|
||||
|
||||
<!-- types : string, int, boolean; possibleValues comma separated possible values for int/string -->
|
||||
<renderingProperty attr="hmRendered" name="All-Purpose Renderer" description="All-Purpose Renderer by Hardy"
|
||||
type="boolean" possibleValues=""/>
|
||||
|
||||
<!-- input exact layer, orderType check tag, value -->
|
||||
<order>
|
||||
<!-- point has order 128 -->
|
||||
|
@ -70,7 +74,7 @@
|
|||
|
||||
<filter tag="power" value="" order="4" />
|
||||
|
||||
<filter tag="natural" value="coastline" order="0.5" />
|
||||
<filter tag="natural" value="coastline" order="1" />
|
||||
<filter tag="natural" value="" order="1" />
|
||||
</group>
|
||||
|
||||
|
@ -116,6 +120,7 @@
|
|||
<filter tag="highway" value="bridleway" order="35" />
|
||||
</group>
|
||||
|
||||
<filter tag="" value="" order="128" orderType="point"/>
|
||||
<filter tag="" value="" layer="-1" order="1" orderType="polygon"/>
|
||||
<filter tag="" value="" layer="1" order="64" orderType="polygon"/>
|
||||
<filter tag="" value="" order="1" orderType="polygon"/>
|
||||
|
@ -124,7 +129,6 @@
|
|||
<filter tag="" value="" layer="1" order="67" orderType="line"/>
|
||||
<filter tag="" value="" order="11" orderType="line"/>
|
||||
|
||||
<filter tag="" value="" order="128" orderType="point"/>
|
||||
</order>
|
||||
|
||||
|
||||
|
@ -1124,7 +1128,6 @@
|
|||
|
||||
|
||||
<filter tag="highway" value="bridleway">
|
||||
<filter layer="1" minzoom="14" maxzoom="14" color="#00ff00" strokeWidth="1" pathEffect="2_2" />
|
||||
<filter layer="1" minzoom="15" color="#88ffffff" strokeWidth="2" color_2="#00ff00" strokeWidth_2="2" pathEffect_2="2_2" />
|
||||
<filter minzoom="12" maxzoom="12" hmRendered="true" color="#00ff00" strokeWidth="0.5" pathEffect="2_2" />
|
||||
<filter minzoom="13" color="#00ff00" strokeWidth="1" pathEffect="2_2" />
|
||||
|
|
Loading…
Reference in a new issue