Fix rendering

This commit is contained in:
Victor Shcherb 2012-03-22 00:30:48 +01:00
parent 3dca79c49f
commit 9651d8e136
10 changed files with 235 additions and 131 deletions

View file

@ -15,7 +15,8 @@ public class ToDoConstants {
// Routing index !!
// Identify coastline areas and pure ocean areas !!!
// Extract & remove the code with multipolygons
// render different texts
// Render : different texts support render.xml
// Render : support additional tags in render.xml
// FIXME layer and renderer 1) FIXME Layer 2 2) FIXME oneway 1

View file

@ -3,6 +3,7 @@ package net.osmand.binary;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.osm.MapRenderingTypes;
public class BinaryMapDataObject {
protected int[] coordinates = null;
@ -10,6 +11,7 @@ public class BinaryMapDataObject {
protected boolean area = false;
protected int[] types = null;
protected int[] additionalTypes = null;
protected int objectType = MapRenderingTypes.POINT_TYPE;
protected TIntObjectHashMap<String> objectNames = null;
protected long id = 0;
@ -35,11 +37,12 @@ public class BinaryMapDataObject {
return name;
}
public String getRef(){
if(mapIndex.refEncodingType != -1 && objectNames != null) {
return objectNames.get(mapIndex.refEncodingType);
}
return null;
public int getObjectType() {
return objectType;
}
public void setObjectType(int objectType) {
this.objectType = objectType;
}
public TIntObjectHashMap<String> getObjectNames() {
@ -54,6 +57,35 @@ public class BinaryMapDataObject {
return types;
}
public boolean containsType(int cachedType) {
if(cachedType != -1) {
for(int i=0; i<types.length; i++){
if(types[i] == cachedType) {
return true;
}
}
}
return false;
}
public boolean containsAdditionalType(int cachedType) {
if (cachedType != -1) {
for (int i = 0; i < additionalTypes.length; i++) {
if (additionalTypes[i] == cachedType) {
return true;
}
}
}
return false;
}
public String getNameByType(int type) {
if(type != -1 && objectNames != null) {
return objectNames.get(type);
}
return null;
}
public int[] getAdditionalTypes() {
return additionalTypes;
}
@ -62,15 +94,20 @@ public class BinaryMapDataObject {
return area;
}
public boolean isCycle(){
if(coordinates == null || coordinates.length < 2) {
return false;
}
return coordinates[0] == coordinates[coordinates.length - 2] &&
coordinates[1] == coordinates[coordinates.length - 1];
}
public void setArea(boolean area) {
this.area = area;
}
public TagValuePair getTagValue(int indType){
if(mapIndex == null){
return null;
}
return mapIndex.decodeType(types[indType]);
throw new UnsupportedOperationException("This functions is deprecated and should be deleted");
}
public long getId() {
@ -86,6 +123,20 @@ public class BinaryMapDataObject {
}
public int getSimpleLayer(){
if(mapIndex != null) {
for (int i = 0; i < additionalTypes.length; i++) {
if (mapIndex.positiveLayers.contains(additionalTypes[i])) {
return 1;
} else if (mapIndex.negativeLayers.contains(additionalTypes[i])) {
return -1;
}
}
}
return 0;
}
public MapIndex getMapIndex() {
return mapIndex;
}

View file

@ -3,6 +3,7 @@ package net.osmand.binary;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.set.hash.TIntHashSet;
import java.io.File;
import java.io.IOException;
@ -564,22 +565,6 @@ public class BinaryMapIndexReader {
}
}
private void initMapEncodingRule(MapIndex index, int type, int id, String tag, String val) {
if(!index.encodingRules.containsKey(tag)){
index.encodingRules.put(tag, new LinkedHashMap<String, Integer>());
}
index.encodingRules.get(tag).put(val, id);
if("name".equals(tag)){
index.nameEncodingType = id;
} else if("natural".equals(tag) && "coastline".equals(val)){
index.coastlineEncodingType = id;
} else if("ref".equals(tag)){
index.refEncodingType = id;
}
if(!index.decodingRules.containsKey(id)){
index.decodingRules.put(id, new TagValuePair(tag, val, type));
}
}
private void readMapEncodingRule(MapIndex index, int id) throws IOException {
int type = 0;
@ -590,7 +575,7 @@ public class BinaryMapIndexReader {
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
initMapEncodingRule(index, type, id, tags, val);
index.initMapEncodingRule(type, id, tags, val);
return;
case MapEncodingRule.VALUE_FIELD_NUMBER :
val = codedIS.readString().intern();
@ -1329,6 +1314,10 @@ public class BinaryMapIndexReader {
public int nameEncodingType = 0;
public int refEncodingType = -1;
public int coastlineEncodingType = -1;
public int onewayAttribute = -1;
public int onewayReverseAttribute = -1;
public TIntHashSet positiveLayers = new TIntHashSet(2);
public TIntHashSet negativeLayers = new TIntHashSet(2);
public List<MapRoot> getRoots() {
return roots;
@ -1338,6 +1327,36 @@ public class BinaryMapIndexReader {
return decodingRules.get(type);
}
private void initMapEncodingRule(int type, int id, String tag, String val) {
if(!encodingRules.containsKey(tag)){
encodingRules.put(tag, new LinkedHashMap<String, Integer>());
}
encodingRules.get(tag).put(val, id);
if(!decodingRules.containsKey(id)){
decodingRules.put(id, new TagValuePair(tag, val, type));
}
if("name".equals(tag)){
nameEncodingType = id;
} else if("natural".equals(tag) && "coastline".equals(val)){
coastlineEncodingType = id;
} else if("oneway".equals(tag) && "yes".equals(val)){
onewayAttribute = id;
} else if("oneway".equals(tag) && "-1".equals(val)){
onewayReverseAttribute = id;
} else if("ref".equals(tag)){
refEncodingType = id;
} else if("layer".equals(tag)){
if(val != null && !val.equals("0") && val.length() > 0) {
if(val.startsWith("-")) {
negativeLayers.add(id);
} else {
positiveLayers.add(id);
}
}
}
}
}
public static class TagValuePair {

View file

@ -39,7 +39,10 @@ public class RenderingRuleStorageProperties {
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 OBJECT_TYPE = "objectType";
public static final String POINT = "point";
public static final String AREA = "area";
public static final String CYCLE = "cycle";
public static final String TAG = "tag";
public static final String VALUE = "value";
public static final String MINZOOM = "minzoom";
@ -82,7 +85,10 @@ public class RenderingRuleStorageProperties {
public RenderingRuleProperty R_ICON;
public RenderingRuleProperty R_LAYER;
public RenderingRuleProperty R_ORDER;
public RenderingRuleProperty R_ORDER_TYPE;
public RenderingRuleProperty R_POINT;
public RenderingRuleProperty R_AREA;
public RenderingRuleProperty R_CYCLE;
public RenderingRuleProperty R_OBJECT_TYPE;
public RenderingRuleProperty R_TAG;
public RenderingRuleProperty R_VALUE;
public RenderingRuleProperty R_MINZOOM;
@ -121,11 +127,13 @@ public class RenderingRuleStorageProperties {
R_MAXZOOM = registerRuleInternal(RenderingRuleProperty.createInputLessIntProperty(MAXZOOM));
R_NIGHT_MODE = registerRuleInternal(RenderingRuleProperty.createInputBooleanProperty(NIGHT_MODE));
R_LAYER = registerRuleInternal(RenderingRuleProperty.createInputIntProperty(LAYER));
R_ORDER_TYPE = registerRuleInternal(RenderingRuleProperty.createInputIntProperty(ORDER_TYPE));
R_POINT = registerRuleInternal(RenderingRuleProperty.createInputBooleanProperty(POINT));
R_AREA = registerRuleInternal(RenderingRuleProperty.createInputBooleanProperty(AREA));
R_CYCLE = registerRuleInternal(RenderingRuleProperty.createInputBooleanProperty(CYCLE));
R_TEXT_LENGTH = registerRuleInternal(RenderingRuleProperty.createInputIntProperty(TEXT_LENGTH));
R_REF = registerRuleInternal(RenderingRuleProperty.createInputBooleanProperty(REF));
R_ATTR_INT_VALUE = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ATTR_INT_VALUE));
R_ATTR_BOOL_VALUE = registerRuleInternal(RenderingRuleProperty.createOutputBooleanProperty(ATTR_BOOL_VALUE));
R_ATTR_COLOR_VALUE = registerRuleInternal(RenderingRuleProperty.createOutputColorProperty(ATTR_COLOR_VALUE));
@ -133,6 +141,7 @@ public class RenderingRuleStorageProperties {
// order - no sense to make it float
R_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ORDER));
R_OBJECT_TYPE = registerRuleInternal(RenderingRuleProperty.createInputIntProperty(OBJECT_TYPE));
R_SHADOW_LEVEL = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(SHADOW_LEVEL));
// text properties

View file

@ -453,7 +453,6 @@ public class RenderingRulesStorage {
searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1);
searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 15);
searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 15);
searchRequest.setIntFilter(storage.PROPS.R_ORDER_TYPE, 2);
// searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true);
// searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true);

View file

@ -75,13 +75,57 @@
-->
<!-- input exact layer, orderType check tag, value -->
<!-- point = 1, line = 2, polygon = 3 -->
<!-- input layer check tag, value, point, cycle, area -->
<!-- output ! objectType point = 1, line = 2, polygon = 3 and order -->
<order>
<!-- point has order 128 -->
<filter tag="" value="" order="128" orderType="1"/>
<filter tag="" value="" point="true" order="128" objectType="1"/>
<!-- default polygon -->
<filter cycle="true" layer="-1" tag="" value="" order="1" objectType="3"/>
<filter area="true" layer="-1" tag="" value="" order="1" objectType="3"/>
<!-- default line -->
<filter layer="-1" tag="" value="" order="10" objectType="2"/>
<filter tag="" value="" order="11" objectType="2"/>
<group orderType="3">
<filter layer="-1" tag="building" value="" order="1"/>
<filter tag="building" value="" order="64"/>
<group orderType="2">
<filter tag="railway" value="" order="58"/>
<filter tag="highway" value="road" order="35"/>
<filter tag="highway" value="unclassified" order="35"/>
<filter tag="highway" value="residential" order="35"/>
<filter tag="highway" value="service" order="35"/>
<filter tag="highway" value="pedestrian" order="35"/>
<filter tag="highway" value="footway" order="35"/>
<filter tag="highway" value="" order="35"/>
<filter tag="aeroway" value="" order="35"/>
<filter tag="power" value="" order="7"/>
<filter tag="amenity" value="" order="7"/>
<filter tag="tourism" value="" order="7"/>
<filter tag="military" value="" order="7"/>
<filter tag="leisure" value="" order="7"/>
<filter tag="waterway" value="" order="6"/>
<filter tag="landuse" value="reservoir" order="5"/>
<filter tag="landuse" value="water" order="5"/>
<filter tag="landuse" value="" order="1"/>
<filter tag="natural" value="water" order="5"/>
<filter tag="natural" value="bay" order="5"/>
<filter tag="natural" value="coastline" order="1"/>
<filter tag="natural" value="" order="1"/>
<groupFilter>
<filter cycle="true"/>
<filter area="true"/>
</groupFilter>
</group>
<group objectType="2">
<!-- Over buildings -->
<filter tag="aerialway" value="" order="68"/>
<filter tag="power" value="" order="68"/>
@ -189,46 +233,9 @@
<filter tag="admin_level" value="0" order="0"/>
<filter tag="admin_level" value="1" order="0"/>
<filter layer="-1" tag="" value="" order="10"/>
<filter tag="" value="" order="11"/>
</group>
<group orderType="3">
<filter layer="-1" tag="building" value="" order="1"/>
<filter tag="building" value="" order="64"/>
<filter tag="railway" value="" order="58"/>
<filter tag="highway" value="road" order="35"/>
<filter tag="highway" value="unclassified" order="35"/>
<filter tag="highway" value="residential" order="35"/>
<filter tag="highway" value="service" order="35"/>
<filter tag="highway" value="pedestrian" order="35"/>
<filter tag="highway" value="footway" order="35"/>
<filter tag="highway" value="" order="35"/>
<filter tag="aeroway" value="" order="35"/>
<filter tag="power" value="" order="7"/>
<filter tag="amenity" value="" order="7"/>
<filter tag="tourism" value="" order="7"/>
<filter tag="military" value="" order="7"/>
<filter tag="leisure" value="" order="7"/>
<filter tag="waterway" value="" order="6"/>
<filter tag="landuse" value="reservoir" order="5"/>
<filter tag="landuse" value="water" order="5"/>
<filter tag="landuse" value="" order="1"/>
<filter tag="natural" value="water" order="5"/>
<filter tag="natural" value="bay" order="5"/>
<filter tag="natural" value="coastline" order="1"/>
<filter tag="natural" value="" order="1"/>
<filter layer="-1" tag="" value="" order="1"/>
<filter tag="" value="" order="1"/>
</group>
</order>

View file

@ -698,8 +698,9 @@ public class BinaryRoutePlanner {
startLat+"", startLon+"", endLat+"", endLon+""));
for (RouteSegmentResult res : result) {
String name = res.object.getName();
if(res.object.getRef() != null) {
name += " " + res.object.getRef();
String ref = res.object.getNameByType(res.object.getMapIndex().refEncodingType);
if(ref != null) {
name += " " + ref;
}
// (res.object.getId() >> 1)
System.out.println(MessageFormat.format("\t<segment id=\"{0}\" start=\"{1}\" end=\"{2}\" name=\"{3}\"/>",

View file

@ -374,18 +374,14 @@ public class MapRenderRepositories {
}
count++;
for (int i = 0; i < r.getTypes().length; i++) {
if (r.getTypes()[i] == r.getMapIndex().coastlineEncodingType) {
// multy polygon r.getId() >> 3
TagValuePair pair = r.getMapIndex().decodeType(r.getTypes()[i]);
if (pair != null) {
pair = new TagValuePair(pair.tag, pair.value, r.getTypes()[i]);
if (!multiPolygons.containsKey(pair)) {
multiPolygons.put(pair, new ArrayList<BinaryMapDataObject>());
}
multiPolygons.get(pair).add(r);
}
// TODO refactor !
if(r.containsType(r.getMapIndex().coastlineEncodingType)) {
TagValuePair pair = r.getMapIndex().decodeType(r.getMapIndex().coastlineEncodingType);
pair = new TagValuePair(pair.tag, pair.value, 0);
if (!multiPolygons.containsKey(pair)) {
multiPolygons.put(pair, new ArrayList<BinaryMapDataObject>());
}
multiPolygons.get(pair).add(r);
}
if (checkWhetherInterrupted()) {
return false;

View file

@ -36,7 +36,6 @@ import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.PointF;
import android.graphics.Xfermode;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Shader;
@ -382,42 +381,37 @@ public class OsmandRenderer {
BinaryMapDataObject o = objects.get(i);
int sh = i << 8;
if (o instanceof MultyPolygon) {
int layer = ((MultyPolygon) o).getLayer();
render.setTagValueZoomLayer(((MultyPolygon) o).getTag(), ((MultyPolygon) o).getValue(), rc.zoom, layer);
render.setIntFilter(render.ALL.R_ORDER_TYPE, MapRenderingTypes.POLYGON_TYPE);
if(render.search(RenderingRulesStorage.ORDER_RULES)) {
int order = render.getIntPropertyValue(render.ALL.R_ORDER);
put(orderMap, order, sh, init);
if(render.isSpecified(render.ALL.R_SHADOW_LEVEL)){
rc.shadowLevelMin = Math.min(rc.shadowLevelMin, order);
rc.shadowLevelMax = Math.max(rc.shadowLevelMax, order);
render.clearValue(render.ALL.R_SHADOW_LEVEL);
}
}
//FIXME Multipolygon : 1
// int layer = ((MultyPolygon) o).getLayer();
// render.setTagValueZoomLayer(((MultyPolygon) o).getTag(), ((MultyPolygon) o).getValue(), rc.zoom, layer);
// render.setIntFilter(render.ALL.R_ORDER_TYPE, MapRenderingTypes.POLYGON_TYPE);
// if(render.search(RenderingRulesStorage.ORDER_RULES)) {
// int order = render.getIntPropertyValue(render.ALL.R_ORDER);
// put(orderMap, order, sh, init);
// if(render.isSpecified(render.ALL.R_SHADOW_LEVEL)){
// rc.shadowLevelMin = Math.min(rc.shadowLevelMin, order);
// rc.shadowLevelMax = Math.max(rc.shadowLevelMax, order);
// render.clearValue(render.ALL.R_SHADOW_LEVEL);
// }
// }
} else {
for (int j = 0; j < o.getTypes().length; j++) {
// put(orderMap, BinaryMapDataObject.getOrder(o.getTypes()[j]), sh + j, init);
int wholeType = o.getTypes()[j];
int mask = MapRenderingTypes.POINT_TYPE;
if(o.getPointsLength() > 1) {
if(o.isArea()){
mask = MapRenderingTypes.POLYGON_TYPE;
} else {
mask = MapRenderingTypes.POLYLINE_TYPE;
}
}
int layer = 0;
if (mask != MapRenderingTypes.POINT_TYPE) {
// FIXME Layer
// layer = MapRenderingTypes.getNegativeWayLayer(wholeType);
if (o.getPointsLength() > 1) {
layer = o.getSimpleLayer();
}
TagValuePair pair = o.getMapIndex().decodeType(wholeType);
if (pair != null) {
render.setTagValueZoomLayer(pair.tag, pair.value, rc.zoom, layer);
render.setIntFilter(render.ALL.R_ORDER_TYPE, mask);
render.setBooleanFilter(render.ALL.R_AREA, o.isArea());
render.setBooleanFilter(render.ALL.R_POINT, o.getPointsLength() == 1);
render.setBooleanFilter(render.ALL.R_CYCLE, o.isCycle());
if (render.search(RenderingRulesStorage.ORDER_RULES)) {
o.setObjectType(render.getIntPropertyValue(render.ALL.R_OBJECT_TYPE));
int order = render.getIntPropertyValue(render.ALL.R_ORDER);
put(orderMap, order, sh + j, init);
if (render.isSpecified(render.ALL.R_SHADOW_LEVEL)) {
@ -450,19 +444,18 @@ public class OsmandRenderer {
boolean renderText, boolean drawOnlyShadow) {
rc.allObjects++;
if (obj instanceof MultyPolygon) {
// TODO
if(!drawOnlyShadow){
drawMultiPolygon(obj, render, canvas, rc);
}
} else {
int mainType = obj.getTypes()[l];
TagValuePair pair = obj.getMapIndex().decodeType(mainType);
if (obj.getPointsLength() == 1 && !drawOnlyShadow) {
int type = obj.getObjectType();
TagValuePair pair = obj.getMapIndex().decodeType(obj.getTypes()[l]);
if (type == MapRenderingTypes.POINT_TYPE && !drawOnlyShadow) {
drawPoint(obj, render, canvas, rc, pair, renderText);
} else if (!obj.isArea()) {
// FIXME Layer
// int layer = MapRenderingTypes.getNegativeWayLayer(mainType);
drawPolyline(obj, render, canvas, rc, pair, 0, drawOnlyShadow);
} else if (obj.isArea() && !drawOnlyShadow) {
} else if (type == MapRenderingTypes.POLYLINE_TYPE) {
drawPolyline(obj, render, canvas, rc, pair, obj.getSimpleLayer(), drawOnlyShadow);
} else if (type == MapRenderingTypes.POLYGON_TYPE && !drawOnlyShadow) {
drawPolygon(obj, render, canvas, rc, pair);
}
}
@ -738,11 +731,14 @@ public class OsmandRenderer {
if(!rendered || !updatePaint(render, paint, 0, false, rc)){
return;
}
boolean oneway = false;
//FIXME oneway
// if(rc.zoom >= 16 && "highway".equals(pair.tag) && MapRenderingTypes.isOneWayWay(obj.getHighwayAttributes())){ //$NON-NLS-1$
// oneway = true;
// }
int oneway = 0;
if(rc.zoom >= 16 && "highway".equals(pair.tag) ){ //$NON-NLS-1$
if(obj.containsAdditionalType(obj.getMapIndex().onewayAttribute)) {
oneway = 1;
} else if(obj.containsAdditionalType(obj.getMapIndex().onewayReverseAttribute)){
oneway = -1;
}
}
rc.visible++;
@ -789,8 +785,8 @@ public class OsmandRenderer {
}
}
if(oneway && !drawOnlyShadow){
Paint[] paints = getOneWayPaints();
if(oneway != 0 && !drawOnlyShadow){
Paint[] paints = oneway == -1? getReverseOneWayPaints() : getOneWayPaints();
for (int i = 0; i < paints.length; i++) {
canvas.drawPath(path, paints[i]);
}
@ -803,6 +799,7 @@ public class OsmandRenderer {
private static Paint[] oneWay = null;
private static Paint[] reverseOneWay = null;
private static Paint oneWayPaint(){
Paint oneWay = new Paint();
oneWay.setStyle(Style.STROKE);
@ -811,6 +808,33 @@ public class OsmandRenderer {
return oneWay;
}
public static Paint[] getReverseOneWayPaints(){
if(reverseOneWay == null){
PathEffect arrowDashEffect1 = new DashPathEffect(new float[] { 0, 12, 10, 152 }, 0);
PathEffect arrowDashEffect2 = new DashPathEffect(new float[] { 0, 13, 9, 152 }, 1);
PathEffect arrowDashEffect3 = new DashPathEffect(new float[] { 0, 14, 2, 148 }, 1);
PathEffect arrowDashEffect4 = new DashPathEffect(new float[] { 0, 15, 1, 148 }, 1);
reverseOneWay = new Paint[4];
reverseOneWay[0] = oneWayPaint();
reverseOneWay[0].setStrokeWidth(1);
reverseOneWay[0].setPathEffect(arrowDashEffect1);
reverseOneWay[1] = oneWayPaint();
reverseOneWay[1].setStrokeWidth(2);
reverseOneWay[1].setPathEffect(arrowDashEffect2);
reverseOneWay[2] = oneWayPaint();
reverseOneWay[2].setStrokeWidth(3);
reverseOneWay[2].setPathEffect(arrowDashEffect3);
reverseOneWay[3] = oneWayPaint();
reverseOneWay[3].setStrokeWidth(4);
reverseOneWay[3].setPathEffect(arrowDashEffect4);
}
return oneWay;
}
public static Paint[] getOneWayPaints(){
if(oneWay == null){
PathEffect arrowDashEffect1 = new DashPathEffect(new float[] { 0, 12, 10, 152 }, 0);

View file

@ -326,11 +326,8 @@ public class TextRenderer {
public void renderText(BinaryMapDataObject obj, RenderingRuleSearchRequest render, RenderingContext rc, TagValuePair pair,
float xMid, float yMid, Path path, PointF[] points) {
// TODO other render text
String ref = null;
if(obj.getMapIndex().refEncodingType >= 0 ) {
ref = obj.getObjectNames().get(obj.getMapIndex().refEncodingType);
}
String name = obj.getObjectNames().get(obj.getMapIndex().nameEncodingType);
String ref = obj.getNameByType(obj.getMapIndex().refEncodingType);
String name = obj.getNameByType(obj.getMapIndex().nameEncodingType);
if(ref != null && ref.trim().length() > 0){
createTextDrawInfo(render, rc, pair, xMid, yMid, path, points, ref, true);
}