MapBox水/土地检测 [英] MapBox water/land detection
问题描述
我开始使用 MapBox iOS SDK 。
有没有办法通过坐标查询MapView并返回地形类型(水,土地)?
我一直在阅读 API doc 已经有一段时间了,但无法弄清楚。
我知道有(临时)解决方案可以使用谷歌网络服务,但我需要这个离线工作。
I've been reading the API doc for quite a while now, but could not figure it out. I know that there are (interim) solutions available to use a Google webservice, but I need this to work offline.
我没有绑定MapBox(但我喜欢它)虽然,谢谢你的暗示!
I am not bound to MapBox (but I like it) though, thank you for any hint!
推荐答案
无需深入研究运行时样式(参见我的其他答案,假导致):使用<$ c $的非常简单的方法c> mapView.visibleFeatures(at:CGPoint,styleLayerIdentifiers:Set< String>)等效的javascript API是 queryRenderedFeatures
。
No need to delve into runtime styling (see my other answer, false lead): very simple method using mapView.visibleFeatures(at: CGPoint, styleLayerIdentifiers: Set<String>)
equivalent for javascript API is queryRenderedFeatures
.
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool)
{
let features = mapView.visibleFeatures(at: mapView.center, styleLayerIdentifiers: ["water"])
print(features)
}
四处移动时的输出示例:
Example output when moving around:
[]
[]
[]
[<MGLMultiPolygonFeature: 0x170284650>]
如果结果为空:没有水,如果是多边形:水。
If empty result: no water, if polygon: water.
这篇关于MapBox水/土地检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!