Charlie-Blake
Charlie-Blake

Reputation: 11050

TileOverlay issue

So, when I use my MapBox maps, the Tiles are overlaid OVER my polylines and polygons, so they cannot be seen.

Is there any way to modify this behavior?

This is the code I'm using:

public class MapBoxOnlineTileProvider extends UrlTileProvider {

    private static final String[] FORMATS;

    static {
        final String[] servers = new String[] { "a", "b", "c", "d" };
        final String[] formats = new String[servers.length];
        for (int i = 0; i < servers.length; i++) {
            formats[i] = String.format(
                    "%%s://%s.tiles.mapbox.com/v3/%%s/%%d/%%d/%%d.png",
                    servers[i]);
        }
        FORMATS = formats;
    }

    // ------------------------------------------------------------------------
    // Instance Variables
    // ------------------------------------------------------------------------

    private String mMapIdentifier;
    private boolean mUseSSL;

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------

    public MapBoxOnlineTileProvider(final String mapIdentifier) {
        this(mapIdentifier, false);
    }

    public MapBoxOnlineTileProvider(final String mapIdentifier,
            final boolean useSSL) {
        super(256, 256);

        this.mMapIdentifier = mapIdentifier;
        this.mUseSSL = useSSL;
    }

    // ------------------------------------------------------------------------
    // Public Methods
    // ------------------------------------------------------------------------

    public String getMapIdentifier() {
        return this.mMapIdentifier;
    }

    public void setMapIdentifier(final String anIdentifier) {
        this.mMapIdentifier = anIdentifier;
    }

    public boolean isSSLEnabled() {
        return this.mUseSSL;
    }

    public void setSSLEnabled(final boolean enableSSL) {
        this.mUseSSL = enableSSL;
    }

    @Override
    public URL getTileUrl(final int x, final int y, final int z) {
        final String f = FORMATS[new Random().nextInt(FORMATS.length)];
        final String p = this.mUseSSL ? "https" : "http";
        try {
            System.out.println(String
                    .format(f, p, this.mMapIdentifier, z, x, y));
            return new URL(String.format(f, p, this.mMapIdentifier, z, x, y));
        } catch (final MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
    }

}

Setting an overlay:

final MapBoxOnlineTileProvider provider = new MapBoxOnlineTileProvider(MAP_ID);
final TileOverlayOptions overlay = new TileOverlayOptions().tileProvider(provider);
mMap.addTileOverlay(overlay);

Upvotes: 2

Views: 704

Answers (2)

N Dorigatti
N Dorigatti

Reputation: 3540

Make use of zIndex as is done in web pages. Consider the Overlay as backgrounds, so give them a zIndex that is multiple of 10 (doing this you can manage also unitary updates (for example in case of different LODs) Then consider the Geometries (Lines and poligons) as multiple of 100 (so each geometry is drawn for sure over the overlays).

Upvotes: 0

MaciejG&#243;rski
MaciejG&#243;rski

Reputation: 22232

You are looking for TileOverlayOptions.zIndex. This is also available on other visual objects (except for markers) and can be modified after the object is created with TileOverlay.setZIndex.

Upvotes: 4

Related Questions