You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MAPSIOS-1861 Add ability to force style reload (#7449)
## Summary
Adds `StyleReloadPolicy` to control whether a style should reload when
the URI or JSON matches the currently loaded style. This enables
developers to force style reload events even when the style hasn't
changed,
which is useful for implementations that rely on style load events
triggering consistently.
## Changes
### New
- **`StyleReloadPolicy`**: A struct with two options:
- `. onlyIfChanged ` (default): Only reloads if URI/JSON differs from
currently loaded style
- `.always`: Always reload even when URI/JSON matches the currently
loaded style
### Modified
- **`MapStyle.init(uri:configuration:reloadPolicy:)`**: Added optional
`reloadPolicy` parameter
- **`MapStyle.init(json:configuration:reloadPolicy:)`**: Added optional
`reloadPolicy` parameter
- **`MapboxMap.loadStyle(_:transition:reloadPolicy:completion:)`**:
Added optional `reloadPolicy` parameter (both URI and JSON variants)
### Implementation
- Updated `MapStyleReconciler` to check reload policy when determining
if reload is needed
- Added comprehensive test coverage with 6 new tests covering all
scenarios
Co-authored-by: Claude <noreply@anthropic.com>
GitOrigin-RevId: ad38bae56d573e3e84cc449e1100c5f09932551d
let options = MapInitOptions(mapStyle: .standardSatellite(lightPreset: .dusk))
19
19
let mapView = MapView(frame: view.bounds, mapInitOptions: options)
20
20
```
21
-
21
+
* Add `StyleReloadPolicy` to control style reload behavior. Use `reloadPolicy: .always` parameter in `loadStyle()` methods or `MapStyle` initializers to always reload the style even when the URI or JSON matches the currently loaded style. Defaults to `.onlyIfChanged` for optimal performance.
Copy file name to clipboardExpand all lines: Sources/MapboxMaps/Foundation/MapboxMap.swift
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -234,12 +234,14 @@ public final class MapboxMap: StyleManager {
234
234
/// - Parameters:
235
235
/// - styleURI: StyleURI to load
236
236
/// - transition: Options for the style transition.
237
+
/// - reloadPolicy: Controls whether the style should reload if the URI matches the currently loaded style. When `nil`, behaves as `.onlyIfChanged`. Defaults to `nil`.
237
238
/// - completion: Closure called when the style has been fully loaded.
238
239
/// If style has failed to load a `MapLoadingError` is provided to the closure.
@@ -265,12 +267,14 @@ public final class MapboxMap: StyleManager {
265
267
/// - Parameters:
266
268
/// - JSON: Style JSON string
267
269
/// - transition: Options for the style transition.
270
+
/// - reloadPolicy: Controls whether the style should reload if the JSON matches the currently loaded style. When `nil`, behaves as `.onlyIfChanged`. Defaults to `nil`.
268
271
/// - completion: Closure called when the style has been fully loaded.
269
272
/// If style has failed to load a `MapLoadingError` is provided to the closure.
/// The style reloads only when the actual ``StyleURI`` or JSON (when loaded with ``MapStyle/init(json:configuration:)`` is changed. To observe the result of the style load you can subscribe to ``MapboxMap/onStyleLoaded`` or ``Snapshotter/onStyleLoaded`` events, or use use ``StyleManager/load(mapStyle:transition:completion:)`` method.
58
+
/// By default, the style reloads only when the actual ``StyleURI`` or JSON (when loaded with ``MapStyle/init(json:configuration:reloadPolicy:)``) is changed. Use ``StyleReloadPolicy/always`` to always reload even when the URI or JSON hasn't changed.
59
+
/// To observe the result of the style load you can subscribe to ``MapboxMap/onStyleLoaded`` or ``Snapshotter/onStyleLoaded`` events, or use ``StyleManager/load(mapStyle:transition:completion:)`` method.
59
60
publicstructMapStyle:Equatable,Sendable{
60
61
enumData:Equatable,Sendable{
61
62
case uri(StyleURI)
@@ -75,20 +76,23 @@ public struct MapStyle: Equatable, Sendable {
75
76
}
76
77
vardata:Data
77
78
varconfiguration:JSONObject?
79
+
varreloadPolicy:StyleReloadPolicy?
78
80
79
81
/// Creates a map style using a Mapbox Style JSON.
80
82
///
81
83
/// Please consult [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/) describing the JSON format.
82
84
///
83
-
/// - Important: For the better performance with large local Style JSON please consider loading style from the file system via the ``MapStyle/init(uri:configuration:)`` initializer.
85
+
/// - Important: For the better performance with large local Style JSON please consider loading style from the file system via the ``MapStyle/init(uri:configuration:reloadPolicy:)`` initializer.
84
86
///
85
87
/// - Parameters:
86
88
/// - json: A Mapbox Style JSON string.
87
89
/// - configuration: Style import configuration to be applied on style load.
88
90
/// Providing `nil` configuration will make no effect and previous configuration will stay in place. In order to change previous value, you should explicitly override it with the new value.
/// - reloadPolicy: Controls whether the style should reload if the JSON matches the currently loaded style. When `nil`, behaves as `.onlyIfChanged`. Defaults to `nil`.
@@ -99,19 +103,21 @@ public struct MapStyle: Equatable, Sendable {
99
103
/// - uri: An instance of ``StyleURI`` pointing to a Mapbox Style URI (mapbox://styles/{user}/{style}), a full HTTPS URI, or a path to a local file.
100
104
/// - configuration: Style import configuration to be applied on style load.
101
105
/// Providing `nil` configuration will make no effect and previous configuration will stay in place. In order to change previous value, you should explicitly override it with the new value.
/// - reloadPolicy: Controls whether the style should reload if the URI matches the currently loaded style. When `nil`, behaves as `.onlyIfChanged`. Defaults to `nil`.
Func MapStyle.standard(theme:lightPreset:font:showPointOfInterestLabels:showTransitLabels:showPlaceLabels:showRoadLabels:showPedestrianRoads:show3dObjects:backgroundPointOfInterestLabels:colorAdminBoundaries:colorBuildingHighlight:colorBuildingSelect:colorGreenspace:colorModePointOfInterestLabels:colorMotorways:colorPlaceLabelHighlight:colorPlaceLabels:colorPlaceLabelSelect:colorPointOfInterestLabels:colorRoadLabels:colorRoads:colorTrunks:colorWater:densityPointOfInterestLabels:roadsBrightness:showAdminBoundaries:showLandmarkIconLabels:showLandmarkIcons:themeData:) has parameter 26 type change from Swift.Bool? to Swift.Double?
2206
2206
Func MapStyle.standard(theme:lightPreset:font:showPointOfInterestLabels:showTransitLabels:showPlaceLabels:showRoadLabels:showPedestrianRoads:show3dObjects:backgroundPointOfInterestLabels:colorAdminBoundaries:colorBuildingHighlight:colorBuildingSelect:colorGreenspace:colorModePointOfInterestLabels:colorMotorways:colorPlaceLabelHighlight:colorPlaceLabels:colorPlaceLabelSelect:colorPointOfInterestLabels:colorRoadLabels:colorRoads:colorTrunks:colorWater:densityPointOfInterestLabels:roadsBrightness:showAdminBoundaries:showLandmarkIconLabels:showLandmarkIcons:themeData:) has parameter 29 type change from Swift.String? to Swift.Bool?
2207
2207
Func MapStyle.standardSatellite(lightPreset:font:showPointOfInterestLabels:showTransitLabels:showPlaceLabels:showRoadLabels:showRoadsAndTransit:showPedestrianRoads:backgroundPointOfInterestLabels:colorAdminBoundaries:colorModePointOfInterestLabels:colorMotorways:colorPlaceLabelHighlight:colorPlaceLabels:colorPlaceLabelSelect:colorPointOfInterestLabels:colorRoadLabels:colorRoads:colorTrunks:densityPointOfInterestLabels:roadsBrightness:showAdminBoundaries:) has parameter 20 type change from Swift.Double? to MapboxMaps.StandardFuelingStationModePointOfInterestLabels?
2208
-
Func MapStyle.standardSatellite(lightPreset:font:showPointOfInterestLabels:showTransitLabels:showPlaceLabels:showRoadLabels:showRoadsAndTransit:showPedestrianRoads:backgroundPointOfInterestLabels:colorAdminBoundaries:colorModePointOfInterestLabels:colorMotorways:colorPlaceLabelHighlight:colorPlaceLabels:colorPlaceLabelSelect:colorPointOfInterestLabels:colorRoadLabels:colorRoads:colorTrunks:densityPointOfInterestLabels:roadsBrightness:showAdminBoundaries:) has parameter 21 type change from Swift.Bool? to Swift.Double?
2208
+
Func MapStyle.standardSatellite(lightPreset:font:showPointOfInterestLabels:showTransitLabels:showPlaceLabels:showRoadLabels:showRoadsAndTransit:showPedestrianRoads:backgroundPointOfInterestLabels:colorAdminBoundaries:colorModePointOfInterestLabels:colorMotorways:colorPlaceLabelHighlight:colorPlaceLabels:colorPlaceLabelSelect:colorPointOfInterestLabels:colorRoadLabels:colorRoads:colorTrunks:densityPointOfInterestLabels:roadsBrightness:showAdminBoundaries:) has parameter 21 type change from Swift.Bool? to Swift.Double?
2209
+
2210
+
// Add StyleReloadPolicy to control style reload behavior
2211
+
Constructor MapStyle.init(json:configuration:) has been removed
2212
+
Constructor MapStyle.init(uri:configuration:) has been removed
2213
+
Func MapboxMap.loadStyle(_:transition:completion:) has been renamed to Func loadStyle(_:transition:reloadPolicy:completion:)
2214
+
Func MapboxMap.loadStyle(_:transition:completion:) has parameter 2 type change from (((any Swift.Error)?) -> ())? to MapboxMaps.StyleReloadPolicy?
0 commit comments