Custom TileProvider with Polygon in Android maps

老子叫甜甜 提交于 2019-12-13 00:55:39

问题


I'm having problems drawing a polygon on Android map. The problem is that I have TileOverlays so the polygon is kinda under the overlays.

I'm drawing a polygon on GoogleMap like this:

map.addPolygon(new PolygonOptions().add(points).strokeColor(Color.RED).strokeWidth(3f));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(points[0], 18));

I can see the polygon before the tiles are starting to load but then it's gone. I would like to achieve that the polygon is drawn over the TileProvider.

I have a custom TileProvider which does three layers: cached layer, custom map layer and data layer which is partly transparent.

When map loads, I create all three layers:

cacheLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addCache()));
mapLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addMap()));
dataLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addData()));

How could I achieve that the polygon is above them all? Or at least above the map layer? Should I create another overlay just for the polygon? If so, how can I draw a polygon on the TileProvider? If that is possible, I could just draw it on the dataLayer?


回答1:


Oh well, the solution is pretty simple, if anyone else will have the problem in the future:

cacheLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addCache()).zIndex(1));
mapLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addMap()).zIndex(2));
dataLayer = map.addTileOverlay(new TileOverlayOptions().tileProvider(addData()).zIndex(3));

And for the polygon:

map.addPolygon(new PolygonOptions().add(points).strokeColor(Color.RED).strokeWidth(3f).zIndex(4));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(points[0], 18));


来源:https://stackoverflow.com/questions/34875340/custom-tileprovider-with-polygon-in-android-maps

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