1

我在我的应用程序中使用 osmdroid 3.0.5 jar 来显示地图视图。我正在叠加一个覆盖层,由水平线和垂直线组成。我注意到仅在某些位置,在高缩放级别下,某些线条会消失,然后在拖动地图时重新出现。

我制作了一个最小的示例应用程序,它演示了在真实设备和模拟器(Gingerbread 2.3.3)上都出现的问题。

完整的代码如下所示 - ('transform' 方法在真实应用程序中是必需的,尽管它们似乎不在这个最小示例中):

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 绘制结束时一次性绘制,线条不会消失就可以了。

任何帮助都感激不尽。

4

2 回答 2

1

听起来可能是这个 bug 的另一种表现: Issue 207

您是否看到与早期 API 版本相同的行为?

于 2011-11-13T23:01:06.387 回答
1

我知道这是一个老问题,但我相信您遇到的是Issue 221。这已在版本 3.0.9 中修复。

另请参阅:OSMDroid PathOverlay 绘图在高缩放级别时损坏

于 2013-04-08T22:30:18.483 回答