我一直在努力尝试在我的集群上添加一个onClick函数,它可以在Map上进行一点缩放,但我不知道如何做到这一点,而且我在文档中也找不到任何帮助。
我一直在尝试使用controller.onCircleTapped
和controller.onFeatureTapped
,但我不明白它是如何工作的,也不知道如何将回调链接到特定的集群。
谢谢大家!
下面是我当前的代码:
`
Future<void> addGeojsonCluster() async {
var geojson = {
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "pois" } },
"features": [
for(var marker in markers){
"type" : "Feature", "properties" : {"id" : marker.title}, "geometry": {"type" : "Point", "coordinates" : [marker.longitude, marker.latitude] }
},
]
};
await controller.addSource(
"poi",
GeojsonSourceProperties(
data: geojson,
cluster: true,
clusterMaxZoom: 14, // Max zoom to cluster points on
clusterRadius:
50, // Radius of each cluster when clustering points (defaults to 50)
)
);
await controller.addLayer(
"poi",
"poi-circles",
const CircleLayerProperties(
circleColor: [
Expressions.step,
[Expressions.get, 'point_count'],
'#51bbd6', //blue
100,
'#f1f075', //yellow
750,
'#f28cb1' //pink
],
circleRadius: [
Expressions.step,
[Expressions.get, 'point_count'],
20,
100,
30,
750,
40
]),
);
await controller.addSymbolLayer(
"poi",
"unclustered-point",
const SymbolLayerProperties(
textField: [Expressions.get, "id"],
textHaloWidth: 1,
textSize: 12.5,
textHaloColor: '#ffffff',
textOffset: [
Expressions.literal,
[0, 2]
],
iconImage: "images/mapbox_circle_marker.png",
iconSize: 2,
iconAllowOverlap: true,
textAllowOverlap: true,
textColor: '#000000',
textHaloBlur: 1,
),
filter: [
'!',
['has', 'point_count']
],
enableInteraction: true,
);
await controller.addLayer(
"poi",
"poi-count",
const SymbolLayerProperties(
textField: [Expressions.get, 'point_count_abbreviated'],
textFont: ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
textSize: 12,
));
}
'
1条答案
按热度按时间qacovj5a1#
您需要在整个Map上注册一个
OnTapListener
,并查询Map上的所有要素。在
_clickMap
中,您可以查询Map上显示的所有内容,并根据返回的结果决定要做什么。在这里,我放大到下一个集群步骤。请记住,目前sdk中存在一个已确认的bug。OnTapListener
不是返回的ScreenCoordinates
,而是地理坐标。因此,您需要首先使用pixelForCoordinate
转换它们。希望能有所帮助:)