gpt4 book ai didi

android - Osmdroid 覆盖在高缩放级别时的奇怪行为

转载 作者:行者123 更新时间:2023-11-29 22:17:42 25 4
gpt4 key购买 nike

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

我制作了一个最小的示例应用程序,它演示了在真实设备和模拟器 (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 绘图结束时一次性将其全部绘制出来,那么线条不会消失。

任何帮助将不胜感激。

最佳答案

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

另见:OSMDroid PathOverlay drawing is corrupted at high zoom levels

关于android - Osmdroid 覆盖在高缩放级别时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8115394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com