在Mapbox Android SDK中显示具有自定义属性的圆环图群集
Mapbox SDK Android地图上有不同的类型标记。 我对标记源使用集群,并使用自定义过滤器显示不同类型的计数在Mapbox Android SDK中显示具有自定义属性的圆环图群集,mapbox,mapbox-android,mapbox-marker,Mapbox,Mapbox Android,Mapbox Marker,Mapbox SDK Android地图上有不同的类型标记。 我对标记源使用集群,并使用自定义过滤器显示不同类型的计数 let geoJsonOptions = new this.mapboxSdk.style.sources.GeoJsonOptions() .withCluster(true) .withClusterMaxZoom(13) .withClusterRadius(51); for(let type in
let geoJsonOptions = new this.mapboxSdk.style.sources.GeoJsonOptions()
.withCluster(true)
.withClusterMaxZoom(13)
.withClusterRadius(51);
for(let type in this.ChecklistAttributes){
geoJsonOptions.withClusterProperty(type,
this.mapboxSdk.style.expressions.Expression.literal("+"),
this.mapboxSdk.style.expressions.Expression.raw('["case",["==",["get","type"],"'+type+'"],1,0]')
)
}
//Add GeoJson Source
this.ChecklistMarkersSource = new this.mapboxSdk.style.sources.GeoJsonSource("checklist-markers-source",
JSON.stringify(this.ChecklistsGeoJson),
geoJsonOptions
);
style.addSource(this.ChecklistMarkersSource);
当我查询源特性时,这就像预期的一样,我得到了具有不同计数的集群数据
我想根据不同类型的数量显示一个油炸圈饼图,但我找不到如何绘制自定义簇并添加到地图中的方法
这里有一个mapbox gl js的现成示例,但它使用了mapbox Android SDK不支持的HTML/SVG,或者我找不到方法来实现:
我曾尝试生成光栅图像,并将其添加为图像源层,但这感觉非常耗费资源,而且方法很糟糕。此外,我不知道在放大过程中如何处理图像的大小。我还遇到了集群问题,特别是Mapbox Android的
withClusterProperty
字段问题。这就是我的工作
要创建名为myClusterProperty
的群集属性,如果要素属性myFeatureProperty
等于“红色”
,则会添加1,否则会添加0:
GeoJsonOptions()
.withClusterProperty("myClusterProperty",
sum(accumulated(), get("myClusterProperty")),
switchCase(eq(get("myFeatureProperty"), "red"),
literal(1), literal(0)))
用于创建簇圆图层:
val mySourceData = GeoJsonSource("mySourceData",
FeatureCollection.fromFeatures(emptyList()),
GeoJsonOptions().withCluster(true).withClusterProperty(...)
要为簇添加圆,请执行以下操作:
// "point_count" is the Mapbox built-in property that only clusters have
val isInCluster = has("point_count")
val circleLayer = CircleLayer("myClusterLayerId", "mySourceData")
circleLayer.setProperties()
circleLayer.setFilter(isInCluster)
addLayer(circleLayer)
要按新创建的群集属性筛选此群集,请将circleLayer.setFilter(isInCluster)
替换为:
val hasCountAtLeastOne = gte(toNumber("myClusterProperty"), literal(1))
circleLayer.setFilter(all(isInCluster, hasCountAtLeastOne))