Add option to avoid specific geometries #662
Labels
blocked
Blocked by dependency or unclarity.
feature
New feature request.
jira-sync-complete
platform parity
The Directions API recently overloaded the
exclude
query parameter with an option to specify a list of point geometries in WKT format. We should add support for this syntax to serve certain use cases that require arbitrary avoidance. This would also help us achieve platform parity with the Java SDK, which implemented the feature in mapbox/mapbox-java#1362. However, it should not be implemented until the newexclude
syntax leaves beta and becomes a formal part of the API contract.Design
The overloading of
exclude
is particularly problematic for this library, which has always exposedexclude
as an option set. But now it can hold arbitrary geometry data, which needs to be typed as a Geometry. Unfortunately, an OptionSet struct can’t store associated values, so there’s no way for us to support this syntax without breaking backwards compatibility. Besides, a geometry is semantically different than a road class.mapbox-directions-swift/Sources/MapboxDirections/RouteOptions.swift
Line 57 in 2b14b8c
mapbox-directions-swift/Sources/MapboxDirections/RouteOptions.swift
Lines 152 to 157 in 2b14b8c
mapbox-directions-swift/Sources/MapboxDirections/RoadClasses.swift
Lines 3 to 6 in 2b14b8c
Perhaps this conflation in the API can be revisited in light of the semantic awkwardness that becomes apparent in Swift. Regardless, we can implement a parallel property,
shapeToAvoid
, declared as typeGeometry?
, with the expectation of being set to aMultiPoint
until more geometry types are implemented on the server side. RouteOptions’ Codable implementation can switch betweenroadClassesToAvoid
andshapeToAvoid
depending on the value. This feature depends on Turf adding support for converting between WKT and GeoJSON: mapbox/turf-swift#185.Workaround
Until we’re able to formally add support for this syntax, a developer can hook into the beta parameter themselves:
/cc @ShrayKhullarMX @Guardiola31337
The text was updated successfully, but these errors were encountered: