Skip to content

Commit

Permalink
Generate typesafe annotations builders
Browse files Browse the repository at this point in the history
  • Loading branch information
persidskiy committed Apr 23, 2024
1 parent 5528f34 commit fe14476
Show file tree
Hide file tree
Showing 34 changed files with 213 additions and 245 deletions.
6 changes: 3 additions & 3 deletions Apps/Examples/Examples/All Examples/ModelLayerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final class ModelLayerExample: UIViewController, ExampleProtocol {
ModelLayer(id: "model-layer-id", source: Constants.sourceId)
.modelId(Exp(.get) { Constants.modelIdKey })
.modelType(.common3d)
.modelScale([40, 40, 40])
.modelTranslation([0, 0, 0])
.modelRotation([0, 0, 90])
.modelScale(x: 40, y: 40, z: 40)
.modelTranslation(x: 0, y: 0, z: 0)
.modelRotation(x: 0, y: 0, z: 90)
.modelOpacity(0.7)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct AnnotationsExample: View {
CircleAnnotation(centerCoordinate: airport.coordinate, isDraggable: true)
.circleColor(StyleColor(flight.color))
.circleRadius(10)
.circleStrokeColor(.init(.black))
.circleStrokeColor(.black)
.circleStrokeWidth(1)
.onTapGesture {
alert = "Airport: \(airport.name)"
Expand Down Expand Up @@ -92,7 +92,7 @@ struct AnnotationsExample: View {
PointAnnotation(coordinate: tap.coordinate)
.image(named: "intermediate-pin")
.iconAnchor(.bottom)
.iconOffset([0, 12])
.iconOffset(x: 0, y: 12)
.onTapGesture {
taps.removeAll(where: { $0.id == tap.id })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ struct ModelsComponent: MapStyleContent {
ModelLayer(id: "models", source: "models-geojson")
.modelId(Exp(.get) { "model" })
.modelType(.common3d)
.modelScale([40, 40, 40])
.modelTranslation([0, 0, 0])
.modelRotation([0, 0, 90])
.modelScale(x: 40, y: 40, z: 40)
.modelTranslation(x: 0, y: 0, z: 0)
.modelRotation(x: 0, y: 0, z: 90)
.modelOpacity(0.7)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct FeaturesQueryExample: View {
// Annotations that shows tap location.
if let queryResult = model.queryResult {
CircleAnnotation(centerCoordinate: queryResult.coordinate)
.circleColor(.init(.red))
.circleColor(.red)
.circleRadius(8)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct PuckPlayground: View {
TestLayer(id: "layer", radius: 3, color: .black, coordinate: .apple, slot: .top)

if case .d3 = puckType {
let scale = puck3dSettings.modelType.initialScale * puck3dSettings.scale
Puck3D(model: puck3dSettings.modelType.model, bearing: bearingType)
.modelScale(puck3dSettings.modelScale)
.modelScale(x: scale, y: scale, z: scale)
.modelOpacity(opacity)
.modelEmissiveStrength(puck3dSettings.emission)
.slot(slot)
Expand Down Expand Up @@ -177,7 +178,6 @@ private struct Puck3DSettings {
}
}
var scale = 1.0
var modelScale: [Double] { .init(repeating: scale * modelType.initialScale, count: 3) }
var modelType = ModelType.sportcar
var emission = 1.0
}
Expand Down
55 changes: 46 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,55 @@ Mapbox welcomes participation and contributions from everyone.
## main

### Experimental API breaking changes ⚠️
* `TransitionOptions` is now a Swift struct rather than an Objective-C class.
* Experimental `MapStyle` no longer conforms to Equatable.
* Experimental protocol `MapContent` now has associated generic type and body requirement.
* Experimental `MapContentBuilder` methods signatures have changed to work with generic `MapContent`.
* `StyleImportConfiguration` was removed from public API
* `MapStyle` now accepts single `configuration` as `JSONObject`
* `StyleImportConfiguration.standard` is no more exposed, use `MapStyle.standard()` to provide configuration for Standard style

In this release, we introduce the new [Declarative Styling API](https://docs.tilestream.net/ios/maps/api/latest/documentation/mapboxmaps/declarative-map-styling) for UIKit and SwiftUI. This change is based on `MapContent` introduced for SwiftUI; therefore, it has been restructured. The changes are compatible; however, in some rare cases, you may need to adjust your code.

* [SwiftUI] `MapContent` now supports custom implementations, similar to SwiftUI views. The `MapContent` protocol now requires the `var body: some MapContent` implementation.
* [SwiftUI] PointAnnotation and Puck3D property-setters that consumed fixed-length arrays reworked to use named properties or platform types for better readability:
```swift
// Before
PointAnnotation()
.iconOffset([10, 20]) // x, y
.iconTextFitPadding([1, 2, 3, 4]) // top, right, bottom, left
Puck3D()
.modelScale([1, 2, 3]) // x, y, z

// After
PointAnnotation()
.iconOffset(x: 10, y: 20)
.iconTextFitPadding(UIEdgeInsets(top: 1, left: 4, bottom: 3, right: 2))
Puck3D()
.modelScale(x: 1, y: 2, z: 3)
```
* `StyleImportConfiguration` was removed from public API, the `MapStyle` now contains the configuration directly.
* `TransitionOptions` is now a Swift `struct` rather than an Objective-C `class`.

### Features ✨ and improvements 🏁

* All the style primitives can now be used as `MapContent` in SwiftUI.
```swift
@_spi(Experimental) MapboxMaps
Map {
LineLayer(id: "traffic")
.lineColor(.red)
.lineWidth(2)
}
```

* UIKit applications can now use the `setMapStyleContent` to use style primitives:
```swift
@_spi(Experimental) MapboxMaps
mapView.mapboxMap.setMapStyleContent {
LineLayer(id: "traffic")
.lineColor(.red)
.lineWidth(2)
}
```

* Allow to assign slot to 2D and 3D location indicators.
* Allow observing start/stop event of `CameraAnimator`
You can observe start/stop event of `CameraAnimator` by using new `CameraAnimationsManager` APIs as shown below
```
```swift
// Observe start event of any CameraAnimator owned by AnimationOwner.cameraAnimationsManager
mapView.camera
.onCameraAnimatorStarted(with: [.cameraAnimationsManager]) { cameraAnimator in
Expand All @@ -32,7 +68,7 @@ Mapbox welcomes participation and contributions from everyone.
.store(in: &cancelables)
```
You can also observe directly on an instance of `CameraAnimator` when using low-level camera APIs to create a custom animator
```
```swift
// Declare an animator that changes the map's bearing
let bearingAnimator = mapView.camera.makeAnimator(duration: 4, curve: .easeInOut) { (transition) in
transition.bearing.toValue = -45
Expand All @@ -49,6 +85,7 @@ Mapbox welcomes participation and contributions from everyone.
* Make Puck2D and Puck3D to be positioned according to relative layer positon in declarative API instead of always top-most position.
* Add codesign for XCFrameworks.


## 11.3.0 - 10 April, 2024

### Features ✨ and improvements 🏁
Expand Down
14 changes: 13 additions & 1 deletion Sources/MapboxMaps/Annotations/Generated/CircleAnnotation.swift

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

38 changes: 31 additions & 7 deletions Sources/MapboxMaps/Annotations/Generated/PointAnnotation.swift

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

14 changes: 13 additions & 1 deletion Sources/MapboxMaps/Annotations/Generated/PolygonAnnotation.swift

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

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

8 changes: 4 additions & 4 deletions Sources/MapboxMaps/ContentBuilders/MapContent/Puck3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public struct Puck3D: MapContent, PrimitiveMapContent {

/// The scale of the model.
@_documentation(visibility: public)
public func modelScale(_ modelScale: [Double]) -> Puck3D {
copyAssigned(self, \.configuration.modelScale, .constant(modelScale))
public func modelScale(x: Double, y: Double, z: Double) -> Puck3D {
copyAssigned(self, \.configuration.modelScale, .constant([x, y, z]))
}

/// The rotation of the model in euler angles [lon, lat, z].
@_documentation(visibility: public)
public func modelRotation(_ modelRotation: [Double]) -> Puck3D {
copyAssigned(self, \.configuration.modelRotation, .constant(modelRotation))
public func modelRotation(x: Double, y: Double, z: Double) -> Puck3D {
copyAssigned(self, \.configuration.modelRotation, .constant([x, y, z]))
}

/// The opacity of the model used as the location puck
Expand Down
12 changes: 0 additions & 12 deletions Sources/MapboxMaps/Style/Generated/Atmosphere.swift

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

Loading

0 comments on commit fe14476

Please sign in to comment.