Skip to content

Commit 3d91b07

Browse files
RD-1432: Update examples
1 parent f40f11a commit 3d91b07

8 files changed

+57
-10
lines changed

Examples/BasicMapView+SwiftUI.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ struct BasicMapView: View {
1818

1919
@State private var mapView = MTMapView(options: MTMapOptions(zoom: Constants.defaultZoomLevel))
2020

21+
// Note: Best practice is to set the API key at app startup (App/Scene or AppDelegate).
22+
// It's set here for standalone copy-paste convenience.
23+
init() {
24+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
25+
}
26+
2127
var body: some View {
2228
MTMapViewContainer(map: mapView) {}
2329
.referenceStyle(referenceStyle)

Examples/BasicMapViewController+UIKit.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ class BasicMapViewController: UIViewController {
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
20-
20+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
2121
initializeMapView()
2222
}
2323

2424
private func initializeMapView() {
25-
let options = MTMapOptions(center: Constants.unterageriCoordinates, zoom: Constants.defaultZoomLevel, bearing: 1.0, pitch: 20.0)
25+
let options = MTMapOptions(
26+
center: Constants.unterageriCoordinates,
27+
zoom: Constants.defaultZoomLevel,
28+
bearing: 1.0,
29+
pitch: 20.0
30+
)
2631
mapView = MTMapView(frame: view.frame, options: options, referenceStyle: .basic)
2732
mapView.delegate = self
2833

Examples/Clustering+SwiftUI.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ struct ClusteringSwiftUIExample: View {
1717
private let clusterCountLayerId = "clusterCount"
1818
private let unclusteredLayerId = "unclusteredPoint"
1919

20+
// Note: Best practice is to set the API key at app startup (App/Scene or AppDelegate).
21+
// It's set here for standalone copy-paste convenience.
22+
init() {
23+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
24+
}
25+
2026
var body: some View {
2127
MTMapViewContainer(map: mapView) {
2228
// Add clustered source via DSL so it exists before layers are added.

Examples/Clustering+UIKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ClusteringUIKitExampleViewController: UIViewController {
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
20-
20+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
2121
let options = MTMapOptions(center: CLLocationCoordinate2D(latitude: 20, longitude: 0), zoom: 0.3)
2222
mapView = MTMapView(frame: view.bounds, options: options, referenceStyle: .dataviz, styleVariant: .dark)
2323
view.addSubview(mapView)

Examples/MarkersAndPopups+SwiftUI.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ struct MarkersAndPopupsMapView: View {
2020

2121
@State private var mapView = MTMapView(options: MTMapOptions(zoom: Constants.defaultZoomLevel))
2222

23+
// Note: Best practice is to set the API key at app startup (App/Scene or AppDelegate).
24+
// It's set here for standalone copy-paste convenience.
25+
init() {
26+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
27+
}
28+
2329
var body: some View {
2430
MTMapViewContainer(map: mapView) {
2531
let unterageriPopup = MTTextPopup(coordinates: unterageriCoordinates, text: "MapTiler", offset: 20.0)

Examples/MarkersAndPopups+UIKit.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ class MarkersAndPopupsMapViewController: UIViewController {
2626

2727
override func viewDidLoad() {
2828
super.viewDidLoad()
29-
29+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
3030
initializeMapView()
3131
}
3232

3333
private func initializeMapView() {
34-
let options = MTMapOptions(center: Constants.unterageriCoordinates, zoom: Constants.defaultZoomLevel, bearing: 1.0, pitch: 20.0)
34+
let options = MTMapOptions(
35+
center: Constants.unterageriCoordinates,
36+
zoom: Constants.defaultZoomLevel,
37+
bearing: 1.0,
38+
pitch: 20.0
39+
)
3540
mapView = MTMapView(frame: view.frame, options: options, referenceStyle: .basic)
3641
mapView.delegate = self
3742

Examples/SourcesAndLayers+SwiftUI.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ struct SourcesAndLayersMapView: View {
1616
let contoursSourceID = "contoursSource"
1717
let airportsSourceID = "airportsSource"
1818

19-
let contoursTilesURL = URL(string: "https://api.maptiler.com/tiles/contours-v2/{z}/{x}/{y}.pbf?key=YOUR_API_KEY") ?? URL.documentsDirectory
19+
let contoursTilesURL = URL(
20+
string: "https://api.maptiler.com/tiles/contours-v2/{z}/{x}/{y}.pbf?key=YOUR_API_KEY"
21+
) ?? URL.documentsDirectory
2022

2123
@State private var referenceStyle: MTMapReferenceStyle = .basic
2224
@State private var styleVariant: MTMapStyleVariant? = .defaultVariant
2325

2426
@State private var mapView = MTMapView(options: MTMapOptions(zoom: Constants.defaultZoomLevel))
2527

28+
// Note: Best practice is to set the API key at app startup (App/Scene or AppDelegate).
29+
// It's set here for standalone copy-paste convenience.
30+
init() {
31+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
32+
}
33+
2634
var body: some View {
2735
MTMapViewContainer(map: mapView) {
2836
MTVectorTileSource(identifier: contoursSourceID, tiles: [contoursTilesURL])

Examples/SourcesAndLayers+UIKit.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ class SourcesAndLayersMapViewController: UIViewController {
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
20-
20+
Task { await MTConfig.shared.setAPIKey("YOUR_API_KEY") }
2121
initializeMapView()
2222
}
2323

2424
private func initializeMapView() {
25-
let options = MTMapOptions(center: Constants.unterageriCoordinates, zoom: Constants.defaultZoomLevel, bearing: 1.0, pitch: 20.0)
25+
let options = MTMapOptions(
26+
center: Constants.unterageriCoordinates,
27+
zoom: Constants.defaultZoomLevel,
28+
bearing: 1.0,
29+
pitch: 20.0
30+
)
2631
mapView = MTMapView(frame: view.frame, options: options, referenceStyle: .basic)
2732
mapView.delegate = self
2833

@@ -34,11 +39,17 @@ class SourcesAndLayersMapViewController: UIViewController {
3439
return
3540
}
3641

37-
if let contoursTilesURL = URL(string: "https://api.maptiler.com/tiles/contours-v2/{z}/{x}/{y}.pbf?key=YOUR_API_KEY") {
42+
if let contoursTilesURL = URL(
43+
string: "https://api.maptiler.com/tiles/contours-v2/{z}/{x}/{y}.pbf?key=YOUR_API_KEY"
44+
) {
3845
let contoursDataSource = MTVectorTileSource(identifier: "contoursSource", tiles: [contoursTilesURL])
3946
style.addSource(contoursDataSource)
4047

41-
let contoursLayer = MTLineLayer(identifier: "contoursLayer", sourceIdentifier: contoursDataSource.identifier, sourceLayer: "contour_ft")
48+
let contoursLayer = MTLineLayer(
49+
identifier: "contoursLayer",
50+
sourceIdentifier: contoursDataSource.identifier,
51+
sourceLayer: "contour_ft"
52+
)
4253
contoursLayer.color = .brown
4354
contoursLayer.width = 2.0
4455

0 commit comments

Comments
 (0)