Skip to content

Commit

Permalink
[CP] v11 snapshotter tilecover (#1649)
Browse files Browse the repository at this point in the history
* Remove broken test exclusion reference

* Adopt telemetry changes from CommonSDK

* Adopt download status changes from CommonSDK

* Update Core snapshot to the latest available version

* Expose tilecover on Snapshotter

* Add changelog entry

* Update mapbox-maps-ios/CHANGELOG.md

Co-authored-by: Patrick Leonard <[email protected]>

---------

Co-authored-by: Patrick Leonard <[email protected]>
  • Loading branch information
evil159 and pjleonard37 authored Jul 14, 2023
1 parent fb7b7d9 commit e8bd444
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions mapbox-maps-ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Mapbox welcomes participation and contributions from everyone.
* Introduce experimental `BackgroundLayer/backgroundEmissiveStrength`, `CircleLayer/circleEmissiveStrength`, `FillLayer/fillEmissiveStrength`, `LineLayer/lineEmissiveStrength`, `SymbolLayer/iconEmissiveStrength`, `SymbolLayer/textEmissiveStrength`, `ModelLayer/modelEmissiveStrength`, `ModelLayer/modelRoughness`, `ModelLayer/modelHeightBasedEmissiveStrengthMultiplier` APIs.
* Introduce experimental `FillExtrusionLayer/fillExtrusionAmbientOcclusionWallRadius`, `FillExtrusionLayer/fillExtrusionAmbientOcclusionGroundRadius`, `FillExtrusionLayer/fillExtrusionAmbientOcclusionGroundAttenuation`, `FillExtrusionLayer/fillExtrusionFloodLightColor`, `FillExtrusionLayer/fillExtrusionFloodLightIntensity`, `FillExtrusionLayer/fillExtrusionFloodLightWallRadius`, `FillExtrusionLayer/fillExtrusionFloodLightGroundRadius`, `FillExtrusionLayer/fillExtrusionFloodLightGroundAttenuation`, `FillExtrusionLayer/fillExtrusionVerticalScale` APIs.
* Rename `Viewport` to `ViewportManager`.
* Add experimental `tileCover` method to the `Snapshotter` that returns tile ids covering the map.

## 11.0.0-alpha.2 - 21 June, 2023

Expand Down
14 changes: 13 additions & 1 deletion mapbox-maps-ios/Sources/MapboxMaps/Snapshot/Snapshotter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal protocol MapSnapshotterProtocol: StyleManagerProtocol {
pitch: NSNumber?) -> MapboxCoreMaps.CameraOptions

func coordinateBoundsForCamera(forCamera camera: MapboxCoreMaps.CameraOptions) -> CoordinateBounds
func __tileCover(for options: MapboxCoreMaps.TileCoverOptions, cameraOptions: MapboxCoreMaps.CameraOptions?) -> [CanonicalTileID]
}

extension MapSnapshotter: MapSnapshotterProtocol {}
Expand All @@ -36,7 +37,7 @@ extension MapSnapshotter: MapSnapshotterProtocol {}
/// You can configure the final result via ``MapSnapshotOptions`` upon construction time and take.
public class Snapshotter: StyleManager {

/// Internal `MapboxCoreMaps.MBXMapSnapshotter` object that takes care of
/// Internal `MapboxCoreMaps.MBMMapSnapshotter` object that takes care of
/// rendering a snapshot.
internal let mapSnapshotter: MapSnapshotterProtocol

Expand Down Expand Up @@ -306,6 +307,17 @@ public class Snapshotter: StyleManager {
bearing: bearing?.NSNumber,
pitch: pitch?.NSNumber))
}

/// Returns array of tile identifiers that cover current map camera.
///
/// - Parameters:
/// - options: Options for the tile cover method.
@_spi(Experimental)
public func tileCover(for options: TileCoverOptions) -> [CanonicalTileID] {
mapSnapshotter.__tileCover(
for: MapboxCoreMaps.TileCoverOptions(options),
cameraOptions: nil)
}
}

// MARK: - Snapshotter Event handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class TileCoverIntegrationTests: MapViewIntegrationTestCase {
}

func testTileCoverDefaultParameters() throws {
throw XCTSkip("Default value resolution will be fixed in MAPSNAT-1024")
mapView.mapboxMap.setCamera(to: CameraOptions(zoom: 5.5))
let tileIds = mapView.mapboxMap.tileCover(for: TileCoverOptions())
XCTAssertFalse(tileIds.isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ final class MockMapSnapshotter: MockStyleManager, MapSnapshotterProtocol {
func coordinateBoundsForCamera(forCamera camera: MapboxCoreMaps.CameraOptions) -> CoordinateBounds {
coordinateBoundsForCameraStub.call(with: camera)
}

struct TileCoverParams {
var options: MapboxCoreMaps.TileCoverOptions
var cameraOptions: MapboxCoreMaps.CameraOptions?
}
var tileCoverStub = Stub<TileCoverParams, [CanonicalTileID]>(defaultReturnValue: [])
func __tileCover(for options: MapboxCoreMaps.TileCoverOptions, cameraOptions: MapboxCoreMaps.CameraOptions?) -> [CanonicalTileID] {
tileCoverStub.call(with: TileCoverParams(options: options, cameraOptions: cameraOptions))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import MapboxMaps
@_spi(Experimental) @testable import MapboxMaps
@_implementationOnly import MapboxCoreMaps_Private
@_implementationOnly import MapboxCommon_Private
import CoreLocation
Expand Down Expand Up @@ -229,4 +229,22 @@ final class SnapshotterTests: XCTestCase {
XCTAssertIdentical(sourceAddedStub.invocations[0].parameters, sourceAdded1)
XCTAssertIdentical(sourceAddedStub.invocations[1].parameters, sourceAdded2)
}

func testTileCover() throws {
let stubReturnTileIDs = [CanonicalTileID(z: 3, x: 5, y: 7)]

let options = TileCoverOptions(tileSize: 512, minZoom: 4, maxZoom: 8, roundZoom: true)
mockMapSnapshotter.tileCoverStub.returnValueQueue.append(stubReturnTileIDs)

let tileIDs = snapshotter.tileCover(for: options)
XCTAssertEqual(stubReturnTileIDs, tileIDs)

let coreOptions = MapboxCoreMaps.TileCoverOptions(options)
let parameters = try XCTUnwrap(mockMapSnapshotter.tileCoverStub.invocations.first?.parameters)

XCTAssertEqual(parameters.options.maxZoom?.uint8Value, options.maxZoom)
XCTAssertEqual(parameters.options.minZoom?.uint8Value, options.minZoom)
XCTAssertEqual(parameters.options.roundZoom?.boolValue, options.roundZoom)
XCTAssertEqual(parameters.options.tileSize?.uint16Value, options.tileSize)
}
}

0 comments on commit e8bd444

Please sign in to comment.