В своем приложении mapbox я пытаюсь использовать только один слой и один источник для отображения нескольких полигонов с их собственным цветом:
Сначала я преобразую полигоны в объекты:
for (GeometryWithData geometryWithData : geometryWithDataList) {
//Transform JTSgeometry into mapbox feature
ArrayList<Point> routeCoordinates = new ArrayList<>();
for (Coordinate coordinate : geometryWithData.getGeometry().getCoordinates()) {
routeCoordinates.add(Point.fromLngLat(coordinate.x, coordinate.y));
}
LineString lineString = LineString.fromLngLats(routeCoordinates);
Feature feature = Feature.fromGeometry(lineString);
feature.addNumberProperty("fill-color", Color.parseColor(geometryWithData.getColor()));
features[idx++] = feature;
}
Затем я добавляю объекты в качестве источника и создаю fillLayer:
FeatureCollection featureCollection = FeatureCollection.fromFeatures(features);
GeoJsonSource geoJsonSource = new GeoJsonSource(SOURCE_ID, featureCollection);
my_mapboxMap.addSource(geoJsonSource);
FillLayer layer = new FillLayer(LAYER_ID, SOURCE_ID);
my_mapboxMap.addLayer(layer);
Есть ли способ использовать numberProperty (добавленный в функцию) в качестве источника цвета?Возможно ли иметь несколько цветов в одном слое?
Похожие записи: https://github.com/mapbox/mapbox-android-demo/issues/733