Closed 1ec5 closed 2 years ago
In the meantime, as a workaround, developers can use NSURLSession to connect to the API directly. The response format is suitable for passing into the map SDK’s MGLShape(data:encoding:error:)
to more easily create an MGLShapeSource, and the various feature properties can be used as attributes in paint and layout property expressions. For example, MGLLineStyleLayer.lineColor
can be set to NSExpression(format: "CAST(mgl_join({'#', fillColor}), 'UIColor')")
.
The response format is suitable for passing into the map SDK’s
MGLShape(data:encoding:error:)
to more easily create an MGLShapeSource, and the various feature properties can be used as attributes in paint and layout property expressions. For example,MGLLineStyleLayer.lineColor
can be set toNSExpression(format: "CAST(mgl_join({'#', fillColor}), 'UIColor')")
.
It’s more verbose with map SDK v10 but still possible:
URLSession.shared.dataTask(with: request) { (possibleData, possibleResponse, possibleError) in
guard let data = possibleData,
let geoJSON = try? JSONDecoder().decode(GeoJSONObject.self, data) else { return }
try? style.updateGeoJSONSource(withId: "isochrone", geoJSON: geoJSON)
var layer = LineLayer(id: "isochrone")
layer.source = "isochrone"
layer.lineColor = .expression(Exp(.color) {
Exp(.concat) {
"#"
Exp(.get) { "fillColor" }
}
})
try? style.addLayer(layer)
}
The Isochrone API requires a new top-level class alongside Directions. Some of the parameters and many of the response properties are visual in nature, reminiscent of MapboxStatic.swift or the map SDK rather than the APIs currently supported by this library, but I don’t see a need to break it out of this library for the time being as long as colors are only specified as hexadecimal triplets.
/cc @ericdeveloper