mapbox-maps-ios
mapbox-maps-ios copied to clipboard
NumberFormatOptions is ignored after updateLayer is called
Environment
- Xcode version: 15
- iOS version: 17.1
- Devices affected: all
- Maps SDK Version: 10.16.1
Observed behavior and steps to reproduce
I'm using a symbol layer to show formatted text on the map, this symbol layer can be hidden or shown by the user. To hide the layer I use the updateLayer function and I change the visibility of the layer.
When the updateLayer function is called, the number format options are ignored, and the number shown is the raw value.
Here is an example code:
import Foundation
import MapboxMaps
import UIKit
class TextLayer {
static let sourceId = "my-source"
private var source = VectorSource()
private var layer = SymbolLayer(id: "layer")
init(_ style: Style, sourceUrl: String) {
self.source.url = sourceUrl
let rawLocale = Locale.current.identifier
// Sometimes the locale we get is in this format en_US@rg=frzzz
// and to make it a valid locale, we need to use only the first part before the @
let cleanedLocale = rawLocale.components(separatedBy: "@").first ?? "en-US"
let priceFormatOptions = NumberFormatOptions(locale: cleanedLocale, currency: "EUR", minFractionDigits: 2, maxFractionDigits: 2)
let textExp = Exp(.concat) {
Exp(.numberFormat) {
Exp(.get) { "price" }
priceFormatOptions
}
"/h"
}
// Add the sources to the map's style.
do {
try style.addSource(self.source, id: TextLayer.sourceId)
try style.addLayer(self.layer)
} catch {
print("Error when adding sources and layers: \(error.localizedDescription)")
}
}
func updateVisibility(visible: Bool, style: Style) {
let visibility: Value<Visibility> = visible ? .constant(.visible) : .constant(.none)
try? style.updateLayer(withId: TextLayer.parkingIconsLayerId, type: SymbolLayer.self) { (layer: inout SymbolLayer) in
layer.visibility = visibility
}
}
}
When I initialize this class, everything works correctly, the price is formatted and concatenated. But as soon as I call the updateVisibility function, the numberFormat is ignored, the concatenation is still working but all the formatting is lost.
Expected behavior
The NumberFormatOptions should be applied even after updating the visibility.
Notes / preliminary analysis
Additional links and references
Thanks for reporting this @abouroubi -- we're looking into it now.
Thanks @pjleonard37, do you have any ETA ?
Hi @abouroubi --
We do not have an ETA on this. We have a confirmed reproduction on our side and are looking into next steps on this now.