Android Maps API v2: Polyline gets drawn under tile overlay
Asked Answered
N

2

8

I'm trying to draw a tile overlay and a poly line to a google map. I would like the poly line to be rendered on top of the tile overlay so it can be seen. Currently it's drawn under the tile overlay and disappears , my code is as follows:

// Draw the tile overlay
NBUrlTileProvider tileProvider = new NBUrlTileProvider(url, 256, 256);

TileOverlayOptions tileOverlayOptions = new TileOverlayOptions()
                    .tileProvider(tileProvider)
                    .fadeIn(true);

mMap.addTileOverlay(tileOverlayOptions);

// Draw the poly line
PolylineOptions polyLineOptions = new PolylineOptions();

polyLineOptions.width(5).geodesic(true).color(Color.rgb(255, 0, 255));

polyLineOptions.add(location1);
polyLineOptions.add(location2);
polyLineOptions.add(location3);

mMap.addPolyline(polyLineOptions);

Any help would be very much appreciated, I thought that poly lines would just get drawn on top of tile overlays by default, is there anything extra I have to add?

Nikolos answered 11/4, 2014 at 6:14 Comment(1)
Hello, I am new to Tiles and don't know anything about it. can you please tell me what is this "url" stands for (or what url contains) and NBUrlTileProvider extends UrlTileProvider or TileProvider ?Edmonds
N
21

Solution was to use:

Polyline polyline = mMap.addPolyline(polyLineOptions);

polyline.setZIndex(1000); //Or some large number :)
Nikolos answered 11/4, 2014 at 7:46 Comment(0)
E
2

You should consider pushing the tiles overlay to the back (I simpyl use -500) instead of pushing the polylines to the front, because they will then be drawn over markers (and cluster markers).

overlay = map.addTileOverlay(new TileOverlayOptions().tileProvider(new MyUrlTileProvider(512, 512, "xxx")).zIndex(-500));

@Gyroscope

Entomologize answered 16/6, 2020 at 20:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.