mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

NumberFormatOptions is ignored after updateLayer is called

Open abouroubi opened this issue 1 year ago • 3 comments

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

abouroubi avatar Oct 30 '23 20:10 abouroubi

Thanks for reporting this @abouroubi -- we're looking into it now.

pjleonard37 avatar Nov 01 '23 21:11 pjleonard37

Thanks @pjleonard37, do you have any ETA ?

abouroubi avatar Nov 06 '23 11:11 abouroubi

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.

pjleonard37 avatar Nov 14 '23 00:11 pjleonard37