Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapBox water/land detection

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!

like image 974
thomas Avatar asked Dec 20 '25 20:12

thomas


1 Answers

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.

like image 54
François Legras Avatar answered Dec 22 '25 10:12

François Legras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!