fix rendering

git-svn-id: https://osmand.googlecode.com/svn/trunk@525 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-09-26 13:57:33 +00:00
parent 041df95c41
commit 1a52d0fb51
7 changed files with 85 additions and 20 deletions

View file

@ -30,14 +30,15 @@ public class ToDoConstants {
// TODO small improvements for release :
// 19. colors for road trunk and motorway
// 12. Fix : find proper location for streets ! centralize them (when create index)?
// 24. TODO! define clockwise/anticlockwise on android for closed path to understand area outised or inside
// 24. +! define clockwise/anticlockwise on android for closed path to understand area outised or inside
// fix Rendering for incompleted rings,
// fix Index Creator : 1) determine clockwise area (inverse if needed)+ 2) index low level multipolygon pass param +
// 3) pass inverse to low level indexes+ 4) coastline / add area +
// 5) identify case when there is only inner boundary (!!!!)
// 5) identify case when there is only inner boundary (!!!!) +
// 26. Move leisure below forest and grass layer (footway/cycleway below unspecified)
// 25. Add all attributes needed for routing (highway attributes, turn_restrictions)
// 27. Fix bug with some buildings in AMS (WTC) that have fence(?)
// 28. Fix freeze while map downloading
// TODO Improvements :
// 1! VELCOM

View file

@ -949,7 +949,6 @@ public class IndexCreator {
}
if (indexMap && (e instanceof Way || e instanceof Node)) {
// check that's not multipolygon
// manipulate what kind of way to load
loadEntityData(e, true);
boolean inverse = "-1".equals(e.getTag(OSMTagKey.ONEWAY));
@ -1025,7 +1024,6 @@ public class IndexCreator {
}
if (indexMap && e instanceof Relation && "multipolygon".equals(e.getTag(OSMTagKey.TYPE))) {
loadEntityData(e, true);
// TODO check for admin_level !!! that's not needed
Map<Entity, String> entities = ((Relation) e).getMemberEntities();
int mtType = 0;
for (Entity es : entities.keySet()) {
@ -1086,21 +1084,21 @@ public class IndexCreator {
double angle = 0;
double prevAng = 0;
for (int i = 1; i < nodes.size(); i++) {
double ang = Math.atan2(nodes.get(i).getLatitude() - nodes.get(i - 1).getLatitude(),
nodes.get(i).getLongitude() - nodes.get(i - 1).getLongitude());
if(i > 1){
double ang = Math.atan2(nodes.get(i).getLatitude() - nodes.get(i - 1).getLatitude(), nodes.get(i).getLongitude()
- nodes.get(i - 1).getLongitude());
if (i > 1) {
double delta = (ang - prevAng);
if(delta < -Math.PI){
delta += 2*Math.PI;
} else if(delta > Math.PI){
delta -= 2*Math.PI;
if (delta < -Math.PI) {
delta += 2 * Math.PI;
} else if (delta > Math.PI) {
delta -= 2 * Math.PI;
}
angle += delta;
prevAng = ang;
} else {
prevAng = ang;
}
}
return angle < 0;
}
@ -1715,7 +1713,7 @@ public class IndexCreator {
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/ams.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/ams_part_map.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/den_haag.tmp.odb"));
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/den_haag.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/den_haag.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/one.tmp.odb"));

View file

@ -243,7 +243,7 @@ public class MapRenderingTypes {
init();
}
addTypes.clear();
if("coastline".equals(e.getTag(OSMTagKey.NATURAL))){
if("coastline".equals(e.getTag(OSMTagKey.NATURAL))){ //$NON-NLS-1$
multipolygon = true;
}
@ -321,7 +321,7 @@ public class MapRenderingTypes {
}
}
}
int type = 0;
if(addTypes.isEmpty()){
return type;
@ -930,7 +930,6 @@ public class MapRenderingTypes {
register(2, "natural", "glacier", NATURAL, 7, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register(1, "natural", "heath", NATURAL, 8, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register(1,"natural", "land", NATURAL, 9, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register("natural", "heath", NATURAL, 10, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register(1, "natural", "marsh", NATURAL, 11, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register(1, "natural", "mud", NATURAL, 12, POLYGON_TYPE, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$
register(1, "natural", "peak", NATURAL, 13, POINT_TYPE); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -294,6 +294,9 @@ public class MapRenderRepositories {
statement = pZoom1.get(c);
} else if (zoom >= 6) {
statement = pZoom2.get(c);
} else {
// TODO show tiles ?
continue;
}
statement.setDouble(1, cBottomLatitude);
statement.setDouble(2, cTopLatitude);
@ -436,7 +439,9 @@ public class MapRenderRepositories {
MultyPolygon pl = processMultiPolygon(leftX, rightX, bottomY, topY, listPolygons, completedRings, incompletedRings, type,
directList, inverselist);
listPolygons.add(pl);
if(pl != null){
listPolygons.add(pl);
}
}
return listPolygons;
}
@ -482,8 +487,29 @@ public class MapRenderRepositories {
processMultipolygonLine(completedRings, incompletedRings, coordinates);
}
}
if(completedRings.size() == 0 && incompletedRings.size() == 0){
return null;
}
if (incompletedRings.size() > 0) {
unifyIncompletedRings(incompletedRings, completedRings, leftX, rightX, bottomY, topY);
} else {
// check for isolated island (android do not fill area outside path)
boolean clockwiseFound = false;
for(List<Long> c : completedRings){
if(isClockwiseWay(c)){
clockwiseFound = true;
break;
}
}
if(!clockwiseFound){
// add whole bound
List<Long> whole = new ArrayList<Long>(4);
whole.add((((long) leftX) << 32) | ((long) topY));
whole.add((((long) rightX) << 32) | ((long) topY));
whole.add((((long) rightX) << 32) | ((long) bottomY));
whole.add((((long) leftX) << 32) | ((long) bottomY));
completedRings.add(whole);
}
}
long[][] lns = new long[completedRings.size()][];
@ -497,6 +523,38 @@ public class MapRenderRepositories {
pl.setLines(lns);
return pl;
}
private boolean isClockwiseWay(List<Long> c){
double angle = 0;
double prevAng = 0;
int px = 0;
int py = 0;
int mask = 0xffffffff;
for (int i = 0; i < c.size(); i++) {
int x = (int) (c.get(i) >> 32);
int y = (int) (c.get(i) & mask);
if (i >= 1) {
double ang = Math.atan2(py - y, x - px);
if (i > 1) {
double delta = (ang - prevAng);
if (delta < -Math.PI) {
delta += 2 * Math.PI;
} else if (delta > Math.PI) {
delta -= 2 * Math.PI;
}
angle += delta;
prevAng = ang;
} else {
prevAng = ang;
}
}
px = x;
py = y;
}
return angle < 0;
}
private void processMultipolygonLine(List<List<Long>> completedRings, List<List<Long>> incompletedRings, List<Long> coordinates) {
if (coordinates.size() > 0) {

View file

@ -1441,7 +1441,7 @@ public class OsmandRenderer implements Comparator<MapRenderObject> {
}
break;
case 12: {
if (zoom >= 11) {
if (zoom >= 10) {
textColor = 0xFF000000;
textSize = 9;
}

View file

@ -9,6 +9,7 @@ public class PolygonRenderer {
public static void renderPolygon(RenderingContext rc, int zoom, int type, int subtype, OsmandRenderer o) {
if (type == MapRenderingTypes.HIGHWAY) {
rc.main.fillArea = zoom >= 15;
if (subtype == MapRenderingTypes.PL_HW_SERVICE || subtype == MapRenderingTypes.PL_HW_UNCLASSIFIED
|| subtype == MapRenderingTypes.PL_HW_RESIDENTIAL) {
rc.second.color = Color.rgb(194, 194, 194);
@ -171,6 +172,7 @@ public class PolygonRenderer {
break;
case 11 :
rc.main.color = Color.rgb(223, 209, 214);
rc.main.fillArea = zoom >= 16;
break;
case 12:
case 17:
@ -289,10 +291,12 @@ public class PolygonRenderer {
} else if (type == MapRenderingTypes.AMENITY_TRANSPORTATION) {
if (subtype == 1 || subtype == 2) {
rc.main.color = Color.rgb(246, 238, 183);
rc.main.fillArea = zoom >= 15;
}
} else if (type == MapRenderingTypes.AMENITY_ENTERTAINMENT) {
if (subtype == 3) {
rc.main.color = Color.rgb(204, 153, 153);
rc.main.fillArea = zoom >= 15;
}
} else if (type == MapRenderingTypes.AMENITY_EDUCATION) {
if(subtype == 1 || subtype == 2 || subtype == 3 || subtype == 5){
@ -303,6 +307,7 @@ public class PolygonRenderer {
} else {
// draw as building education
rc.main.color = Color.rgb(188, 169, 169);
rc.main.fillArea = zoom >= 16;
}
}
}

View file

@ -4,6 +4,7 @@ import net.osmand.ResourceManager;
import net.osmand.osm.MapUtils;
import net.osmand.views.OsmandMapLayer;
import net.osmand.views.OsmandMapTileView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
@ -61,7 +62,8 @@ public class RendererLayer implements OsmandMapLayer {
}
MapRenderRepositories renderer = resourceManager.getRenderer();
if (renderer != null && renderer.getBitmap() != null) {
Bitmap bmp = renderer.getBitmap();
if (renderer != null && bmp != null) {
RectF newLoc = renderer.getCachedWaysLoc();
float rot = renderer.getCachedRotate();
float leftX1 = (float) MapUtils.getTileNumberX(view.getFloatZoom(), newLoc.left);
@ -75,7 +77,9 @@ public class RendererLayer implements OsmandMapLayer {
float y2 = calcDiffPixelY(rot, rightX1 - view.getXTile(), bottomY1 - view.getYTile()) + view.getCenterPointY();
canvas.rotate(-rot, view.getCenterPointX(), view.getCenterPointY());
destImage.set(x1, y1, x2, y2);
canvas.drawBitmap(renderer.getBitmap(), null, destImage, paintImg);
if(!bmp.isRecycled()){
canvas.drawBitmap(bmp, null, destImage, paintImg);
}
}
}
}