-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CP] MAPSIOS-1670: *-use-theme adoption (#2436)
- Loading branch information
1 parent
f9b6b36
commit afed663
Showing
57 changed files
with
1,085 additions
and
52 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
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
79 changes: 79 additions & 0 deletions
79
Sources/Examples/All Examples/Lab/ColorThemeMapExample.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,79 @@ | ||
import UIKit | ||
@_spi(Experimental) import MapboxMaps | ||
|
||
final class ColorThemeMapExample: UIViewController, ExampleProtocol { | ||
private var mapView: MapView! | ||
private var mapUseTheme = true | ||
private var circleUseTheme = true | ||
private var cancellables = Set<AnyCancelable>() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let mapInitOptions = MapInitOptions(styleURI: .streets) | ||
mapView = MapView(frame: view.bounds, mapInitOptions: mapInitOptions) | ||
|
||
view.addSubview(mapView) | ||
view.backgroundColor = .skyBlue | ||
mapView.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
mapView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), | ||
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | ||
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | ||
]) | ||
|
||
try! mapView.mapboxMap.setColorTheme(ColorTheme(uiimage: UIImage(named: "monochrome_lut")!)) | ||
addTestLayer() | ||
|
||
mapView.gestures.onMapTap.observe { _ in | ||
self.mapUseTheme.toggle() | ||
if self.mapUseTheme { | ||
try! self.mapView.mapboxMap.setColorTheme(ColorTheme(uiimage: UIImage(named: "monochrome_lut")!)) | ||
} else { | ||
try! self.mapView.mapboxMap.removeColorTheme() | ||
} | ||
} | ||
.store(in: &cancellables) | ||
|
||
mapView.gestures.onLayerTap("blue-layer") { _, _ in | ||
self.circleUseTheme.toggle() | ||
self.addTestLayer(useTheme: self.circleUseTheme) | ||
return true | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
private func addTestLayer( | ||
id: String = "blue-layer", | ||
radius: LocationDistance = 2, | ||
color: UIColor = .blue, | ||
coordinate: CLLocationCoordinate2D = .init(latitude: 40, longitude: -104), | ||
useTheme: Bool = true | ||
) { | ||
let sourceId = "\(id)-source" | ||
try? mapView.mapboxMap.removeLayer(withId: id) | ||
try? mapView.mapboxMap.removeLayer(withId: "\(id)-border") | ||
try? mapView.mapboxMap.removeSource(withId: sourceId) | ||
|
||
mapView.mapboxMap.setMapStyleContent { | ||
FillLayer(id: id, source: sourceId) | ||
.fillColorUseTheme(useTheme ? .default : .none) | ||
.fillColor(color) | ||
.fillOpacity(0.4) | ||
LineLayer(id: "\(id)-border", source: sourceId) | ||
.lineColor(color.darker) | ||
.lineColorUseTheme(useTheme ? .default : .none) | ||
.lineOpacity(0.4) | ||
.lineWidth(2) | ||
GeoJSONSource(id: sourceId) | ||
.data(.geometry(.polygon(Polygon(center: coordinate, radius: radius * 1000000, vertices: 60)))) | ||
} | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
// The below line is used for internal testing purposes only. | ||
finish() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
- ``Rain`` | ||
- ``Snow`` | ||
- ``ColorTheme`` | ||
- ``ColorUseTheme`` | ||
|
||
### Declarative Map Styling | ||
|
||
|
Oops, something went wrong.