【问题标题】:OSMDroid PathOverlay not appearingOSMDroid PathOverlay 没有出现
【发布时间】:2013-11-04 20:43:17
【问题描述】:

我正在尝试向 OSMDroid 地图添加路径叠加,但它没有出现。我错过了什么?

更新:

我发现它与图块大小有关。即使瓦片是 256,我也将大小设置为 512,否则地图太小而无法在高像素密度屏幕上阅读。如果我将大小更改为 256,则会显示路径。如果我把它改回 512,它就不会显示。

public class MainActivity extends Activity {

    // set this to 256 for actual tile size, 512 to show larger and cause PathOverlay to not be displayed
    int tileSize = 512; 

    private MapView mapView;

    // area of offline tiles
    double north = 40.739063;
    double south =  40.708361;
    double west  =  -73.967171;
    double east  =  -73.936272;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // center of offline tiles
        double centerlat = (double) ((north+south)/2);
        double centerlon = (double) ((west+east)/2);

        // copy tiles to sd location for offline map
        putMapOnSD();

        // create mapView and show layout
        mapView = new MapView(this,tileSize);
        final LinearLayout layout = new LinearLayout(this);
        final LinearLayout.LayoutParams mapViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        layout.addView(mapView, mapViewLayoutParams);
        setContentView(layout);

        // set map to use offline tiles and display
        mapView.setTileSource  (new XYTileSource ("tiles", ResourceProxy.string.offline_mode, 13, 17, tileSize, ".png", "http://127.0.0.1")); 
        mapView.setUseDataConnection(false);
        mapView.setClickable(false);
        mapView.setMultiTouchControls(true);
        mapView.setBuiltInZoomControls(false);
        mapView.getController().setZoom(15);
        mapView.getController().setCenter(new GeoPoint(centerlat,centerlon));

        // show pathOverlay
        PathOverlay pathOverlay = new PathOverlay(Color.RED, this);
        pathOverlay.addPoint(new GeoPoint(centerlat,centerlon));
        centerlat += 0.005;
        pathOverlay.addPoint(new GeoPoint(centerlat,centerlon));
        centerlon += 0.005;
        pathOverlay.addPoint(new GeoPoint(centerlat,centerlon));
        pathOverlay.getPaint().setStrokeWidth(10.0f);
        mapView.getOverlays().add(pathOverlay);

        // refresh map, is this needed?
        mapView.invalidate();
    }


    // this copies the offline tiles to the proper location for OSMDroid to use them offline
    private void putMapOnSD() {
        // see GitHub for this
    }
}

在 GitHub 上获取完整的项目。 https://github.com/tomkincaid/PathExample

我通过使用 Cloudmade 的 @2x 磁贴解决了这个问题,因此我不必为高密度屏幕使用 512 像素大小。尽管有人想调查,但基本问题仍然存在。

【问题讨论】:

  • 如果瓷砖尺寸越大,路径覆盖越差,你可能不得不使用你的地理坐标来增加差异或尺寸:)一旦这对我有用:)

标签: android map osmdroid


【解决方案1】:

尝试将带有笔划的Paint 添加到PathOverlay

Paint paint = new Paint();
paint.setAlpha(155);
paint.setColor(Color.argb(205, 178, 255, 255));
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(10);
pathOverlay.setPaint(paint);

更新: 我认为,您的路径未出现的主要原因与Tile Size 参数直接相关。因为在绘制pathOVerlay的时候,所有的投影和线的计算都是基于这个参数的。因此,如果您将其设置为不是图块实际大小的值,则计算将失败并且不会显示覆盖路径。

【讨论】:

  • 仍然没有显示。
  • 因为我之前使用过带有路径叠加的 OSMDroid 地图,所以我会要求您发布您的地图活动的整个代码,以便我可以提供帮助。
  • 谢谢蒂姆。代码中有很多额外的东西。我将不得不清理它以使示例清晰。我发现 Cloudmade 以 2 倍的速度提供图块,因此它实际上解决了问题。我可以在 256 使用他们的牌。
  • 我发布了一个示例项目的代码,并把整个东西放在了 GitHub 上。
猜你喜欢
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多