Skip to content

Commit

Permalink
Upgrade Core & Common (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
macdrevx authored Oct 3, 2021
1 parent 6b37822 commit 377e7ce
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 149 deletions.
8 changes: 4 additions & 4 deletions Apps/Apps.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git",
"state": {
"branch": null,
"revision": "98893cfe86f3aeed89d852f406d74a1756f71dad",
"version": "19.0.0"
"revision": "0344eb61ec9e3cf96c81b1767354a8a3cd1246fc",
"version": "20.0.0"
}
},
{
"package": "MapboxCoreMaps",
"repositoryURL": "https://github.com/mapbox/mapbox-core-maps-ios.git",
"state": {
"branch": null,
"revision": "a5561019739925ba364263d3cf0dc58e1133a9ea",
"version": "10.0.0-rc.9.1"
"revision": "fd3b7e65b51fd984831c1337876b038ed183480b",
"version": "10.0.0"
}
},
{
Expand Down
29 changes: 13 additions & 16 deletions Apps/Examples/Examples/All Examples/CustomLayerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import UIKit
import MapboxMaps

@objc(CustomLayerExample)
final class CustomLayerExample: UIViewController, ExampleProtocol {

public class CustomLayerExample: UIViewController, ExampleProtocol {
var mapView: MapView!

internal var mapView: MapView!

var depthStencilState: MTLDepthStencilState!
var pipelineState: MTLRenderPipelineState!

override public func viewDidLoad() {
override func viewDidLoad() {
super.viewDidLoad()

mapView = MapView(frame: view.bounds)
Expand All @@ -22,23 +18,26 @@ public class CustomLayerExample: UIViewController, ExampleProtocol {
}
}

override public func viewDidAppear(_ animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// The below line is used for internal testing purposes only.
finish()
}

internal func addCustomLayer() {
func addCustomLayer() {
// Position the custom layer above the water layer and below all other layers.
try! mapView.mapboxMap.style.addCustomLayer(
withId: "Custom",
layerHost: self,
layerHost: CustomLayerExampleCustomLayerHost(),
layerPosition: .above("water"))
}
}

extension CustomLayerExample: CustomLayerHost {
public func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
final class CustomLayerExampleCustomLayerHost: NSObject, CustomLayerHost {
var depthStencilState: MTLDepthStencilState!
var pipelineState: MTLRenderPipelineState!

func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {

let compileOptions = MTLCompileOptions()

Expand Down Expand Up @@ -101,7 +100,7 @@ extension CustomLayerExample: CustomLayerHost {
}
}

public func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {

let vertices = [
simd_float2(0, 0.5),
Expand All @@ -123,12 +122,10 @@ extension CustomLayerExample: CustomLayerHost {
renderCommandEncoder.endEncoding()
}

public func renderingWillEnd() {
func renderingWillEnd() {
// Unimplemented
}
}

extension CustomLayerExample {
// The Metal shader program, written in the
// [Metal Shader Language](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf) format.
var metalShaderProgram: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public class OfflineRegionManagerExample: UIViewController, ExampleProtocol {

internal func setupExample() {
let uriString = mapView.mapboxMap.style.uri!.rawValue
let offlineRegionDef = OfflineRegionGeometryDefinition(styleURL: uriString,
geometry: MapboxCommon.Geometry(point: CGPoint(x: coord.latitude, y: coord.longitude) as NSValue),
minZoom: zoom - 2,
maxZoom: zoom + 2,
pixelRatio: Float(UIScreen.main.scale),
glyphsRasterizationMode: .noGlyphsRasterizedLocally)
let offlineRegionDef = OfflineRegionGeometryDefinition(
__styleURL: uriString,
geometry: MapboxCommon.Geometry(point: CGPoint(x: coord.latitude, y: coord.longitude) as NSValue),
minZoom: zoom - 2,
maxZoom: zoom + 2,
pixelRatio: Float(UIScreen.main.scale),
glyphsRasterizationMode: .noGlyphsRasterizedLocally)

// Please note - this is using a deprecated API, and will be removed in a future release.
offlineManager = OfflineRegionManager(resourceOptions: resourceOptions())
Expand Down Expand Up @@ -86,6 +87,7 @@ public class OfflineRegionManagerExample: UIViewController, ExampleProtocol {
}

/// Delegate for OfflineRegion
@available(*, deprecated)
public class OfflineRegionExampleObserver: OfflineRegionObserver {

weak var offlineRegion: OfflineRegion?
Expand Down
53 changes: 30 additions & 23 deletions Apps/Examples/Examples/All Examples/SceneKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@ import SceneKit
import MapboxMaps

@objc(SceneKitExample)
final class SceneKitExample: UIViewController, ExampleProtocol {

public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost {

internal var mapView: MapView!

var mapView: MapView!
let modelOrigin = CLLocationCoordinate2D(latitude: -35.39847, longitude: 148.9819)
var renderer: SCNRenderer!
var scene: SCNScene!
var modelNode: SCNNode!
var cameraNode: SCNNode!
var textNode: SCNNode!
var useCPUOcclusion = false

override public func viewDidLoad() {
override func viewDidLoad() {
super.viewDidLoad()

let camera = CameraOptions(center: self.modelOrigin,
let camera = CameraOptions(center: modelOrigin,
zoom: 18,
bearing: 180,
pitch: 60)
Expand All @@ -34,14 +26,12 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
}
}

override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}

func addModelAndTerrain() {
try! mapView.mapboxMap.style.addCustomLayer(
withId: "Custom",
layerHost: self,
layerHost: SceneKitExampleCustomLayerHost(
modelOrigin: modelOrigin,
renderingWillEndHandler: { [weak self] in self?.finish() }),
layerPosition: .below("waterway-label"))

var demSource = RasterDemSource()
Expand Down Expand Up @@ -71,8 +61,25 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost

try! mapView.mapboxMap.style.addLayer(with: properties, layerPosition: .below("water"))
}
}

final class SceneKitExampleCustomLayerHost: NSObject, CustomLayerHost {
let modelOrigin: CLLocationCoordinate2D
var renderer: SCNRenderer!
var scene: SCNScene!
var modelNode: SCNNode!
var cameraNode: SCNNode!
var textNode: SCNNode!
var useCPUOcclusion = false
let renderingWillEndHandler: () -> Void

init(modelOrigin: CLLocationCoordinate2D, renderingWillEndHandler: @escaping () -> Void) {
self.modelOrigin = modelOrigin
self.renderingWillEndHandler = renderingWillEndHandler
super.init()
}

public func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
renderer = SCNRenderer(device: metalDevice)
scene = SCNScene()
renderer.scene = scene
Expand Down Expand Up @@ -123,7 +130,7 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
modelNode.addChildNode(pointNode)
}

internal func makeTranslationMatrix(tx: Double, ty: Double, tz: Double) -> simd_double4x4 {
func makeTranslationMatrix(tx: Double, ty: Double, tz: Double) -> simd_double4x4 {
var matrix = matrix_identity_double4x4

matrix[3, 0] = tx
Expand All @@ -133,7 +140,7 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
return matrix
}

internal func makeScaleMatrix(xScale: Double, yScale: Double, zScale: Double) -> simd_double4x4 {
func makeScaleMatrix(xScale: Double, yScale: Double, zScale: Double) -> simd_double4x4 {
var matrix = matrix_identity_double4x4

matrix[0, 0] = xScale
Expand All @@ -143,7 +150,7 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
return matrix
}

public func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
func render(_ parameters: CustomLayerRenderParameters, mtlCommandBuffer: MTLCommandBuffer, mtlRenderPassDescriptor: MTLRenderPassDescriptor) {
guard let colorTexture = mtlRenderPassDescriptor.colorAttachments[0].texture else {
return
}
Expand Down Expand Up @@ -220,8 +227,8 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost

}

public func renderingWillEnd() {
func renderingWillEnd() {
// The below line is used for internal testing purposes only.
self.finish()
renderingWillEndHandler()
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Mapbox welcomes participation and contributions from everyone.
* `MapboxMap.setCameraBounds(for:)` has been renamed to `.setCameraBounds(with:)` ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* Requires [Turf v2.0.0-rc.2](https://github.com/mapbox/turf-swift/releases/tag/v2.0.0-rc.2). ([#715](https://github.com/mapbox/mapbox-maps-ios/pull/715))
* Renames `Style.updateGeoJSONSource<T: GeoJSONObject>(withId:geoJSON:)` to `Style.updateGeoJSONSource(withId:geoJSON:)`. Instead of passing in the expected GeoJSON object type, you perform pattern matching on the return value using `case let`. ([#715](https://github.com/mapbox/mapbox-maps-ios/pull/715))
* `MapboxCoreMaps.Settings` is now deprecated. ([#732](https://github.com/mapbox/mapbox-maps-ios/pull/732))
* Setting `data` property on a GeoJSON source via `Style.setSourceProperty(for:property:value:)` or `Style.updateGeoJSONSource(withId:geoJSON:)` is now asynchronous and never returns an error. Errors will be reported asynchronously via a `MapEvents.EventKind.mapLoadingError` event instead. ([#732](https://github.com/mapbox/mapbox-maps-ios/pull/732))
* Core and Common APIs that accept user-defined implementations of protocols now hold strong references to the provided objects. Please audit your usage of the following protocols and make any required changes to avoid memory leaks: `CustomLayerHost`, `ElevationData`, `MapClient`, `MBMMetalViewProvider`, `Observer`, `OfflineRegionObserver`, `HttpServiceInterceptorInterface`, `HttpServiceInterface`, `LogWriterBackend`, `OfflineSwitchObserver`, `ReachabilityInterface`, `TileStoreObserver`. ([#732](https://github.com/mapbox/mapbox-maps-ios/pull/732))

### Features ✨ and improvements 🏁

Expand All @@ -34,7 +37,8 @@ Mapbox welcomes participation and contributions from everyone.
* Any touch event in the map now immediately disables camera animation. Temporarily disable user interaction on the `MapView` to disable this behavior as needed. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* `BasicCameraAnimator` no longer updates the camera a final time after being stopped or canceled prior to running to completion. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* `BasicCameraAnimator.isReversed` is now settable. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712))
* The double tap, quick zoom, and double touch gestures now use the gesture's location in the view to anchor camera changes. Previously, they used the camera's center coordinate ([#722](https://github.com/mapbox/mapbox-maps-ios/pull/722))
* The double tap, quick zoom, and double touch gestures now use the gesture's location in the view to anchor camera changes. Previously, they used the camera's center coordinate. ([#722](https://github.com/mapbox/mapbox-maps-ios/pull/722))
* `MapboxCommon.HTTPServiceFactor.reset()` has been added to release the HTTP service implementation. ([#732](https://github.com/mapbox/mapbox-maps-ios/pull/732))

## 10.0.0-rc.9 - Sept 22, 2021

Expand Down
4 changes: 2 additions & 2 deletions MapboxMaps.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Pod::Spec.new do |m|
m.source_files = 'Sources/MapboxMaps/**/*.{swift,h}'
m.resources = 'Sources/**/*.{xcassets,strings}'

m.dependency 'MapboxCoreMaps', '10.0.0-rc.9.1'
m.dependency 'MapboxCommon', '19.0.0'
m.dependency 'MapboxCoreMaps', '10.0.0'
m.dependency 'MapboxCommon', '20.0.0'
m.dependency 'MapboxMobileEvents', '1.0.5'
m.dependency 'Turf', '2.0.0-rc.2'

Expand Down
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git",
"state": {
"branch": null,
"revision": "98893cfe86f3aeed89d852f406d74a1756f71dad",
"version": "19.0.0"
"revision": "0344eb61ec9e3cf96c81b1767354a8a3cd1246fc",
"version": "20.0.0"
}
},
{
"package": "MapboxCoreMaps",
"repositoryURL": "https://github.com/mapbox/mapbox-core-maps-ios.git",
"state": {
"branch": null,
"revision": "a5561019739925ba364263d3cf0dc58e1133a9ea",
"version": "10.0.0-rc.9.1"
"revision": "fd3b7e65b51fd984831c1337876b038ed183480b",
"version": "10.0.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ let package = Package(
targets: ["MapboxMaps"]),
],
dependencies: [
.package(name: "MapboxCoreMaps", url: "https://github.com/mapbox/mapbox-core-maps-ios.git", .exact("10.0.0-rc.9.1")),
.package(name: "MapboxCoreMaps", url: "https://github.com/mapbox/mapbox-core-maps-ios.git", .exact("10.0.0")),
.package(name: "MapboxCommon", url: "https://github.com/mapbox/mapbox-common-ios.git", .exact("20.0.0")),
.package(name: "MapboxMobileEvents", url: "https://github.com/mapbox/mapbox-events-ios.git", .exact("1.0.5")),
.package(name: "MapboxCommon", url: "https://github.com/mapbox/mapbox-common-ios.git", .exact("19.0.0")),
.package(name: "Turf", url: "https://github.com/mapbox/turf-swift.git", .exact("2.0.0-rc.2")),
.package(name: "CocoaImageHashing", url: "https://github.com/ameingast/cocoaimagehashing", .exact("1.9.0"))
],
Expand Down
13 changes: 0 additions & 13 deletions Sources/MapboxMaps/Foundation/DelegatingObserver.swift

This file was deleted.

3 changes: 1 addition & 2 deletions Sources/MapboxMaps/Foundation/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ open class MapView: UIView {
/// A reference to the `EventsManager` used for dispatching telemetry.
internal var eventsListener: EventsListener!

private let mapClient = DelegatingMapClient()

/// A Boolean value that indicates whether the underlying `CAMetalLayer` of the `MapView`
/// presents its content using a CoreAnimation transaction
///
Expand Down Expand Up @@ -180,6 +178,7 @@ open class MapView: UIView {

self.pixelRatio = CGFloat(resolvedMapInitOptions.mapOptions.pixelRatio)

let mapClient = DelegatingMapClient()
mapClient.delegate = self
mapboxMap = MapboxMap(mapClient: mapClient, mapInitOptions: resolvedMapInitOptions)

Expand Down
Loading

0 comments on commit 377e7ce

Please sign in to comment.