use zoom level mask instead of min < zoom < max

This commit is contained in:
Hannes Janetzek 2013-05-28 08:15:09 +02:00
parent 4abec66e39
commit 7f6fe14f60
6 changed files with 47 additions and 48 deletions

View File

@ -215,28 +215,25 @@ public class RenderTheme implements IRenderTheme {
matches.clear();
if (element.type == GeometryType.LINE) {
for (int i = 0, n = mRules.length; i < n; i++)
mRules[i].matchWay(element.tags,
(byte) zoomLevel, Closed.NO, matches);
for (Rule rule : mRules)
rule.matchWay(element.tags, zoomMask, Closed.NO, matches);
} else if (element.type == GeometryType.POLY) {
for (int i = 0, n = mRules.length; i < n; i++)
mRules[i].matchWay(element.tags,
(byte) zoomLevel, Closed.YES, matches);
for (Rule rule : mRules)
rule.matchWay(element.tags, zoomMask, Closed.YES, matches);
} else {
for (int i = 0, n = mRules.length; i < n; i++)
mRules[i].matchNode(element.tags,
(byte) zoomLevel, matches);
for (Rule rule : mRules)
rule.matchNode(element.tags, zoomMask, matches);
}
int size = matches.size();
if (size > 1){
for (int i = 0; i < size-1; i++){
if (size > 1) {
for (int i = 0; i < size - 1; i++) {
RenderInstruction r = matches.get(i);
for (int j = i + 1; j < size; j++){
if (matches.get(j) == r){
for (int j = i + 1; j < size; j++) {
if (matches.get(j) == r) {
Log.d(TAG, "fix duplicate instruction! "
+ Arrays.deepToString(element.tags)
+ ":"+ zoomLevel);
+ ":" + zoomLevel);
matches.remove(j--);
size--;
}
@ -309,7 +306,6 @@ public class RenderTheme implements IRenderTheme {
return ri.list;
}
void complete(List<Rule> rulesList, int levels) {
mLevels = levels;

View File

@ -1,5 +1,6 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -15,7 +16,8 @@
package org.oscim.theme.rule;
public final class Closed {
public static final int ANY = 0;
public static final int NO = 1;
public static final int YES = 2;
public static final int NO = 1 << 0;
public static final int YES = 1 << 1;
public static final int ANY = NO | YES;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -15,7 +16,7 @@
package org.oscim.theme.rule;
final class Element {
public static final int ANY = 0;
public static final int NODE = 1;
public static final int WAY = 2;
public static final int NODE = 1 << 0;
public static final int WAY = 1 << 1;
public static final int ANY = NODE | WAY;
}

View File

@ -19,9 +19,9 @@ import org.oscim.core.Tag;
class NegativeRule extends Rule {
final AttributeMatcher mAttributeMatcher;
NegativeRule(int element, int closed, byte zoomMin, byte zoomMax,
NegativeRule(int element, int closed, int zoom,
AttributeMatcher attributeMatcher) {
super(element, closed, zoomMin, zoomMax);
super(element, closed, zoom);
mAttributeMatcher = attributeMatcher;
}

View File

@ -20,9 +20,9 @@ class PositiveRule extends Rule {
final AttributeMatcher mKeyMatcher;
final AttributeMatcher mValueMatcher;
PositiveRule(int element, int closed, byte zoomMin, byte zoomMax,
PositiveRule(int element, int closed, int zoom,
AttributeMatcher keyMatcher, AttributeMatcher valueMatcher) {
super(element, closed, zoomMin, zoomMax);
super(element, closed, zoom);
if (keyMatcher instanceof AnyMatcher)
mKeyMatcher = null;

View File

@ -45,18 +45,23 @@ public abstract class Rule {
List<String> valueList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN
.split(values)));
int zoom = 0;
for (int z = zoomMin; z <= zoomMax && z < 32; z++)
zoom |= (1 << z);
if (valueList.remove(STRING_NEGATION)) {
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
false);
return new NegativeRule(element, closed, zoomMin, zoomMax,
return new NegativeRule(element, closed, zoom,
attributeMatcher);
}
if (valueList.remove(STRING_EXCLUSIVE)) {
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
true);
return new NegativeRule(element, closed, zoomMin, zoomMax,
attributeMatcher);
return new NegativeRule(element, closed, zoom, attributeMatcher);
}
AttributeMatcher keyMatcher = getKeyMatcher(keyList);
AttributeMatcher valueMatcher = getValueMatcher(valueList);
@ -64,7 +69,7 @@ public abstract class Rule {
keyMatcher = RuleOptimizer.optimize(keyMatcher, ruleStack);
valueMatcher = RuleOptimizer.optimize(valueMatcher, ruleStack);
return new PositiveRule(element, closed, zoomMin, zoomMax,
return new PositiveRule(element, closed, zoom,
keyMatcher, valueMatcher);
}
@ -169,17 +174,15 @@ public abstract class Rule {
private Rule[] mSubRuleArray;
private RenderInstruction[] mRenderInstructionArray;
final byte mZoomMax;
final byte mZoomMin;
final int mZoom;
final int mElement;
final int mClosed;
Rule(int element, int closed, byte zoomMin, byte zoomMax) {
Rule(int element, int closed, int zoom) {
mClosed = closed;
mElement = element;
mZoomMin = zoomMin;
mZoomMax = zoomMax;
mZoom = zoom;
mRenderInstructions = new ArrayList<RenderInstruction>(4);
mSubRules = new ArrayList<Rule>(4);
@ -197,11 +200,10 @@ public abstract class Rule {
abstract boolean matchesWay(Tag[] tags);
public void matchNode(Tag[] tags, byte zoomLevel,
public void matchNode(Tag[] tags, int zoomLevel,
List<RenderInstruction> matchingList) {
if ((mElement != Element.WAY)
&& mZoomMin <= zoomLevel
&& mZoomMax >= zoomLevel
if (((mElement & Element.NODE) != 0)
&& ((mZoom & zoomLevel) != 0)
&& matchesNode(tags)) {
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
@ -213,23 +215,21 @@ public abstract class Rule {
}
}
public void matchWay(Tag[] tags, byte zoomLevel,
public void matchWay(Tag[] tags, int zoomLevel,
int closed, List<RenderInstruction> matchingList) {
if ((mElement != Element.NODE)
&& mZoomMin <= zoomLevel
&& mZoomMax >= zoomLevel
&& (mClosed == closed || mClosed == Closed.ANY)
if (((mElement & Element.WAY) != 0)
&& ((mZoom & zoomLevel) != 0)
&& ((mClosed & closed) != 0)
&& (matchesWay(tags))) {
// add instructions for this rule
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
matchingList.add(mRenderInstructionArray[i]);
for (RenderInstruction ri : mRenderInstructionArray)
matchingList.add(ri);
// check subrules
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
mSubRuleArray[i].matchWay(tags, zoomLevel, closed,
matchingList);
for (Rule subRule : mSubRuleArray)
subRule.matchWay(tags, zoomLevel, closed, matchingList);
}
}