奇怪的行为与Osmdroid覆盖高缩放级别 [英] Strange behaviour with Osmdroid overlay at high zoom levels

查看:199
本文介绍了奇怪的行为与Osmdroid覆盖高缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的应用程序的osmdroid 3.0.5罐子以显示地图视图。我重叠的重叠,其中包括的水平和垂直线。我注意到,在只有某些地方,高缩放级别的某些行消失,然后重新出现在地图拖动。

I'm using the osmdroid 3.0.5 jar in my app to display a map view. I'm superimposing an overlay, consisting of horizontal and vertical lines. I've noticed that in certain locations only, at high zoom levels some of the lines disappear, then reappear as the map is dragged.

我制作这表明它具有自己既是一个真实的设备和仿真器上的问题最小的示例应用程序(姜饼2.3.3)。

I've produced a minimal sample app which demonstrates the problem which exhibits itself both on a real device and an emulator (Gingerbread 2.3.3).

完整code如下 - (即改造虽然他们不似乎是这个最小样本的方法是在真正的应用程序需要):

The complete code is shown below - (the 'transform' methods are necessary in the real app although they don't appear to be in this minimal sample) :

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);
        }
    }
}

有趣的是,如果在我的真正的应用程序,如果我做的画上一个屏幕外的位图,然后绘制这一切在叠加的平局结束一气呵成,这是确定的行不会消失。

Interestingly if, in my real app, if I do the drawing to an offscreen bitmap, then draw it all in one go at the end of the Overlay's draw, it's OK the lines don't disappear.

任何帮助将非常AP preciated。

Any help will be much appreciated.

推荐答案

我知道这是一个老问题,但我相信您遇到的的问题221 。这已被固定在3.0.9版本。

I know this is an old question, but I believe what you're experiencing is Issue 221. This has been fixed in version 3.0.9.

另请参见:<一href=\"http://stackoverflow.com/questions/9273561/osmdroid-pathoverlay-drawing-is-corrupted-at-high-zoom-levels\">OSMDroid PathOverlay绘图高缩放级别的损坏

这篇关于奇怪的行为与Osmdroid覆盖高缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆