您最好的乐趣可能是使用 Mapbox 提供的源/图层功能。
源包含您的数据点,作为层,您可以将其视为 HTML 的样式表。它包含有关数据点外观的信息。
对于创建图层,您有不同的选项,具体取决于您希望标记的外观。如果你想显示你自己的图标,你必须使用 SymbolLayer,但还有更多(CircleLayer 用于显示点/圆,...)
要创建源代码,请使用以下内容
style.addLayer(
new SymbolLayer(YOUR_LAYER_ID_STRING, YOUR_SOURCE_ID_STRING)
.withProperties(
// here you can define things like the icon
// icon color
// icon size
// ... many more. Have a look at the Property class
)
);
您还可以根据项目的值设置项目的样式。它在 Mapbox 中称为数据驱动样式。看看我的另一个答案,也许会得到更多的理解。
要创建源,请使用以下内容
ArrayList<Feature> features = new ArrayList<>();
Iterate over your CSV items {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("subject_key", item.subjectValue);
jsonObject.addProperty("report_key", item.reportByValue);
features.add(Feature.fromGeometry(Point.fromLngLat(item.getLat(), item.getLon()), jsonObject);
}
FeatureCollection featureCollection = FeatureCollection.fromFeatures(features);
style.addSource(new GeoJsonSource(YOUR_SOURCE_ID_STRING, featureCollection, new GeoJsonOptions()));
您还可以让点击侦听器捕捉对标记的点击 (https://docs.mapbox.com/android/maps/examples/click-on-a-single-layer/)。