mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
469 stars 152 forks source link

ElevationData getelevationfor**(_:) from outdoors map layers does not work #2151

Open jumbopilot opened 6 months ago

jumbopilot commented 6 months ago

Map Contour lines Environment

Xcode version: Version 15.2 (15C500b) iOS version: iOS17 Devices affected: iPhone15 Maps SDK Version: 11.2.0 (same behavior with 11.1.0)

Observed behavior and steps to reproduce

Pre-condition:

Create a SwiftUI mapview using

let locationProvider = AppleLocationProvider()
var mapStyle: MapStyle = .outdoors

MapReader { proxy in
       Map(viewport: $viewport) {
             ...
        }
         .onMapLongPressGesture { context in
           // Get elevation from map
          print("Elevation: \(proxy.map?.elevation(at: locationProvider.getLastObservedLocation()!.coordinate))m, location:\(locationProvider.getLastObservedLocation()!.coordinate)")
        }
}

coordinate is a CLLocationCoordinate2D and points to a visible region on the screen.

printed elevation is always "nil' regardless whether mapstyle is set to outdoors, zoom scale and contour lines with contour line elevation (e.g. 300m) are displayed on the map.

printed message is: Elevation: nilm, location:CLLocationCoordinate2D(latitude: 34.88005051423801, longitude: 5.031331175034814)

Expected behavior

https://docs.tilestream.net/ios/maps/api/latest/documentation/mapboxmaps/mapboxmap/elevation(at:) func elevation(at coordinate: CLLocationCoordinate2D) -> Double?

return a value according the visible contour lines or other estimation method of features shown on map.

Notes / preliminary analysis

Additional layers are programmatically added in slot .middle and .top

Additional links and references

protocol ElevationData https://docs.tilestream.net/ios/maps/api/latest/documentation/mapboxmaps/elevationdata/#instance-methods

func getElevationFor(CLLocationCoordinate2D) -> NSNumber?

getelevationfor(_:) works according specification and returns the terrain elevation in m.

jumbopilot commented 6 months ago

further investigations using a separate queryRenderedFeatures() brought up results with contained features, but only when sufficiently zooming out the map to show these features. Does the getelevationfor(:) work the same way that features having any elevation data need to be displayed on the current map in order to be found? Would have expected a mechanism to search features regardless of the current display/zoom or the getelevationfor(:) to work.