use zoom level mask instead of min < zoom < max
This commit is contained in:
parent
4abec66e39
commit
7f6fe14f60
@ -215,17 +215,14 @@ public class RenderTheme implements IRenderTheme {
|
|||||||
matches.clear();
|
matches.clear();
|
||||||
|
|
||||||
if (element.type == GeometryType.LINE) {
|
if (element.type == GeometryType.LINE) {
|
||||||
for (int i = 0, n = mRules.length; i < n; i++)
|
for (Rule rule : mRules)
|
||||||
mRules[i].matchWay(element.tags,
|
rule.matchWay(element.tags, zoomMask, Closed.NO, matches);
|
||||||
(byte) zoomLevel, Closed.NO, matches);
|
|
||||||
} else if (element.type == GeometryType.POLY) {
|
} else if (element.type == GeometryType.POLY) {
|
||||||
for (int i = 0, n = mRules.length; i < n; i++)
|
for (Rule rule : mRules)
|
||||||
mRules[i].matchWay(element.tags,
|
rule.matchWay(element.tags, zoomMask, Closed.YES, matches);
|
||||||
(byte) zoomLevel, Closed.YES, matches);
|
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0, n = mRules.length; i < n; i++)
|
for (Rule rule : mRules)
|
||||||
mRules[i].matchNode(element.tags,
|
rule.matchNode(element.tags, zoomMask, matches);
|
||||||
(byte) zoomLevel, matches);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = matches.size();
|
int size = matches.size();
|
||||||
@ -309,7 +306,6 @@ public class RenderTheme implements IRenderTheme {
|
|||||||
return ri.list;
|
return ri.list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void complete(List<Rule> rulesList, int levels) {
|
void complete(List<Rule> rulesList, int levels) {
|
||||||
mLevels = levels;
|
mLevels = levels;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* 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
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -15,7 +16,8 @@
|
|||||||
package org.oscim.theme.rule;
|
package org.oscim.theme.rule;
|
||||||
|
|
||||||
public final class Closed {
|
public final class Closed {
|
||||||
public static final int ANY = 0;
|
public static final int NO = 1 << 0;
|
||||||
public static final int NO = 1;
|
public static final int YES = 1 << 1;
|
||||||
public static final int YES = 2;
|
public static final int ANY = NO | YES;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* 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
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -15,7 +16,7 @@
|
|||||||
package org.oscim.theme.rule;
|
package org.oscim.theme.rule;
|
||||||
|
|
||||||
final class Element {
|
final class Element {
|
||||||
public static final int ANY = 0;
|
public static final int NODE = 1 << 0;
|
||||||
public static final int NODE = 1;
|
public static final int WAY = 1 << 1;
|
||||||
public static final int WAY = 2;
|
public static final int ANY = NODE | WAY;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,9 +19,9 @@ import org.oscim.core.Tag;
|
|||||||
class NegativeRule extends Rule {
|
class NegativeRule extends Rule {
|
||||||
final AttributeMatcher mAttributeMatcher;
|
final AttributeMatcher mAttributeMatcher;
|
||||||
|
|
||||||
NegativeRule(int element, int closed, byte zoomMin, byte zoomMax,
|
NegativeRule(int element, int closed, int zoom,
|
||||||
AttributeMatcher attributeMatcher) {
|
AttributeMatcher attributeMatcher) {
|
||||||
super(element, closed, zoomMin, zoomMax);
|
super(element, closed, zoom);
|
||||||
|
|
||||||
mAttributeMatcher = attributeMatcher;
|
mAttributeMatcher = attributeMatcher;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,9 @@ class PositiveRule extends Rule {
|
|||||||
final AttributeMatcher mKeyMatcher;
|
final AttributeMatcher mKeyMatcher;
|
||||||
final AttributeMatcher mValueMatcher;
|
final AttributeMatcher mValueMatcher;
|
||||||
|
|
||||||
PositiveRule(int element, int closed, byte zoomMin, byte zoomMax,
|
PositiveRule(int element, int closed, int zoom,
|
||||||
AttributeMatcher keyMatcher, AttributeMatcher valueMatcher) {
|
AttributeMatcher keyMatcher, AttributeMatcher valueMatcher) {
|
||||||
super(element, closed, zoomMin, zoomMax);
|
super(element, closed, zoom);
|
||||||
|
|
||||||
if (keyMatcher instanceof AnyMatcher)
|
if (keyMatcher instanceof AnyMatcher)
|
||||||
mKeyMatcher = null;
|
mKeyMatcher = null;
|
||||||
|
|||||||
@ -45,18 +45,23 @@ public abstract class Rule {
|
|||||||
List<String> valueList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN
|
List<String> valueList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN
|
||||||
.split(values)));
|
.split(values)));
|
||||||
|
|
||||||
|
int zoom = 0;
|
||||||
|
for (int z = zoomMin; z <= zoomMax && z < 32; z++)
|
||||||
|
zoom |= (1 << z);
|
||||||
|
|
||||||
if (valueList.remove(STRING_NEGATION)) {
|
if (valueList.remove(STRING_NEGATION)) {
|
||||||
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
|
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
|
||||||
false);
|
false);
|
||||||
return new NegativeRule(element, closed, zoomMin, zoomMax,
|
return new NegativeRule(element, closed, zoom,
|
||||||
attributeMatcher);
|
attributeMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (valueList.remove(STRING_EXCLUSIVE)) {
|
if (valueList.remove(STRING_EXCLUSIVE)) {
|
||||||
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
|
AttributeMatcher attributeMatcher = new NegativeMatcher(keyList, valueList,
|
||||||
true);
|
true);
|
||||||
return new NegativeRule(element, closed, zoomMin, zoomMax,
|
return new NegativeRule(element, closed, zoom, attributeMatcher);
|
||||||
attributeMatcher);
|
|
||||||
}
|
}
|
||||||
AttributeMatcher keyMatcher = getKeyMatcher(keyList);
|
AttributeMatcher keyMatcher = getKeyMatcher(keyList);
|
||||||
AttributeMatcher valueMatcher = getValueMatcher(valueList);
|
AttributeMatcher valueMatcher = getValueMatcher(valueList);
|
||||||
@ -64,7 +69,7 @@ public abstract class Rule {
|
|||||||
keyMatcher = RuleOptimizer.optimize(keyMatcher, ruleStack);
|
keyMatcher = RuleOptimizer.optimize(keyMatcher, ruleStack);
|
||||||
valueMatcher = RuleOptimizer.optimize(valueMatcher, ruleStack);
|
valueMatcher = RuleOptimizer.optimize(valueMatcher, ruleStack);
|
||||||
|
|
||||||
return new PositiveRule(element, closed, zoomMin, zoomMax,
|
return new PositiveRule(element, closed, zoom,
|
||||||
keyMatcher, valueMatcher);
|
keyMatcher, valueMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,17 +174,15 @@ public abstract class Rule {
|
|||||||
private Rule[] mSubRuleArray;
|
private Rule[] mSubRuleArray;
|
||||||
private RenderInstruction[] mRenderInstructionArray;
|
private RenderInstruction[] mRenderInstructionArray;
|
||||||
|
|
||||||
final byte mZoomMax;
|
final int mZoom;
|
||||||
final byte mZoomMin;
|
|
||||||
final int mElement;
|
final int mElement;
|
||||||
final int mClosed;
|
final int mClosed;
|
||||||
|
|
||||||
Rule(int element, int closed, byte zoomMin, byte zoomMax) {
|
Rule(int element, int closed, int zoom) {
|
||||||
|
|
||||||
mClosed = closed;
|
mClosed = closed;
|
||||||
mElement = element;
|
mElement = element;
|
||||||
mZoomMin = zoomMin;
|
mZoom = zoom;
|
||||||
mZoomMax = zoomMax;
|
|
||||||
|
|
||||||
mRenderInstructions = new ArrayList<RenderInstruction>(4);
|
mRenderInstructions = new ArrayList<RenderInstruction>(4);
|
||||||
mSubRules = new ArrayList<Rule>(4);
|
mSubRules = new ArrayList<Rule>(4);
|
||||||
@ -197,11 +200,10 @@ public abstract class Rule {
|
|||||||
|
|
||||||
abstract boolean matchesWay(Tag[] tags);
|
abstract boolean matchesWay(Tag[] tags);
|
||||||
|
|
||||||
public void matchNode(Tag[] tags, byte zoomLevel,
|
public void matchNode(Tag[] tags, int zoomLevel,
|
||||||
List<RenderInstruction> matchingList) {
|
List<RenderInstruction> matchingList) {
|
||||||
if ((mElement != Element.WAY)
|
if (((mElement & Element.NODE) != 0)
|
||||||
&& mZoomMin <= zoomLevel
|
&& ((mZoom & zoomLevel) != 0)
|
||||||
&& mZoomMax >= zoomLevel
|
|
||||||
&& matchesNode(tags)) {
|
&& matchesNode(tags)) {
|
||||||
|
|
||||||
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
|
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) {
|
int closed, List<RenderInstruction> matchingList) {
|
||||||
|
|
||||||
if ((mElement != Element.NODE)
|
if (((mElement & Element.WAY) != 0)
|
||||||
&& mZoomMin <= zoomLevel
|
&& ((mZoom & zoomLevel) != 0)
|
||||||
&& mZoomMax >= zoomLevel
|
&& ((mClosed & closed) != 0)
|
||||||
&& (mClosed == closed || mClosed == Closed.ANY)
|
|
||||||
&& (matchesWay(tags))) {
|
&& (matchesWay(tags))) {
|
||||||
|
|
||||||
// add instructions for this rule
|
// add instructions for this rule
|
||||||
for (int i = 0, n = mRenderInstructionArray.length; i < n; i++)
|
for (RenderInstruction ri : mRenderInstructionArray)
|
||||||
matchingList.add(mRenderInstructionArray[i]);
|
matchingList.add(ri);
|
||||||
|
|
||||||
// check subrules
|
// check subrules
|
||||||
for (int i = 0, n = mSubRuleArray.length; i < n; i++)
|
for (Rule subRule : mSubRuleArray)
|
||||||
mSubRuleArray[i].matchWay(tags, zoomLevel, closed,
|
subRule.matchWay(tags, zoomLevel, closed, matchingList);
|
||||||
matchingList);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user