我在我的应用程序中使用osmdroid 3.0.5 jar来显示地图视图。我正在叠加一个由水平和垂直线组成的叠加层。我注意到,仅在某些位置,在高缩放级别,某些线条会消失,然后在拖动地图时重新出现。
我制作了一个最小的示例应用程序,它演示了在真实设备和模拟器(Gingerbread 2.3.3)上展示自身的问题。
完整的代码如下所示 - ('变换'方法在真实应用中是必需的,尽管它们似乎不在这个最小的样本中):
public class DemoMap extends Activity implements MapViewConstants {
private MapView mapView;
private MapController mapController;
private MapOverlay mmapOverlay = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.copymain);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapController = mapView.getController();
mapController.setZoom(17);
// Only shows the bug at ceratin lat/lon positions, this is one
GeoPoint point2 = new GeoPoint(39191699, -120102561);
mapController.setCenter(point2);
mmapOverlay = new MapOverlay(this);
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mmapOverlay);
mapView.invalidate();
}
public class MapOverlay extends org.osmdroid.views.overlay.Overlay {
public MapOverlay(Context ctx) {super(ctx); }
private int mVpl;// viewport left, top, right, bottom
private int mVpt;
private int mVpr;
private int mVpb;
private MapView mMv = null;
// Two routines to transform and scale between viewport and mapview
private float transformX(float in, MapView mv) {
float out;
out = ((mVpr - mVpl) * in) / (mv.getRight() - mv.getLeft())
+ mVpl;
return out;
}
private float transformY(float in, MapView mv) {
float out;
out = ((mVpb - mVpt) * in) / (mv.getBottom() - mv.getTop())
+ mVpt;
return out;
}
@Override
protected void draw(Canvas pC, MapView mapV, boolean shadow) {
if (shadow)
return;
Paint paint;
paint = new Paint();
paint.setColor(Color.RED);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(1);
paint.setTextAlign(Paint.Align.LEFT);
paint.setTextSize(12);
final Rect viewportRect = new Rect();
final Projection projection = mapV.getProjection();
viewportRect.set(projection.getScreenRect());
mVpl = viewportRect.left;
mVpt = viewportRect.top;
mVpr = viewportRect.right;
mVpb = viewportRect.bottom;
// draw two lines to split screen into 2x2 quarters
// drag the map left and right and the vertical line disappears,
// then reappears! It's OK at one less zoom level
pC.drawLine(transformX(mapV.getWidth()/2, mapV), transformY(0, mapV),
transformX(mapV.getWidth()/2, mapV),
transformY(mapV.getHeight(), mapV), paint);
pC.drawLine(transformX(0, mapV), transformY(mapV.getHeight()/2, mapV),
transformX(mapV.getWidth(), mapV),
transformY(mapV.getHeight()/2, mapV), paint);
}
}
}
有趣的是,如果在我的真实应用程序中,如果我将绘图绘制到屏幕外的位图,那么在Overlay的绘制结束时一次性绘制它,就可以了,线条不会消失。
非常感谢任何帮助。
答案 0 :(得分:1)
听起来这可能是这个错误的另一种表现形式: Issue 207
您是否看到早期API版本的相同行为?
答案 1 :(得分:1)
我知道这是一个老问题,但我相信你遇到的是Issue 221。这已在版本3.0.9中修复。
另见:OSMDroid PathOverlay drawing is corrupted at high zoom levels