MapBox water/land detection

耗尽温柔 提交于 2019-12-05 02:42:52

问题


I am starting to use the MapBox iOS SDK.

Is there any possible way to query the MapView by a coordinate and get back the terrain-type (water, land) as a result?

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.

I am not bound to MapBox (but I like it) though, thank you for any hint!


回答1:


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.




回答2:


It seems to be possible:

Found on https://www.mapbox.com/ios-sdk/api/3.5.0/runtime-styling.html

There is the possibility of adapting the UI according to the position of the user (park, city, water, etc.) Unfortunately I don't know how! (will update as soon as I find out)

Map interactivity You can customize the map to the point of having it respond dynamically based on the actions your users are taking. Increase the text size of streets while a user is driving, emphasize points of interest tailored to a user’s preferences, or change your UI if users are at parks, trails, landmarks, or rivers.

UI GIF demo




回答3:


I made a sample code that can help you a little bit. https://github.com/P0nj4/Coordinates-on-water-or-land

giving a coordinate, the app checks with google if it's land or water.



来源:https://stackoverflow.com/questions/19775585/mapbox-water-land-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!