osmdroid - higher zoom level?

跟風遠走 提交于 2019-12-03 12:23:30

问题


I'm trying to implement a MapView using the osmdroid library.

However at the moment the furthest I seem to be able to zoom in isn't sufficient enough for my purposes.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Setup map view:
    mapView = new MapView(this, 256);
    setContentView(mapView);

    // Parse parameters
    Intent intent = getIntent();

    center      = intent.getDoubleArrayExtra(INITIAL_CENTER);
    multiTouch  = intent.getBooleanExtra(MULTI_TOUCH, DEFAULT_MULTI_TOUCH);
    zoomButtons = intent.getBooleanExtra(ZOOM_BUTTONS, DEFAULT_ZOOM_BUTTONS);
    zoomLevel   = intent.getIntExtra(ZOOM_LEVEL, DEFAULT_ZOOM_LEVEL);

    if (center == null)
        center  = DEFAULT_INITIAL_CENTER;

    // Applying parameters
    mapView.setClickable(true);
    mapView.setMultiTouchControls(multiTouch);
    mapView.setBuiltInZoomControls(zoomButtons);
    mapView.getController().setZoom(zoomLevel);
    mapView.getController().setCenter(new GeoPoint(center[0], center[1]));
    mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
    mapView.setMaxZoomLevel(18);

    // Show current location coordinates
    Toast.makeText(
            getApplicationContext(),
            "Latitude:\t\t" + center[0] + "\n" +
            "Longitude:\t" + center[1],
            Toast.LENGTH_LONG).show();

    // Offline maps:
    mapView.setUseDataConnection(true);

}

Is there anyway to zoom in further (I've already tried setting zoom level to 18)?


回答1:


The maximum zoom level is determined by the tile source that you are using. If you are using one of the provided online tile sources like MAPNIK, then the max zoom level is set to 18 because that is the max zoom level that the tile source creates tiles for. If you want to zoom in further then you need to use a tile source that provides higher zoom level tiles.

If you simply want to override the max zoom level regardless of the tile source's zoom level then you can simply call:

mapView.setMaxZoomLevel(19);

to set the max zoom level to 19, but again the tile source may just not have tiles at that zoom level.




回答2:


For anybody looking for solution for better tile scaling, osmdroid now comes in with built-in function called :

setTilesScaledDpi(boolean) 

The function is located in MapView class.




回答3:


I had a similar problem to this while using a new HTC One today. Owing to the very high screen density, the maximum zoom level rendered the map tiles in such a manner as to make the street names and locations almost unreadable (I'm using OpenStreetMap). The best solution that I found was to scale the images in the tile source:

final float scale = getBaseContext().getResources().getDisplayMetrics().density;
final int newScale = (int) (256 * scale);
String[] OSMSource = new String[2];
OSMSource[0] = "http://a.tile.openstreetmap.org/";
OSMSource[1] = "http://b.tile.openstreetmap.org/";  
XYTileSource MapSource = new XYTileSource("OSM", null, 1, 18, newScale, ".png", OSMSource);  
map.setTileSource(MapSource);

Varying the scale in accordance with the screen density is a relatively good solution, provided you add some contingency to prevent the tiles becoming too blurry.

This is not my solution BTW, I found it among the OSMDROID issues on Github. Thanks goes to stefangab95.

EDIT: If the screen density is too high then scaling the tiles can also have the negative impact of making routes paths (generated using RoadManager) invisible. This problem has been recorded as an issue on the OSMBonusPack web site - No Polyline drawn. There is no resolution as yet.



来源:https://stackoverflow.com/questions/22282315/osmdroid-higher-zoom-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!