Search code examples
androidosmdroid

Osmdroid render not expected like that - TileSource PublicTransport


i've got some trouble with an app wich need to use the OSMPublicTransport tilesource.

Click here to see the strange MapView. So, why is this ugly thing in my app ? Other tilesource work like a charm.

I don't know why it shows me the mapview like this. I was waiting for a result like the official website

Here is my XML file :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tilesource="OSMPublicTransport" />
</RelativeLayout>

And here how I declare my view :

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);
            mapView = FindViewById<MapView> (Resource.Id.mapview);

            mapView.SetTileSource (TileSourceFactory.PublicTransport);

            mapView.SetBuiltInZoomControls (true);
            mapView.SetMultiTouchControls (true);
       }

In advance, thanks you!


Solution

  • The OSMPublicTransport tiles are overlay tiles. They are meant to be displayed on top of existing imagery. So use a regular tile source, and then add a new TilesOverlay for the overlay imagery:

    // Add tiles layer
    MapTileProviderBasic provider = new MapTileProviderBasic(getApplicationContext());
    provider.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
    TilesOverlay tilesOverlay = new TilesOverlay(provider, this.getBaseContext());
    mapView.getOverlays().add(tilesOverlay);