-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to add slots at runtime (#2112)
- Loading branch information
1 parent
65ddb4a
commit e44697a
Showing
11 changed files
with
345 additions
and
9 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
64 changes: 64 additions & 0 deletions
64
Apps/Examples/Examples/All Examples/RuntimeSlotsExample.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,64 @@ | ||
import UIKit | ||
@_spi(Experimental) import MapboxMaps | ||
|
||
/// This example shows how to use a slot from the Standard style and use another custom slot added at runtime | ||
/// to split the former into two parts. | ||
@available(iOS 13.0, *) | ||
final class RuntimeSlotsExample: UIViewController, ExampleProtocol { | ||
private var mapView: MapView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
mapView = MapView(frame: view.bounds) | ||
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
view.addSubview(mapView) | ||
|
||
let square = Polygon(center: .berlin, radius: 1000, vertices: 4) | ||
let triangle = Polygon(center: .berlin.coordinate(at: 800, facing: 320), radius: 700, vertices: 3) | ||
|
||
mapView.mapboxMap.setMapStyleContent { | ||
GeoJSONSource(id: "square-data") | ||
.data(.feature(Feature(geometry: square))) | ||
|
||
/// The MapStyleContent defines the desired layers positions. | ||
/// ``` | ||
/// ... bottom layers ... | ||
/// "middle" slot | ||
/// - "annotation-placeholder" slot | ||
/// - "polygon" layer | ||
/// ... top layers layers ... | ||
/// ``` | ||
SlotLayer(id: "annotation-placeholder") | ||
.slot(.middle) | ||
FillLayer(id: "square", source: "square-data") | ||
.fillColor(.systemPink) | ||
.fillOpacity(0.8) | ||
.slot(.middle) | ||
} | ||
|
||
/// The annotation uses slot `annotation-placeholder` so it will be rendered below the polygon: | ||
/// ``` | ||
/// ... bottom layers ... | ||
/// "middle" slot | ||
/// - triangle annotation | ||
/// - "annotation-placeholder" slot | ||
/// - "square" layer | ||
/// ... top layers layers ... | ||
/// ``` | ||
/// If any other layers or annotations added to the `annotation-placeholder` slot, they will appear above the triangle annotation, but below the square layer. | ||
let manager = mapView.annotations.makePolygonAnnotationManager() | ||
manager.slot = "annotation-placeholder" | ||
manager.annotations = [ | ||
PolygonAnnotation(polygon: triangle).fillColor(StyleColor(.yellow)) | ||
] | ||
|
||
mapView.mapboxMap.setCamera(to: CameraOptions(center: .berlin, zoom: 12)) | ||
} | ||
|
||
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 |
---|---|---|
|
@@ -25,4 +25,5 @@ | |
- ``CustomLayerHost`` | ||
- ``ElevationData`` | ||
- ``Slot`` | ||
- ``SlotLayer`` | ||
- ``LayerAtPosition`` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
49 changes: 49 additions & 0 deletions
49
...s/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SlotLayerIntegrationTests.swift
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.