3

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!

Community
  • 1
  • 1
thomas
  • 2,580
  • 1
  • 22
  • 28

3 Answers3

2

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.

François Legras
  • 308
  • 2
  • 12
1

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

François Legras
  • 308
  • 2
  • 12
0

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.

Ponja
  • 663
  • 1
  • 8
  • 15
  • Thanks for your input, but a necessary feature of this mechanism is the offline usage, since this will be used on a sailboat where a fast enough internet connection is not provided to implement a routing algorithm against a webservice. I actually implemented it with OSM data. It works easily, in memory, and super fast. See my link in my above answer. – thomas Dec 16 '13 at 22:41