在Android地图中使用Polygon自定义TileProvider [英] Custom TileProvider with Polygon in Android maps
问题描述
我在绘制Android地图上的多边形时遇到问题。
问题是我有TileOverlay,所以多边形还是在叠加层下。
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.
我在GoogleMap上绘制多边形,如下所示:
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));
在瓷砖开始加载之前,我可以看到多边形,但它不见了。我想实现多边形绘制在TileProvider上。
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.
我有一个自定义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()));
我怎么能达到多边形在它们之上?或者至少在地图图层之上?我应该为多边形创建另一个覆盖层吗?如果是这样,我如何在TileProvider上绘制多边形?如果可能的话,我可以在dataLayer上绘制它?
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?
推荐答案
哦,这个解决方案非常简单,如果有人否则将来会遇到问题:
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));
而对于多边形:
map.addPolygon(new PolygonOptions().add(points).strokeColor(Color.RED).strokeWidth(3f).zIndex(4));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(points[0], 18));
这篇关于在Android地图中使用Polygon自定义TileProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!