-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature querying methods should return Turf.Feature, not MapboxCommon.Feature #526
Comments
I was confused by this, as well. My GeoJSON source is a feature collection created from an array of Turf.Feature objects. But when querying for the rendered feature that was tapped on, I'm getting back an array of QueriedFeature which use instances of MapboxCommon.Feature. I was trying to cast MapboxCommon.Feature to Turf.Feature or to be able to init Turf.Feature using MapboxCommon.Feature but couldn't get either to work. |
I ran into the same issue so a workaround I used was something Mapbox's 'internal' code does: mapbox-maps-ios/Sources/MapboxMaps/Foundation/Extensions/Turf/Geometry.swift Lines 8 to 20 in 453577d
So for example, in my application I need access to the feature's geometry type however, mapbox's feature only returns an integer and I'd prefer a more readable format i.e., a String which Turf provides. I created a function: // Convert from Mapbox geometry type to Turfs
static func convertGeometryType(geometry: MapboxMaps.GeometryType) -> Turf.GeometryType? {
switch geometry {
case GeometryType_Point:
return Turf.GeometryType.Point
// ... You get the gist
} Hope that helps @bmt2018 Anyway, I think there should be more consistency in the querying methods to prevent from having to do workarounds like this. And by consistency what I mean is that some functionality relies on Turf.Feature whereas some on Mapbox's feature. |
@nbieniek Thank you for the suggestion! I ended up doing something very similar as a workaround for now. I also hope that they'll make this more consistent in a future build of the SDK. |
We plan to do this by refining FeatureExtensionValue.featureCollection and QueriedFeature.feature so that their types are Turf types instead of the current MBXFeature-based types. |
MapboxMap’s feature querying methods’ callbacks should accept
Turf.Feature
s as arguments, notMapboxCommon.Feature
s. Otherwise, there’s no way for the developer to work with the results in other Mapbox products such as MapboxDirections or MapboxNavigation.mapbox-maps-ios/Sources/MapboxMaps/Foundation/MapboxMap.swift
Lines 379 to 381 in c622444
At a glance, it seems like the code would simply need to map the results to this convenience initializer:
mapbox-maps-ios/Sources/MapboxMaps/Foundation/Extensions/Turf/Feature.swift
Line 11 in c622444
/cc @mapbox/maps-ios @ZiZasaurus @mapbox/navigation-ios
The text was updated successfully, but these errors were encountered: