mapbox / mapbox/mapbox-maps-ios

NumberFormatOptions is ignored after updateLayer is called

Open
#2,044 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## 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:
```swift
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 = 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Swift example with Style.updateLayer, SymbolLayer visibility, and NumberFormatOptions. Inspect how the layer update handles the number-format expression; done means the price remains formatted and concatenated after visibility changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.