Skip to content

Commit afed663

Browse files
authored
[CP] MAPSIOS-1670: *-use-theme adoption (#2436)
1 parent f9b6b36 commit afed663

File tree

57 files changed

+1085
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1085
-52
lines changed

CHANGELOG.md

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

33
Mapbox welcomes participation and contributions from everyone.
44

5+
## main
6+
7+
* Add support for the `maxOverscaleFactorForParentTiles` property in `CustomRasterSource` and `CustomGeometrySource`, allowing greater control over tile overscaling behavior when rendering custom raster tiles.
8+
* Add support for experimental *-use-theme propert that allow to override the color theme set on the Map. This is experimental and have several limitations - currently expressions are not supported. Color properties in Lights, Rain, Snow are not supported. *-use-theme for layer applied only after zoom level change.
9+
510
## 11.10.0-beta.1 - 20 January, 2025
611

712
* 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:

Examples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
634BA74F4E553C53EE906F5A /* OfflineManagerExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 000D0E4CEFB6D5AF02518807 /* OfflineManagerExample.storyboard */; platformFilters = (ios, ); };
7171
64F4FA139388DB34564AD42D /* CLLocationCoordinate2D+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 455C0B9F01316D0FF38ED62B /* CLLocationCoordinate2D+Random.swift */; platformFilters = (ios, ); };
7272
655105BD0FAFF4C4BA65DC32 /* ExamplesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE19F00E87B31FDE5481D56 /* ExamplesTests.swift */; platformFilters = (ios, ); };
73+
65E9F2B993AEB394FC2D0080 /* ColorThemeMapExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F519EC4AF0B4BEE0FDCABC /* ColorThemeMapExample.swift */; platformFilters = (ios, ); };
7374
6661DB69D4980E24BCA18AB2 /* PolygonAnnotationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DCBE4524A8793B4DE950533 /* PolygonAnnotationExample.swift */; platformFilters = (ios, ); };
7475
68FD9E1F4606B2729BA1E6DC /* SnapshotterExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 588FD640D91E9DD366703F7B /* SnapshotterExample.swift */; platformFilters = (ios, ); };
7576
6B040F65241ABF600D70D14D /* Custom3DPuckExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C957F9CA07061B793C2DD4A /* Custom3DPuckExample.swift */; platformFilters = (ios, ); };
@@ -225,6 +226,7 @@
225226
4DCBE814694CF08A9C2E4A42 /* AddOneMarkerSymbolExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOneMarkerSymbolExample.swift; sourceTree = "<group>"; };
226227
4EE19F00E87B31FDE5481D56 /* ExamplesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExamplesTests.swift; sourceTree = "<group>"; };
227228
50618B3CF42CCF735CCAE9B4 /* fragment-realestate-NY.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "fragment-realestate-NY.json"; sourceTree = "<group>"; };
229+
50F519EC4AF0B4BEE0FDCABC /* ColorThemeMapExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorThemeMapExample.swift; sourceTree = "<group>"; };
228230
524D79FF01638A0E8A3C1248 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
229231
588FD640D91E9DD366703F7B /* SnapshotterExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotterExample.swift; sourceTree = "<group>"; };
230232
590D83805AA598D2B0A7638A /* ExamplesTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = ExamplesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -632,6 +634,7 @@
632634
F4E57BB1463BD6558C9EE37A /* Lab */ = {
633635
isa = PBXGroup;
634636
children = (
637+
50F519EC4AF0B4BEE0FDCABC /* ColorThemeMapExample.swift */,
635638
8DBF737C9C7FBF46BB5F7B78 /* CombineExample.swift */,
636639
A4EE8F38428A64B5B9D4DBBE /* CombineLocationExample.swift */,
637640
60A8CD8A69D3429FCF8ACBDD /* Lights3DExample.swift */,
@@ -859,6 +862,7 @@
859862
1DAE02D73D16E543777C2025 /* ClusteringExample.swift in Sources */,
860863
5A28C124249725578389175A /* ColorExpressionExample.swift in Sources */,
861864
DA109856E64BBD8071DF0619 /* ColorThemeExample.swift in Sources */,
865+
65E9F2B993AEB394FC2D0080 /* ColorThemeMapExample.swift in Sources */,
862866
C664365A373267B564EC84EE /* CombineExample.swift in Sources */,
863867
215230836B6AD1040D3DA547 /* CombineLocationExample.swift in Sources */,
864868
3E515D1DD1D9CA02F3E95AA2 /* Constants.swift in Sources */,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import UIKit
2+
@_spi(Experimental) import MapboxMaps
3+
4+
final class ColorThemeMapExample: UIViewController, ExampleProtocol {
5+
private var mapView: MapView!
6+
private var mapUseTheme = true
7+
private var circleUseTheme = true
8+
private var cancellables = Set<AnyCancelable>()
9+
10+
override func viewDidLoad() {
11+
super.viewDidLoad()
12+
13+
let mapInitOptions = MapInitOptions(styleURI: .streets)
14+
mapView = MapView(frame: view.bounds, mapInitOptions: mapInitOptions)
15+
16+
view.addSubview(mapView)
17+
view.backgroundColor = .skyBlue
18+
mapView.translatesAutoresizingMaskIntoConstraints = false
19+
NSLayoutConstraint.activate([
20+
mapView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
21+
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
22+
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
23+
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
24+
])
25+
26+
try! mapView.mapboxMap.setColorTheme(ColorTheme(uiimage: UIImage(named: "monochrome_lut")!))
27+
addTestLayer()
28+
29+
mapView.gestures.onMapTap.observe { _ in
30+
self.mapUseTheme.toggle()
31+
if self.mapUseTheme {
32+
try! self.mapView.mapboxMap.setColorTheme(ColorTheme(uiimage: UIImage(named: "monochrome_lut")!))
33+
} else {
34+
try! self.mapView.mapboxMap.removeColorTheme()
35+
}
36+
}
37+
.store(in: &cancellables)
38+
39+
mapView.gestures.onLayerTap("blue-layer") { _, _ in
40+
self.circleUseTheme.toggle()
41+
self.addTestLayer(useTheme: self.circleUseTheme)
42+
return true
43+
}
44+
.store(in: &cancellables)
45+
}
46+
47+
private func addTestLayer(
48+
id: String = "blue-layer",
49+
radius: LocationDistance = 2,
50+
color: UIColor = .blue,
51+
coordinate: CLLocationCoordinate2D = .init(latitude: 40, longitude: -104),
52+
useTheme: Bool = true
53+
) {
54+
let sourceId = "\(id)-source"
55+
try? mapView.mapboxMap.removeLayer(withId: id)
56+
try? mapView.mapboxMap.removeLayer(withId: "\(id)-border")
57+
try? mapView.mapboxMap.removeSource(withId: sourceId)
58+
59+
mapView.mapboxMap.setMapStyleContent {
60+
FillLayer(id: id, source: sourceId)
61+
.fillColorUseTheme(useTheme ? .default : .none)
62+
.fillColor(color)
63+
.fillOpacity(0.4)
64+
LineLayer(id: "\(id)-border", source: sourceId)
65+
.lineColor(color.darker)
66+
.lineColorUseTheme(useTheme ? .default : .none)
67+
.lineOpacity(0.4)
68+
.lineWidth(2)
69+
GeoJSONSource(id: sourceId)
70+
.data(.geometry(.polygon(Polygon(center: coordinate, radius: radius * 1000000, vertices: 60))))
71+
}
72+
}
73+
74+
override func viewDidAppear(_ animated: Bool) {
75+
super.viewDidAppear(animated)
76+
// The below line is used for internal testing purposes only.
77+
finish()
78+
}
79+
}

Sources/Examples/Models/Examples.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ struct Examples {
141141
Example(title: "Combine",
142142
description: "Shows how to use map events with Combine framework.",
143143
type: CombineExample.self)
144+
Example(title: "Color Theme Example",
145+
description: "Shows how to use color theme",
146+
type: ColorThemeMapExample.self)
144147
Example(title: "Combine location",
145148
description: "Shows how to use Combine framework to drive the location puck.",
146149
type: CombineLocationExample.self)

Sources/Examples/SwiftUI Examples/ColorThemeExample.swift

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ struct ColorThemeExample: View {
1010

1111
@State private var theme: Theme = .red
1212
@State private var panelHeight: CGFloat = 0
13+
@State private var atmosphereUseTheme = true
14+
@State private var circleUseTheme = true
1315

1416
var body: some View {
15-
Map(initialViewport: .camera(center: .init(latitude: 40.72, longitude: -73.99), zoom: 11, pitch: 45)) {
17+
Map(initialViewport: .camera(center: .init(latitude: 40.72, longitude: -73.99), zoom: 2, pitch: 45)) {
1618
switch theme {
1719
case .default:
1820
EmptyMapContent()
@@ -22,8 +24,12 @@ struct ColorThemeExample: View {
2224
ColorTheme(uiimage: monochromeTheme)
2325
}
2426

25-
/// Defines a custom layer and source to draw the border line.
26-
NYNJBorder()
27+
Atmosphere()
28+
.color(.green)
29+
.colorUseTheme(atmosphereUseTheme ? .default : .none)
30+
31+
TestLayer(id: "blue-layer", radius: 2, color: .blue, coordinate: .init(latitude: 40, longitude: -104), useTheme: circleUseTheme)
32+
2733
}
2834
.mapStyle(.streets) /// In standard style it's possible to provide custom theme using `.standard(themeData: "base64String")`
2935
.additionalSafeAreaInsets(.bottom, panelHeight)
@@ -36,6 +42,9 @@ struct ColorThemeExample: View {
3642
ColorButton(color: .red, isOn: Binding(get: { theme == .red }, set: { _, _ in theme = .red }))
3743
ColorButton(color: .secondaryLabel, isOn: Binding(get: { theme == .monochrome }, set: { _, _ in theme = .monochrome }))
3844
}
45+
46+
Toggle("Atmosphere Use Theme", isOn: $atmosphereUseTheme)
47+
Toggle("Circle Use Theme", isOn: $circleUseTheme)
3948
}
4049
.floating()
4150
}
@@ -82,33 +91,33 @@ private struct ColorButton: View {
8291
}
8392
}
8493

85-
private struct NYNJBorder: MapContent {
86-
var body: some MapContent {
87-
GeoJSONSource(id: "border")
88-
.data(.geometry(.lineString(LineString([
89-
CLLocationCoordinate2D(latitude: 40.913503418907936, longitude: -73.91912400100642),
90-
CLLocationCoordinate2D(latitude: 40.82943110786286, longitude: -73.9615887363045),
91-
CLLocationCoordinate2D(latitude: 40.75461056309348, longitude: -74.01409059085539),
92-
CLLocationCoordinate2D(latitude: 40.69522028220487, longitude: -74.02798814058939),
93-
CLLocationCoordinate2D(latitude: 40.65188756398558, longitude: -74.05655532615407),
94-
CLLocationCoordinate2D(latitude: 40.64339339389301, longitude: -74.13916853846217),
95-
]))))
94+
private struct TestLayer: MapStyleContent {
95+
var id: String
96+
var radius: LocationDistance
97+
var color: UIColor
98+
var coordinate: CLLocationCoordinate2D
99+
var useTheme: Bool
96100

97-
LineLayer(id: "border", source: "border")
98-
.lineColor(.orange)
99-
.lineWidth(8)
100-
.slot(.bottom)
101+
var body: some MapStyleContent {
102+
let sourceId = "\(id)-source"
103+
FillLayer(id: id, source: sourceId)
104+
.fillColorUseTheme(useTheme ? .default : .none)
105+
.fillColor(color)
106+
.fillOpacity(0.4)
107+
LineLayer(id: "\(id)-border", source: sourceId)
108+
.lineColor(color.darker)
109+
.lineColorUseTheme(useTheme ? .default : .none)
110+
.lineOpacity(0.4)
111+
.lineWidth(2)
112+
GeoJSONSource(id: sourceId)
113+
.data(.geometry(.polygon(Polygon(center: coordinate, radius: radius * 1000000, vertices: 60))))
101114
}
102115
}
103116

104117
private let styleURL = Bundle.main.url(forResource: "fragment-realestate-NY", withExtension: "json")!
105118
private let monochromeTheme = UIImage(named: "monochrome_lut")!
106119
private let redTheme = "iV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/6Vf+fKv0YAjAAYATACYATACIARACMARgCMABgBMAJgBMAIgBEAIwCdZuiA64AjwAgwAtxjpg6cDlztLlLA7/Pr1gueyr56/jx/5ZzUNeof9Y/6R/0zk4HGAGAAMAAYAAwABgADgAHAAGAAMAAYAAwABgADgAHQaQ4DgAGAgCPgCHiPmTqQOpC1u8gAYACMjAf5V/6Vf+XfmTrQ8l97v8Z/5X8GAAOAAcAAYAAwABgADAAGAAOAAcAAYAAwABgADIBO0xgADAAdCB0IHYgeMxkADAAdkGM7IPbf/pfuWlmj/lH/qH/UPzMZGAwABgADgAHAAGAAMAAYAAwABgADgAHAAGAAMAAYAJ3mMAAYAAg4Ao6A95jJAGAA6EDrQJfuclkj/8q/8q/8O1MHWv47Nv8xABgADAAGAAOAAcAAYAAwABgADAAGAAOAAcAAYAB0msYAYADoQOhA6ED0mMkAYADogBzbAbH/9r/YFWWN+kf9o/5R/8xkYDAAGAAMAAYAA4ABwABgADAAGAAMAAYAA4ABwABgAHSawwBgACDgCDgC3mMmA4ABoAOtA126y2WN/Cv/yr/y70wdaPnv2PzHAGAAMAAYAAwABgADgAHAAGAAMAAYAAwABgADgAHQaRoDgAGgA6EDoQPRYyYDgAGgA3JsB8T+2/9iV5Q16h/1j/pH/TOTgcEAYAAwABgADAAGAAOAAcAAYAAwABgADAAGAAPgyQ2AT4NBIB3ew5dkAAAAAElFTkSuQmCC"
107120

108-
private extension StandardTheme {
109-
static let red = StandardTheme(rawValue: "red")
110-
}
111-
112121
struct ColorThemeExample_Previews: PreviewProvider {
113122
static var previews: some View {
114123
StandardStyleImportExample()

Sources/MapboxMaps/Documentation.docc/API Catalogs/Style.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- ``Rain``
3030
- ``Snow``
3131
- ``ColorTheme``
32+
- ``ColorUseTheme``
3233

3334
### Declarative Map Styling
3435

0 commit comments

Comments
 (0)