我也尝试使用Polygon进行自定义TileProvider
。但是,我不知道我是否采取了正确的方式。事实上,我使用getTileUrl
得到了我的Polygon:
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public synchronized URL getTileUrl(int x, int y, int zoom) {
int reversedY = (1 << zoom) - y - 1;
tt = true;
x_tile=x;
y_tile=reversedY;
z_tile=zoom;
Observable<Algorithm> algorithmObs = Observable.from(algorithm);
Observable<List<Tuple<org.geojson.Polygon, Integer>>> geometriesObs = Observable
.from(algorithm)
.concatMap(algo -> algorithmService.getLatestVectorizedData(algorithm.getParcelle().getIndex(), algorithm.getIndex()))
.map(VectorizedDataDto::getIndex)
.concatMap(id -> algorithmService.getTiledVectorizedGeometries(algorithm.getIdAnalysedData(), 4,zoom,x,reversedY))
.map(VectorizedGeometriesDto::geometriesWithColor);
Observable
.zip(algorithmObs, geometriesObs, Tuple::new)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onSuccessGetVectorizedGeometrie);
return null;
}
private void onSuccessGetVectorizedGeometrie(Tuple<Algorithm, List<Tuple<org.geojson.Polygon, Integer>>> tuple) {
Algorithm algorithm = tuple.x;
List<Tuple<org.geojson.Polygon, Integer>> geometriesWithColor = tuple.y;
//algorithm.setParcelle(currentParcelle);
algorithm.setPolygonsWithColor(geometriesWithColor);
algorithm.setX_tile(x_tile);
algorithm.setY_tile(y_tile);
algorithm.setZ_tile(z_tile);
algorithm.setPolygon(geometriesWithColor.toString());
algorithm.save();
showTiledPolygon();
}
public void showTiledPolygon(){
for (Tuple<org.geojson.Polygon, Integer> algorithmPolygonWithColor : algorithm.getPolygonsWithColor()) {
polygon = googleMap
.addPolygon(new PolygonOptions()
.addAll(PolygonHelper.getBorder(algorithmPolygonWithColor.x))
.fillColor(algorithmPolygonWithColor.y)
.strokeColor(0xff000000)
.strokeWidth(3)
//.strokeColor(algorithmPolygonWithColor.y)
//.strokeWidth(0)
);
algorithmPolygons.add(polygon);
}
mapProgress.setVisibility(View.INVISIBLE);
}
};
它有效,但我不喜欢我的方法,因为没有缓存,所以我必须删除所有多边形并在每次缩放事件时调用它们。
对于具有多边形的自定义切片提供程序,是否有更好的方法?
非常感谢!