简体   繁体   English

在 iOS 上的 Mapbox 地图中检测标签上的点击

[英]Detect tap on a label in Mapbox map on iOS

I'd like to know if there is a way to best detect a users tap on a label?我想知道是否有一种方法可以最好地检测用户点击标签? The new iOS15 Maps app allows a tap on eg a cities name and then shows informations about that city.新的 iOS15 地图应用程序允许点击例如城市名称,然后显示有关该城市的信息。 I am now wondering if something similar can be done with mapbox?我现在想知道是否可以用 mapbox 做类似的事情?

I know that there is a mapView.visibleFeatures(in: myRect) function that can somehow help here.我知道有一个mapView.visibleFeatures(in: myRect)函数可以在这里提供帮助。 So I can convert my finger location to a rect and then get all features there.所以我可以将我的手指位置转换为矩形,然后在那里获取所有特征。 BUT... my city eg might have a label that is let's say 200 px wide.但是...我的城市例如可能有一个标签,比如说 200 像素宽。 So I would need to have a quite large rect to find the point of my city label.所以我需要一个相当大的矩形来找到我的城市标签的点。 And then I will also get all kinds of other labels that might be there.然后我还会得到可能存在的各种其他标签。 Maybe even not visible, but in the dataset.甚至可能不可见,但在数据集中。

Is there no way to ask the map what the frontmost element was when I tapped?有没有办法在我点击时询问地图最前面的元素是什么? So that when I tap on the far end of the label, I still get that ONE feature?所以当我点击标签的远端时,我仍然可以获得那个 ONE 功能?

I am still using Mapbox V6.3... the latest before their last major update.我仍在使用 Mapbox V6.3……他们最后一次重大更新之前的最新版本。 But if it's not possible with that version, an answer about the latest V10.something would also be great.但是,如果该版本不可能,关于最新的 V10.something 的答案也会很棒。

For v10, this example demonstrates how to identify features near a click.对于 v10,此示例演示了如何识别点击附近的特征。 While the overall example is to a different end, the onMapClick functions shows the method to find a feature and then build an annotation.虽然整个示例的目的有所不同,但onMapClick函数显示了查找要素然后构建注释的方法。

https://docs.mapbox.com/ios/maps/examples/view-annotation-marker/ https://docs.mapbox.com/ios/maps/examples/view-annotation-marker/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM