如何使用要素属性在地图框图层内设置多个填充颜色

时间:2019-02-05 03:32:18

标签: mapbox-android

对于我的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

0 个答案:

没有答案