android - OSMDroid PathOverlay 没有出现

标签 android dictionary osmdroid

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

更新:

我发现它与图 block 大小有关。我将大小设置为 512,即使图 block 为 256,否则 map 太小而无法在高像素密度屏幕上阅读。如果我将大小更改为 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 tiles 解决了这个问题,所以我不必为高密度屏幕使用 512 像素大小。基本问题仍然存在,以防万一有人想调查。

最佳答案

尝试在 PathOverlay 中添加带有描边的 Paint

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的时候,所有的投影和直线计算都是基于这个参数。因此,如果您将其设置为不是图 block 实际大小的值,则计算将失败并且不会显示覆盖路径。

关于android - OSMDroid PathOverlay 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19776760/

相关文章:

python - 将两个列表(其中一个是列表的列表)映射到字典中

c# - 如何处理 ASP.NET MVC 3 中每个键的多个值?

android - osmdroid:计算 map 大小

android - Android 中的 OsmAnd

java - 为什么应用程序中的音频停止播放?

android - 在 Eclipse 上为 Android 程序插入断点

python - 在 python 3 中创建嵌套字典

android - 打开街道 map 离线工作 android

android - 使所有 fragment 位于横幅广告上方

android - 错误: duplicate value for resource 'attr/orientation' with config '' . aapt.v2.Aapt2Exception:Android资源编译失败