It should be possible to use D3.js-style blocks/callbacks for representing functions in data-driven styling.
I imagine this might be less performant than static functions since core would have to call back to platform code for every feature rendered, but would be more powerful for defining arbitrary interpolation functions as well as make custom mappings and data joins much easier.
A example in Swift: MGLStyleFunction(withBlock: (feature: MGLFeature, zoomLevel: Double) -> MGLStyleValue)
let highlightedFeatures = Set<String>()
circleLayer.circleColor = MGLStyleFunction(withBlock: { (feature, zoomLevel) in
let attr = feature.attributes
if highlightedFeatures.contains(attr["osm_id"]) {
return MGLStyleValue(rawValue: UIColor.gold)
}
if attr["category"] == "restaurant" {
return MGLStyleValue(rawValue: UIColor.green)
}
return MGLStyleValue(rawValue: UIColor.blue)
})
symbolLayer.textFontSize = MGLStyleFunction(withBlock: { (feature, zoomLevel) in
let size = round(9.0 + 2 * log10(feature.attributes["score"] as! Double + 1))
return MGLStyleValue(rawValue: size)
})
This has been discussed before for JS in the following tickets: mapbox/mapbox-gl-style-spec#47, mapbox/mapbox-gl-function#28
Arbitrary function callbacks aren't possible in JS per @lucaswoj because modified styles need to be serialized to JSON so that they can be transferred to worker threads.
In gl-native, we shouldn't have this limitation.
/cc @jfirebaugh @boundsj @1ec5
It should be possible to use D3.js-style blocks/callbacks for representing functions in data-driven styling.
I imagine this might be less performant than static functions since core would have to call back to platform code for every feature rendered, but would be more powerful for defining arbitrary interpolation functions as well as make custom mappings and data joins much easier.
A example in Swift:
MGLStyleFunction(withBlock: (feature: MGLFeature, zoomLevel: Double) -> MGLStyleValue)This has been discussed before for JS in the following tickets: mapbox/mapbox-gl-style-spec#47, mapbox/mapbox-gl-function#28
Arbitrary function callbacks aren't possible in JS per @lucaswoj because modified styles need to be serialized to JSON so that they can be transferred to worker threads.
In gl-native, we shouldn't have this limitation.
/cc @jfirebaugh @boundsj @1ec5