mapbox - 在 Mapbox Android SDK 中显示具有自定义属性的圆环图集群
问题描述
Mapbox SDK Android 地图上有不同的类型标记。我正在使用带有自定义过滤器的标记源聚类来显示不同类型的计数。
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,或者我找不到方法:
https://docs.mapbox.com/mapbox-gl-js/example/cluster-html/
我尝试生成光栅图像并将它们添加为图像源层,但这感觉非常占用资源和糟糕的方法。另外,我不知道如何在放大过程中处理图像的大小。
解决方案
我也遇到了集群问题,特别是 Mapbox Android 的withClusterProperty
字段。这对我有用。
要创建一个名为myClusterProperty
- 的集群属性,如果特征属性myFeatureProperty
等于"red"
,则添加 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)
要通过新创建的集群属性过滤此集群,请myClusterProperty
替换circleLayer.setFilter(isInCluster)
为:
val hasCountAtLeastOne = gte(toNumber("myClusterProperty"), literal(1))
circleLayer.setFilter(all(isInCluster, hasCountAtLeastOne))
推荐阅读
- angular - 在 *NgFor 中为每一行放置一个按钮
- javascript - 如何通过选择表单选项将 html div 发送到另一个
- vue.js - 如果购物车中的 id 相同,Vue 会自动更新总值
- html - 通过 aria-label Excel VBA 获取 HTML 元素
- c# - VS2019 奇怪的 nuget 命名空间解析
- javascript - 在表单中更新状态
- javascript - JavaScript Promise 回调在 Promise 本身之前执行
- network-programming - UDP:如何使网络连接上的 UDP 数据包的数据流率平滑
- c# - C# 将字符串转换为常量字符串
- php - 如何使用 PHP 将类添加到“a href”元素?