我想将群集添加到地图集地图中。我跟着可用的文档,过了一段时间我就堆积了它:
List<Feature> markerCoordinates = new ArrayList<>();
Log.v(LOG_TAG, "all advertiesrs retrieved");
for(Elem e: result) {
markerCoordinates.add(Feature.fromGeometry(
Point.fromCoordinates(Position.fromCoordinates(e.getLatitude(), e.getLongitude())))
);
}
FeatureCollection featureCollection = FeatureCollection.fromFeatures(markerCoordinates);
Log.v(LOG_TAG, "list has: " + markerCoordinates.size() + " elements");
FeatureCollection collection1 = FeatureCollection.fromFeatures(markerCoordinates);
map.addSource(
new GeoJsonSource(CUSTOM_DATA_SOURCE,
collection1,
new GeoJsonOptions()
.withCluster(true)
.withClusterMaxZoom(14)
.withClusterRadius(50)
)
);
// Each point range gets a different fill color.
int[][] layers = new int[][] {
new int[] {10, ContextCompat.getColor(MainActivity.this, R.color.marker_red)},
new int[] {4, ContextCompat.getColor(MainActivity.this, R.color.marker_green)},
new int[] {0, ContextCompat.getColor(MainActivity.this, R.color.marker_blue)}
};
//Creating a marker layer for single data points
//How to create different markers for different points categories
Bitmap icon = BitmapFactory.decodeResource(MainActivity.this.getResources(), R.drawable.marker_1);
map.addImage("marker_1", icon);
SymbolLayer unclustered = new SymbolLayer("unclustered-points", CUSTOM_DATA_SOURCE);
unclustered.setProperties(iconImage("marker_1"));
map.addLayer(unclustered);
for (int i = 0; i < layers.length; i++) {
//Add clusters' circles
CircleLayer circles = new CircleLayer("cluster-" + i, CUSTOM_DATA_SOURCE);
circles.setProperties(
circleColor(layers[i][1]),
circleRadius(18f)
);
circles.setFilter(
i == 0
? gte("point_count", layers[i][0]) :
all(gte("point_count", layers[i][0]), lt("point_count", layers[i - 1][0]))
);
map.addLayer(circles);
}
//Add the count labels
SymbolLayer count = new SymbolLayer("count", CUSTOM_DATA_SOURCE);
count.setProperties(
textField("{point_count}"),
textSize(12f),
textColor(Color.WHITE)
);
map.addLayer(count);
问题是,我需要为不同的非聚集点添加不同的图标标记。现在我只能添加一个常用图标marker_1
。我无法弄清楚如何创建一些非聚集数据的“组”(每个不同点类别的不同图标)。