user3420815
user3420815

Reputation: 805

TileOverlay#getTile starts at zoom level 3

I'm trying to build a Map with custom tiles using the Google Maps Android SDK. I've checked out the TileOverlayDemoActivity of the android-samples Github repository.

According to the documentation at Zoom level 0 a single image will be requested, on zoom level 1 a total of 4 images and so on. Currently I'm facing the problem that immediately after loading the map the TileProvider#getTitle is getting called with zoom level 3 and there is no way for me to zoom out. Even if I display the zoom controls the "-" is disabled.

What I have tried

I figured it might be related to the Camera so I tried calling the following

map.moveCamera(CameraUpdateFactory.zoomTo(0.0f));

Unfortunately this doesn't have any effect. Same goes for the following

map.setMinZoomPreference(0);

Currently I don't know what the issue might be.

Following my code. It's basically the same as in the linked demo activity I've just changed the UrlTileProvider to my own.

@Override
public void onMapReady(GoogleMap map) {
    map.setMapType(GoogleMap.MAP_TYPE_NONE);
    map.setMinZoomPreference(0);
    map.getUiSettings().setZoomControlsEnabled(true);
    map.moveCamera(CameraUpdateFactory.zoomTo(0.0f));

    TileProvider tileProvider = new TileProvider() {
        @Override
        public Tile getTile(int x, int y, int zoom) {
            String name = "tile_" + Integer.toString(zoom) + "_" + Integer.toString(x) + "_" + Integer.toString(y);
            Resources resources = getResources();
            final int resourceId = resources.getIdentifier(name, "drawable", getPackageName());

            Drawable d = getResources().getDrawable(resourceId);
            Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] bitmapdata = stream.toByteArray();

            return new Tile(256, 256, bitmapdata);
        }
    };

    mapTiles = map.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
}

Maybe it's worth mentioning what map.getCameraPosition() returns:

CameraPosition{target=lat/lng: (0.0,0.0), zoom=2.0, tilt=0.0, bearing=0.0}

tl;dr

How can I set the Map to zoom level 0?

Edit

According to the comment and answer I tried to activate Lite Mode and set the zoom level via XML:

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraZoom="1"
    map:mapType="normal"
    class="com.google.android.gms.maps.SupportMapFragment" />

Unfortunately without any effect. It still starts requesting at zoom level 3.

Upvotes: 1

Views: 189

Answers (1)

Andrii Omelchenko
Andrii Omelchenko

Reputation: 13343

Seems that is impossible to set zoom level to 0 because minimal zoom level is 1 from documentation:

The following list shows the approximate level of detail you can expect to see at each zoom level:

1: World
5: Landmass/continent
10: City
15: Streets
20: Buildings

also from documentation:

Note: Due to screen size and density, some devices may not support the lowest zoom levels. Use GoogleMap.getMinimumZoomLevel() to get the minimum zoom level possible for the map. If you need to show the entire world in the viewport, it may be better to use Lite Mode.

So, use Lite Mode to show the entire world in the viewport.

Upvotes: 1

Related Questions