Skip to content

Commit

Permalink
Allow to add slots at runtime (#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
persidskiy authored Apr 17, 2024
1 parent 65ddb4a commit e44697a
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 9 deletions.
20 changes: 12 additions & 8 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
C953F022C91FCA59CFF06BE9 /* SymbolClusteringExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FD38B8D20C0695A03AE4E68 /* SymbolClusteringExample.swift */; platformFilters = (ios, ); };
CA2209956E93ECB18C4C9DEC /* CircleAnnotationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1658938A5F0908D151A9B9 /* CircleAnnotationExample.swift */; platformFilters = (ios, ); };
CBCC60FF68BE9754DE0C6AF3 /* DynamicStylingExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61CC711054A032EE0446036 /* DynamicStylingExample.swift */; };
CBD01BBA4E78796827A6E52D /* RuntimeSlotsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AB4D202692A8951BAF2D57 /* RuntimeSlotsExample.swift */; platformFilters = (ios, ); };
CF5C5513D659D4981706DDEC /* ViewAnnotationAnimationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E5647315A2357320BCF575 /* ViewAnnotationAnimationExample.swift */; platformFilters = (ios, ); };
D27F0573360A7234BCF7AB6C /* AnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC8E7B565C817D872CFBCAD /* AnnotationView.swift */; platformFilters = (ios, ); };
D4FFFAE49D4B805BDA014AAD /* BasicMapExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 257F10278F5E580C7ABA5570 /* BasicMapExample.swift */; platformFilters = (ios, ); };
Expand Down Expand Up @@ -217,6 +218,7 @@
62DA0608D44DEF6C4A82777C /* LocateMeExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocateMeExample.swift; sourceTree = "<group>"; };
640198169EEDFC7CBEFCFCCF /* StandardStyleImportExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardStyleImportExample.swift; sourceTree = "<group>"; };
65535FB9F190778001AB847A /* MapScrollExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapScrollExample.swift; sourceTree = "<group>"; };
65AB4D202692A8951BAF2D57 /* RuntimeSlotsExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuntimeSlotsExample.swift; sourceTree = "<group>"; };
67FA937DC17F7EA27931763A /* RasterTileSourceExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RasterTileSourceExample.swift; sourceTree = "<group>"; };
6A090EE21C9A65BE2697868F /* NavigationSimulatorExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSimulatorExample.swift; sourceTree = "<group>"; };
6BB52F9D3A810B1A9CEC832C /* Example.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -516,6 +518,7 @@
289434058C4AB25A17655FEF /* PointClusteringExample.swift */,
98D66333697502A83B85BCD9 /* RasterColorExample.swift */,
67FA937DC17F7EA27931763A /* RasterTileSourceExample.swift */,
65AB4D202692A8951BAF2D57 /* RuntimeSlotsExample.swift */,
267AA1719061B281479BBBCB /* SceneKitExample.swift */,
93B8372871DB4BC991737A06 /* SkyLayerExample.swift */,
D77368780E4DBCCFB2CBD400 /* SnapshotterCoreGraphicsExample.swift */,
Expand Down Expand Up @@ -597,32 +600,32 @@
path = Lab;
sourceTree = "<group>";
};
"TEMP_3B22CCC3-D6FC-48F0-9141-CC0AB3CBDA8B" /* All Examples */ = {
"TEMP_588CFFC1-4749-481B-BBDF-B659936E47B4" /* Sample Data */ = {
isa = PBXGroup;
children = (
);
path = "All Examples";
path = "Sample Data";
sourceTree = "<group>";
};
"TEMP_612F4B06-1BB2-450B-859E-16B56798EB12" /* SwiftUI */ = {
"TEMP_61A0AF9A-95B5-4FBE-96DA-E01092702FA7" /* iOS */ = {
isa = PBXGroup;
children = (
);
path = SwiftUI;
path = iOS;
sourceTree = "<group>";
};
"TEMP_65DC9708-DA51-4826-9E66-BF0BB7DD0378" /* iOS */ = {
"TEMP_C82D4BA9-D5D7-49FA-9898-1B62501CB97E" /* All Examples */ = {
isa = PBXGroup;
children = (
);
path = iOS;
path = "All Examples";
sourceTree = "<group>";
};
"TEMP_E0F08E73-FFA3-4E93-BDDA-E10D0C39641C" /* Sample Data */ = {
"TEMP_E73E7D7D-B57B-4230-AB47-9D04225FAD33" /* SwiftUI */ = {
isa = PBXGroup;
children = (
);
path = "Sample Data";
path = SwiftUI;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -893,6 +896,7 @@
E8CEBC697D805204F129C4FB /* RasterTileSourceExample.swift in Sources */,
191391C51FC69A6D36EB67F0 /* ResizableImageExample.swift in Sources */,
86AED5DD9F8C8BB2C9736483 /* ResizeMapViewExample.swift in Sources */,
CBD01BBA4E78796827A6E52D /* RuntimeSlotsExample.swift in Sources */,
4791CACAC0846107E4B0955B /* SceneKitExample.swift in Sources */,
F613749DCDDDDC6F041032A0 /* SimpleMapExample.swift in Sources */,
1F860D5B445E75772C4C3B6C /* SkyLayerExample.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_MAPS_CONTENT_DSL_LOGS_ENABLED"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_REOPEN_EXAMPLE"
value = "1"
Expand Down Expand Up @@ -132,6 +137,11 @@
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_MAPS_CONTENT_DSL_LOGS_ENABLED"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_REOPEN_EXAMPLE"
value = "1"
Expand Down Expand Up @@ -173,6 +183,11 @@
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_MAPS_CONTENT_DSL_LOGS_ENABLED"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "MAPBOX_REOPEN_EXAMPLE"
value = "1"
Expand Down
64 changes: 64 additions & 0 deletions Apps/Examples/Examples/All Examples/RuntimeSlotsExample.swift
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()
}
}
12 changes: 11 additions & 1 deletion Apps/Examples/Examples/Models/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,17 @@ struct Examples {
title: "Add custom raster source",
description: "Load a custom raster source to Style and display it on a map as animated weather data using RasterLayer.",
type: CustomRasterSourceExample.self),
]
] + {
if #available(iOS 13.0, *) {
return [
Example(title: "Runtime slots example",
description: "Shows shows how to use the runtime slots.",
type: RuntimeSlotsExample.self),
]
} else {
return []
}
}()

// Examples that show use cases related to user interaction with the map.
static let userInteractionExamples = [
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone.

## main
* Allow to assign slot to 2D and 3D location indicators.
* Allow to add slots at runtime.

## 11.3.0 - 10 April, 2024

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
- ``CustomLayerHost``
- ``ElevationData``
- ``Slot``
- ``SlotLayer``
- ``LayerAtPosition``
17 changes: 17 additions & 0 deletions Sources/MapboxMaps/Style/Generated/LayerWrapper.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Sources/MapboxMaps/Style/Generated/Layers/SlotLayer.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Sources/MapboxMaps/Style/LayerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public struct LayerType: ExpressibleByStringLiteral, RawRepresentable, Codable,
/// Layer representing the sky
public static let sky: LayerType = "sky"

/// Layer representing a place for other layers.
public static let slot: LayerType = "slot"

/// Layer used for a 3D model
@_documentation(visibility: public)
@_spi(Experimental)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e44697a

Please sign in to comment.