We needed to display the numbers on our map based on a chosen locale. I found the "number-format" style specifications on the Mapbox documentation. Since I can't seem to find a custom function for number formatting, the approach was to use MGL_FUNCTION using "number-format". So I've been on this problem for more than a day now.
Here are the once I have tried
let locale: [String: Any] = ["locale": "en", "min-fraction-digits": 1, "max-fraction-digits": 1]
let jsonData = try? JSONSerialization.data(withJSONObject: locale, options: [])
let jsonString = String(data: jsonData!, encoding: .utf8)!
// Use json string
let formattedNumber = NSExpression(format: "MGL_FUNCTION('number-format', CAST(value, 'NSNumber'), %@)", jsonString)
// Use dictionary
let formattedNumber = NSExpression(format: "MGL_FUNCTION('number-format', CAST(value, 'NSNumber'), %@)", locale)
// Use style specs "object" json string
let object = NSExpression(mglJSONObject: ["object", jsonString])
let formattedNumber = NSExpression(format: "MGL_FUNCTION('number-format', CAST(value, 'NSNumber'), %@)", object)
// Use style specs "object" dictionary
let object = NSExpression(mglJSONObject: ["object", locale])
let formattedNumber = NSExpression(format: "MGL_FUNCTION('number-format', CAST(value, 'NSNumber'), %@)", object)
All of which returns 'Invalid property value: [1][2]: Number-format options argument must be an object.'
Hope anyone would be able to point out what I am doing wrong and the correct syntax/object format to pass for the "number-format" style specifications.
Thanks!