Fix labelx, labely

This commit is contained in:
Victor Shcherb 2020-01-28 18:48:43 +01:00
parent 8c8f83c5d0
commit 6f48ca6cbb
2 changed files with 46 additions and 66 deletions

View file

@ -19,7 +19,8 @@ public class BinaryMapDataObject {
protected int[] types = null;
protected int[] additionalTypes = null;
protected int objectType = RenderingRulesStorage.POINT_RULES;
protected int[] labelCoordinates = null;
protected int labelX;
protected int labelY;
protected TIntObjectHashMap<String> objectNames = null;
protected TIntArrayList namesOrder = null;
@ -34,7 +35,7 @@ public class BinaryMapDataObject {
public BinaryMapDataObject(long id, int[] coordinates, int[][] polygonInnerCoordinates, int objectType, boolean area,
int[] types, int[] additionalTypes, int[] labelCoordinates){
int[] types, int[] additionalTypes, int labelX, int labelY){
this.polygonInnerCoordinates = polygonInnerCoordinates;
this.coordinates = coordinates;
this.additionalTypes = additionalTypes;
@ -42,7 +43,8 @@ public class BinaryMapDataObject {
this.id = id;
this.objectType = objectType;
this.area = area;
this.labelCoordinates = labelCoordinates;
this.labelX = labelX;
this.labelY = labelY;
}
protected void setCoordinates(int[] coordinates) {
@ -204,79 +206,80 @@ public class BinaryMapDataObject {
&& this.id == thatObj.id
&& this.area == thatObj.area
&& compareCoordinates(this.coordinates, thatObj.coordinates, coordinatesPrecision) ) {
if(mapIndex == null) {
if (mapIndex == null) {
throw new IllegalStateException("Illegal binary object: " + id);
}
if(thatObj.mapIndex == null) {
if (thatObj.mapIndex == null) {
throw new IllegalStateException("Illegal binary object: " + thatObj.id);
}
boolean equals = true;
if(equals) {
if(polygonInnerCoordinates == null || thatObj.polygonInnerCoordinates == null) {
equals = polygonInnerCoordinates == thatObj.polygonInnerCoordinates;
} else if(polygonInnerCoordinates.length != thatObj.polygonInnerCoordinates.length){
if (equals) {
if (polygonInnerCoordinates == null || thatObj.polygonInnerCoordinates == null) {
equals = polygonInnerCoordinates == thatObj.polygonInnerCoordinates;
} else if (polygonInnerCoordinates.length != thatObj.polygonInnerCoordinates.length) {
equals = false;
} else {
for(int i = 0; i < polygonInnerCoordinates.length && equals; i++) {
if(polygonInnerCoordinates[i] == null || thatObj.polygonInnerCoordinates[i] == null) {
equals = polygonInnerCoordinates[i] == thatObj.polygonInnerCoordinates[i];
} else if(polygonInnerCoordinates[i].length != thatObj.polygonInnerCoordinates[i].length){
for (int i = 0; i < polygonInnerCoordinates.length && equals; i++) {
if (polygonInnerCoordinates[i] == null || thatObj.polygonInnerCoordinates[i] == null) {
equals = polygonInnerCoordinates[i] == thatObj.polygonInnerCoordinates[i];
} else if (polygonInnerCoordinates[i].length != thatObj.polygonInnerCoordinates[i].length) {
equals = false;
} else {
equals = compareCoordinates(polygonInnerCoordinates[i], thatObj.polygonInnerCoordinates[i], coordinatesPrecision);
equals = compareCoordinates(polygonInnerCoordinates[i], thatObj.polygonInnerCoordinates[i],
coordinatesPrecision);
}
}
}
}
if(equals) {
if(types == null || thatObj.types == null) {
equals = types == thatObj.types;
} else if(types.length != thatObj.types.length){
if (equals) {
if (types == null || thatObj.types == null) {
equals = types == thatObj.types;
} else if (types.length != thatObj.types.length) {
equals = false;
} else {
for(int i = 0; i < types.length && equals; i++) {
for (int i = 0; i < types.length && equals; i++) {
TagValuePair o = mapIndex.decodeType(types[i]);
TagValuePair s = thatObj.mapIndex.decodeType(thatObj.types[i]);
equals = o.equals(s) && equals;
}
}
}
if(equals) {
if(additionalTypes == null || thatObj.additionalTypes == null) {
equals = additionalTypes == thatObj.additionalTypes;
} else if(additionalTypes.length != thatObj.additionalTypes.length){
if (equals) {
if (additionalTypes == null || thatObj.additionalTypes == null) {
equals = additionalTypes == thatObj.additionalTypes;
} else if (additionalTypes.length != thatObj.additionalTypes.length) {
equals = false;
} else {
for(int i = 0; i < additionalTypes.length && equals; i++) {
for (int i = 0; i < additionalTypes.length && equals; i++) {
TagValuePair o = mapIndex.decodeType(additionalTypes[i]);
TagValuePair s = thatObj.mapIndex.decodeType(thatObj.additionalTypes[i]);
equals = o.equals(s);
}
}
}
if(equals) {
if(namesOrder == null || thatObj.namesOrder == null) {
equals = namesOrder == thatObj.namesOrder;
} else if(namesOrder.size() != thatObj.namesOrder.size()){
if (equals) {
if (namesOrder == null || thatObj.namesOrder == null) {
equals = namesOrder == thatObj.namesOrder;
} else if (namesOrder.size() != thatObj.namesOrder.size()) {
equals = false;
} else {
for(int i = 0; i < namesOrder.size() && equals; i++) {
for (int i = 0; i < namesOrder.size() && equals; i++) {
TagValuePair o = mapIndex.decodeType(namesOrder.get(i));
TagValuePair s = thatObj.mapIndex.decodeType(thatObj.namesOrder.get(i));
equals = o.equals(s);
}
}
}
if(equals) {
if (equals) {
// here we know that name indexes are equal & it is enough to check the value sets
if(objectNames == null || thatObj.objectNames == null) {
equals = objectNames == thatObj.objectNames;
} else if(objectNames.size() != thatObj.objectNames.size()){
if (objectNames == null || thatObj.objectNames == null) {
equals = objectNames == thatObj.objectNames;
} else if (objectNames.size() != thatObj.objectNames.size()) {
equals = false;
} else {
for(int i = 0; i < namesOrder.size() && equals; i++) {
for (int i = 0; i < namesOrder.size() && equals; i++) {
String o = objectNames.get(namesOrder.get(i));
String s = thatObj.objectNames.get(thatObj.namesOrder.get(i));
equals = Algorithms.objectEquals(o, s);
@ -284,18 +287,6 @@ public class BinaryMapDataObject {
}
}
//do we need it? use precision?
if (equals) {
if (labelCoordinates == null || thatObj.labelCoordinates == null) {
equals = labelCoordinates == thatObj.labelCoordinates;
//do we need it? precision?
// } else {
// for(int i = 0; i < labelCoordinates.length && equals; i++) {
// equals = labelCoordinates[i] == thatObj.labelCoordinates[i];
// }
}
}
return equals;
}
// thatObj.mapIndex.decodeType(thatObj.types[0])

View file

@ -76,7 +76,6 @@ import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap;
import gnu.trove.set.hash.TIntHashSet;
import gnu.trove.set.hash.TLongHashSet;
public class BinaryMapIndexReader {
@ -1135,8 +1134,8 @@ public class BinaryMapIndexReader {
TIntArrayList additionalTypes = null;
TIntObjectHashMap<String> stringNames = null;
TIntArrayList stringOrder = null;
TIntArrayList labelCoordinates = null;
long id = 0;
int labelX = 0, labelY = 0;
boolean loop = true;
while (loop) {
@ -1234,18 +1233,13 @@ public class BinaryMapIndexReader {
}
break;
case OsmandOdb.MapData.LABELCOORDINATES_FIELD_NUMBER:
System.out.println("label coords");
labelCoordinates = new TIntArrayList();
sizeL = codedIS.readRawVarint32();
old = codedIS.pushLimit(sizeL);
labelX = codedIS.readRawVarint32();
labelY = codedIS.readRawVarint32();
if (READ_STATS) {
req.stat.addTagHeader(OsmandOdb.MapData.LABELCOORDINATES_FIELD_NUMBER, sizeL);
req.stat.lastObjectLabelCoordinates += sizeL;
req.stat.addTagHeader(OsmandOdb.MapData.LABELCOORDINATES_FIELD_NUMBER, 0);
req.stat.lastObjectLabelCoordinates += CodedOutputStream.computeRawVarint32Size(labelX);
req.stat.lastObjectLabelCoordinates += CodedOutputStream.computeRawVarint32Size(labelY);
}
while (codedIS.getBytesUntilLimit() > 0) {
labelCoordinates.add(codedIS.readRawVarint32());
}
codedIS.popLimit(old);
break;
default:
skipUnknownField(t);
@ -1274,11 +1268,8 @@ public class BinaryMapIndexReader {
dataObject.id = id;
dataObject.area = area;
dataObject.mapIndex = root;
if (labelCoordinates != null) {
dataObject.labelCoordinates = labelCoordinates.toArray();
} else {
dataObject.labelCoordinates = new int[0];
}
dataObject.labelX = labelX;
dataObject.labelY = labelY;
return dataObject;
}
@ -1941,7 +1932,7 @@ public class BinaryMapIndexReader {
BinaryMapDataObject bm =
new BinaryMapDataObject(o.id, o.coordinates, o.polygonInnerCoordinates, o.objectType, o.area,
types.toArray(), additionalTypes.isEmpty() ? null : additionalTypes.toArray(),
o.labelCoordinates);
o.labelX, o.labelY);
if (o.namesOrder != null) {
bm.objectNames = new TIntObjectHashMap<>();
bm.namesOrder = new TIntArrayList();
@ -2225,7 +2216,6 @@ public class BinaryMapIndexReader {
private static List<Location> readGPX(File f) {
List<Location> res = new ArrayList<Location>();
try {
StringBuilder content = new StringBuilder();
BufferedReader reader = new BufferedReader(getUTF8Reader(new FileInputStream(f)));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder dom = factory.newDocumentBuilder();
@ -2242,7 +2232,6 @@ public class BinaryMapIndexReader {
// Document doc = dom.parse(new InputSource(new StringReader(content.toString())));
Document doc = dom.parse(new InputSource(reader));
NodeList list = doc.getElementsByTagName("trkpt");
Way w = new Way(-1);
for (int i = 0; i < list.getLength(); i++) {
Element item = (Element) list.item(i);
try {