Skip to content

Commit bf0bb4b

Browse files
evil159pjleonard37
andauthored
Expose maxOverscaleFactorForParentTiles for custom raster source (#2421)
Co-authored-by: Patrick Leonard <[email protected]>
1 parent b495c0e commit bf0bb4b

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Mapbox welcomes participation and contributions from everyone.
44

5+
## main
6+
7+
* Added support for the `maxOverscaleFactorForParentTiles` property in `CustomRasterSource`, allowing greater control over tile overscaling behavior when rendering custom raster tiles.
8+
59
## 11.10.0-beta.1 - 20 January, 2025
610

711
* Mark `SymbolElevationReference`, `FillExtrusionBaseAlignment`, `FillExtrusionHeightAlignment`, `ModelScaleMode`, `ModelType`, `ClipLayerTypes`, `BackgroundPitchAlignment` types as Experimental. Initially they were exposed as stable by mistake. If you use them, please import `MapboxMaps` with `Experimental` SPI:

Sources/MapboxMaps/Style/CustomSources/CustomRasterSource.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,49 @@ public struct CustomRasterSource: Source, Equatable {
1919
@_documentation(visibility: public)
2020
public let options: CustomRasterSourceOptions?
2121

22+
/// When a set of tiles for a current zoom level is being rendered and some of the ideal tiles that cover the screen are not yet loaded, parent tiles could be used instead. Note that this might introduce unwanted rendering side-effects, especially for raster tiles that are overscaled multiple times. This property sets the maximum limit for how much a parent tile can be overscaled.
2223
@_documentation(visibility: public)
23-
public init(id: String, options: CustomRasterSourceOptions) {
24+
public var maxOverscaleFactorForParentTiles: UInt8?
25+
26+
@_documentation(visibility: public)
27+
public init(id: String, options: CustomRasterSourceOptions, maxOverscaleFactorForParentTiles: UInt8? = nil) {
2428
self.id = id
2529
self.options = options
30+
self.maxOverscaleFactorForParentTiles = maxOverscaleFactorForParentTiles
2631
}
2732
}
2833

2934
extension CustomRasterSource {
3035
enum CodingKeys: String, CodingKey {
3136
case id
3237
case type
38+
case maxOverscaleFactorForParentTiles = "max-overscale-factor-for-parent-tiles"
3339
}
3440

3541
/// Init from a decoder, note that the CustomRasterSourceOptions are not decodable and need to be set separately
3642
public init(from decoder: Decoder) throws {
3743
let container = try decoder.container(keyedBy: CodingKeys.self)
3844
id = try container.decode(String.self, forKey: .id)
3945
options = nil
46+
maxOverscaleFactorForParentTiles = try container.decodeIfPresent(UInt8.self, forKey: .maxOverscaleFactorForParentTiles)
4047
}
4148

4249
/// Encode, note that options will not be included
4350
public func encode(to encoder: Encoder) throws {
4451
var container = encoder.container(keyedBy: CodingKeys.self)
45-
try encodeNonVolatile(to: encoder, into: &container)
52+
53+
if encoder.userInfo[.volatilePropertiesOnly] as? Bool == true {
54+
try encodeVolatile(to: encoder, into: &container)
55+
} else if encoder.userInfo[.nonVolatilePropertiesOnly] as? Bool == true {
56+
try encodeNonVolatile(to: encoder, into: &container)
57+
} else {
58+
try encodeVolatile(to: encoder, into: &container)
59+
try encodeNonVolatile(to: encoder, into: &container)
60+
}
61+
}
62+
63+
private func encodeVolatile(to encoder: Encoder, into container: inout KeyedEncodingContainer<CodingKeys>) throws {
64+
try container.encodeIfPresent(maxOverscaleFactorForParentTiles, forKey: .maxOverscaleFactorForParentTiles)
4665
}
4766

4867
private func encodeNonVolatile(to encoder: Encoder, into container: inout KeyedEncodingContainer<CodingKeys>) throws {

Tests/MapboxMapsTests/Style/CustomSourcesIntegrationTests.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ final class CustomSourcesIntegrationTests: MapViewIntegrationTestCase {
1515
let rasterOptions = CustomRasterSourceOptions(
1616
clientCallback: CustomRasterSourceClient.fromCustomRasterSourceTileStatusChangedCallback { _, _ in }
1717
)
18+
let maxOverscaleFactorForParentTiles = UInt8(83)
1819

1920
didFinishLoadingStyle = { mapView in
20-
let source = CustomRasterSource(id: "test-source", options: rasterOptions)
21+
let source = CustomRasterSource(
22+
id: "test-source",
23+
options: rasterOptions,
24+
maxOverscaleFactorForParentTiles: maxOverscaleFactorForParentTiles
25+
)
2126

2227
// Add source
2328
do {
@@ -29,8 +34,9 @@ final class CustomSourcesIntegrationTests: MapViewIntegrationTestCase {
2934

3035
// Retrieve the source
3136
do {
32-
_ = try mapView.mapboxMap.source(withId: "test-source", type: CustomRasterSource.self)
37+
let retrievedSource = try mapView.mapboxMap.source(withId: "test-source", type: CustomRasterSource.self)
3338

39+
XCTAssertEqual(retrievedSource.maxOverscaleFactorForParentTiles, maxOverscaleFactorForParentTiles)
3440
successfullyRetrievedSourceExpectation.fulfill()
3541
} catch {
3642
XCTFail("Failed to retrieve CustomRasterSource because of error: \(error)")

scripts/api-compatibility-check/breakage_allowlist.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,4 +2062,7 @@ Constructor ViewAnnotationOptions.init(annotatedFeature:width:height:allowOverla
20622062
Func StyleManager.removeRain() is now with @_documentation
20632063
Func StyleManager.removeSnow() is now with @_documentation
20642064
Func StyleManager.setRain(_:) is now with @_documentation
2065-
Func StyleManager.setSnow(_:) is now with @_documentation
2065+
Func StyleManager.setSnow(_:) is now with @_documentation
2066+
2067+
# Add maxOverscaleFactorForParentTiles to CustomRasterSource constructor
2068+
Constructor CustomRasterSource.init(id:options:) has been removed

0 commit comments

Comments
 (0)