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!
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.
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
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.