MapBox water/land detection

你。 提交于 2019-12-03 21:23:12

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.

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