-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MAPSIOS-1095] Expose missing MapView APIs in SwiftUI (#2074)
- Loading branch information
1 parent
5430c84
commit f8075af
Showing
13 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Apps/Examples/Examples/SwiftUI Examples/SnapshotMapExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import SwiftUI | ||
@_spi(Experimental) import MapboxMaps | ||
|
||
@available(iOS 13.0, *) | ||
struct SnapshotMapExample: View { | ||
@State var image: UIImage? | ||
|
||
var body: some View { | ||
GeometryReader { geometry in | ||
VStack(spacing: 10) { | ||
MapReader { proxy in | ||
Map(initialViewport: .helsinkiOverview) | ||
.mapStyle(.outdoors) | ||
.onMapIdle { _ in image = proxy.captureSnapshot() } | ||
.frame(height: geometry.size.height / 2) | ||
} | ||
|
||
SnapshotView(snapshot: image) | ||
.frame(height: geometry.size.height / 2) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
struct SnapshotView: View { | ||
var snapshot: UIImage? | ||
|
||
var body: some View { | ||
if let snapshot { | ||
Image(uiImage: snapshot) | ||
} else { | ||
EmptyView() | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
private extension Viewport { | ||
static let helsinkiOverview = Self.overview(geometry: Polygon(center: .helsinki, radius: 10000, vertices: 30)) | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
struct SnapshotMapExample_Preview: PreviewProvider { | ||
static var previews: some View { | ||
SnapshotMapExample() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters