Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce MapboxMap #280

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public class ColorExpressionExample: UIViewController, ExampleProtocol {

if let data = try? JSONEncoder().encode(exp.self),
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) {
mapView.__map.setStyleLayerPropertyForLayerId("land",
property: "background-color",
value: jsonObject)
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(
"land",
property: "background-color",
value: jsonObject)
}

// The below line is used for internal testing purposes only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public class CustomLayerExample: UIViewController, ExampleProtocol {
// Position the custom layer above the water layer and below all other layers.
let layerPosition = LayerPosition(above: "water", below: nil, at: nil)

mapView.__map.addStyleCustomLayer(forLayerId: "Custom",
layerHost: self,
layerPosition: layerPosition)
mapView.mapboxMap.__map.addStyleCustomLayer(
forLayerId: "Custom",
layerHost: self,
layerPosition: layerPosition)
}
}

Expand Down
13 changes: 7 additions & 6 deletions Apps/Examples/Examples/All Examples/SceneKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
}

func addModelAndTerrain() {
mapView.__map.addStyleCustomLayer(forLayerId: "Custom",
layerHost: self,
layerPosition: LayerPosition(above: nil, below: "waterway-label", at: nil))
mapView.mapboxMap.__map.addStyleCustomLayer(
forLayerId: "Custom",
layerHost: self,
layerPosition: LayerPosition(above: nil, below: "waterway-label", at: nil))

var demSource = RasterDemSource()
demSource.url = "mapbox://mapbox.mapbox-terrain-dem-v1"
Expand All @@ -59,16 +60,16 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
_ = self.mapView.style.addLayer(layer: skyLayer)

// Re-use terrain source for hillshade
let map = self.mapView.__map!
let properties = [
"id": "terrain_hillshade",
"type": "hillshade",
"source": "mapbox-dem",
"hillshade-illumination-anchor": "map"
] as [ String: Any ]

map.addStyleLayer(forProperties: properties,
layerPosition: LayerPosition(above: nil, below: "water", at: nil))
mapView.mapboxMap.__map.addStyleLayer(
forProperties: properties,
layerPosition: LayerPosition(above: nil, below: "water", at: nil))
}

public func renderingWillStart(_ metalDevice: MTLDevice, colorPixelFormat: UInt, depthStencilPixelFormat: UInt) {
Expand Down
23 changes: 11 additions & 12 deletions Apps/StressTest/StressTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ViewController: UIViewController {
var color: StylePropertyValue?
var mapInitOptions: MapInitOptions!
var snapshotter: Snapshotter?
var peer: MBXPeerWrapper?
var logHandle: OSLog!

override func viewDidLoad() {
Expand Down Expand Up @@ -248,12 +247,15 @@ class ViewController: UIViewController {
do {
let data = try JSONEncoder().encode(exp.self)
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
color = try mapView.__map.getStyleLayerProperty(forLayerId: land, property: "background-color")
color = mapView.mapboxMap.__map.getStyleLayerProperty(
forLayerId: land,
property: "background-color")

print("Setting background color expression")
try mapView.__map.setStyleLayerPropertyForLayerId(land,
property: "background-color",
value: jsonObject)
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(
land,
property: "background-color",
value: jsonObject)
} catch let error {
print("Error setting background color: \(error)")
}
Expand All @@ -266,13 +268,10 @@ class ViewController: UIViewController {

if let color = color {
print("Re-setting background color expression")
do {
try mapView.__map.setStyleLayerPropertyForLayerId(land,
property: "background-color",
value: color.value)
} catch let error {
print("Failed to reset the background color: \(error)")
}
mapView.mapboxMap.__map.setStyleLayerPropertyForLayerId(
land,
property: "background-color",
value: color.value)
}
color = nil
}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Mapbox welcomes participation and contributions from everyone.
* `BaseMapView` no longer conforms to `MapClient` or `MBMMetalViewProvider`, and the methods they required are now internal.
* The setter for `BaseMapView.__map` is now private
* `Snapshotter` no longer conforms to `Observer`, and the method it required is now internal.
* The `BaseMapView.__map` property has been moved to `BaseMapView.mapboxMap.__map`. ([#280](https://github.com/mapbox/mapbox-maps-ios/pull/280))

## 10.0.0-beta.17 - April 13, 2021

Expand Down
12 changes: 12 additions & 0 deletions Mapbox/MapboxMaps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
B51DE65B25D7038900A80AC9 /* Comparable+Clamped.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51DE62125D7032C00A80AC9 /* Comparable+Clamped.swift */; };
B51DE68125D7039700A80AC9 /* Comparable+ClampedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51DE64725D7038300A80AC9 /* Comparable+ClampedTests.swift */; };
B52050A8260538240003E5BB /* ModelLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52050A7260538240003E5BB /* ModelLayer.swift */; };
B521FC93262F626900B9A446 /* MapboxMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = B521FC92262F626900B9A446 /* MapboxMap.swift */; };
B521FC98262F627300B9A446 /* Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = B521FC97262F627300B9A446 /* Size.swift */; };
B521FC9D262F665C00B9A446 /* SizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B521FC9C262F665C00B9A446 /* SizeTests.swift */; };
B529341C2624E9D6003B181C /* PreferredFPS.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52934192624E9D6003B181C /* PreferredFPS.swift */; };
B529341D2624E9D6003B181C /* DelegatingMapClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = B529341A2624E9D6003B181C /* DelegatingMapClient.swift */; };
B529341E2624E9D6003B181C /* DelegatingObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B529341B2624E9D6003B181C /* DelegatingObserver.swift */; };
Expand Down Expand Up @@ -594,6 +597,9 @@
B51DE62125D7032C00A80AC9 /* Comparable+Clamped.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Clamped.swift"; sourceTree = "<group>"; };
B51DE64725D7038300A80AC9 /* Comparable+ClampedTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+ClampedTests.swift"; sourceTree = "<group>"; };
B52050A7260538240003E5BB /* ModelLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelLayer.swift; sourceTree = "<group>"; };
B521FC92262F626900B9A446 /* MapboxMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapboxMap.swift; sourceTree = "<group>"; };
B521FC97262F627300B9A446 /* Size.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Size.swift; sourceTree = "<group>"; };
B521FC9C262F665C00B9A446 /* SizeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeTests.swift; sourceTree = "<group>"; };
B52934192624E9D6003B181C /* PreferredFPS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferredFPS.swift; sourceTree = "<group>"; };
B529341A2624E9D6003B181C /* DelegatingMapClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelegatingMapClient.swift; sourceTree = "<group>"; };
B529341B2624E9D6003B181C /* DelegatingObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelegatingObserver.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -770,6 +776,7 @@
0782B1DB258C254400D5FCE5 /* Core */ = {
isa = PBXGroup;
children = (
B521FC97262F627300B9A446 /* Size.swift */,
CABCDF502620E0FF00D61635 /* MapOptions.swift */,
B5B55D4B260E4D2900EBB589 /* MBXEdgeInsets.swift */,
0782B075258C190C00D5FCE5 /* CoordinateBounds.swift */,
Expand Down Expand Up @@ -1145,6 +1152,7 @@
1F11C1102421B05600F8397B /* MapboxMapsFoundation */ = {
isa = PBXGroup;
children = (
B521FC92262F626900B9A446 /* MapboxMap.swift */,
B529341A2624E9D6003B181C /* DelegatingMapClient.swift */,
B529341B2624E9D6003B181C /* DelegatingObserver.swift */,
B52934192624E9D6003B181C /* PreferredFPS.swift */,
Expand Down Expand Up @@ -1472,6 +1480,7 @@
children = (
CA03F0962624FDED00673961 /* ResourceOptionsTests.swift */,
CA0C42942602BF000054D9D0 /* LayerPositionTests.swift */,
B521FC9C262F665C00B9A446 /* SizeTests.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -1901,6 +1910,7 @@
0C708F2524EB1EE2003CE791 /* HillshadeLayer.swift in Sources */,
CABCDF512620E0FF00D61635 /* MapOptions.swift in Sources */,
0C708F2124EB1EE2003CE791 /* FillExtrusionLayer.swift in Sources */,
B521FC98262F627300B9A446 /* Size.swift in Sources */,
0C26425524EECD14001FE2E3 /* AllExpressions.swift in Sources */,
0782B1A3258C250400D5FCE5 /* Geometry.swift in Sources */,
0CD62F1024588530006421D1 /* GestureManager.swift in Sources */,
Expand Down Expand Up @@ -1984,6 +1994,7 @@
1FECC9E02474519D00B63910 /* Expression.swift in Sources */,
B52050A8260538240003E5BB /* ModelLayer.swift in Sources */,
B529341C2624E9D6003B181C /* PreferredFPS.swift in Sources */,
B521FC93262F626900B9A446 /* MapboxMap.swift in Sources */,
0CD62F1124588532006421D1 /* GestureHandlerDelegate.swift in Sources */,
0782B061258C16B200D5FCE5 /* Utils.swift in Sources */,
0CD62F2C24588937006421D1 /* Style.swift in Sources */,
Expand Down Expand Up @@ -2139,6 +2150,7 @@
CA548FFB251C404B00F829A3 /* StyleURITests.swift in Sources */,
CA2E4A1B2538D3530096DEDE /* MapViewIntegrationTestCase.swift in Sources */,
0C32CA2A25F982300057ED31 /* ImageSourceTests.swift in Sources */,
B521FC9D262F665C00B9A446 /* SizeTests.swift in Sources */,
0C5CFCD625BB951B0001E753 /* FillExtrusionLayerTests.swift in Sources */,
B54B7F2125DB1ABA003FD6CA /* Stub.swift in Sources */,
0C01C0B925486E7200E4AA46 /* ExpressionTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal protocol AnnotationSupportableMap: UIView {
extension BaseMapView: AnnotationSupportableMap {

public var observable: Observable? {
return __map
return mapboxMap.__map
}

public enum QueryRenderedFeaturesError: Error {
Expand Down Expand Up @@ -62,7 +62,7 @@ extension BaseMapView: AnnotationSupportableMap {
let screenBox = ScreenBox(min: ScreenCoordinate(x: Double(rect.minX), y: Double(rect.minY)),
max: ScreenCoordinate(x: Double(rect.maxX), y: Double(rect.maxY)))

__map.queryRenderedFeatures(for: screenBox, options: queryOptions, callback: { (expected: MBXExpected?) in
mapboxMap.__map.queryRenderedFeatures(for: screenBox, options: queryOptions, callback: { (expected: MBXExpected?) in

guard let validExpected = expected else {
completion(.failure(.unknown))
Expand Down Expand Up @@ -113,7 +113,7 @@ extension BaseMapView: AnnotationSupportableMap {
let screenPoint = ScreenCoordinate(x: Double(point.x),
y: Double(point.y))

__map.queryRenderedFeatures(forPixel: screenPoint, options: queryOptions, callback: { (expected: MBXExpected?) in
mapboxMap.__map.queryRenderedFeatures(forPixel: screenPoint, options: queryOptions, callback: { (expected: MBXExpected?) in

guard let validExpected = expected else {
completion(.failure(.unknown))
Expand Down
59 changes: 33 additions & 26 deletions Sources/MapboxMaps/Foundation/BaseMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ import Turf

internal typealias PendingAnimationCompletion = (completion: AnimationCompletion, animatingPosition: UIViewAnimatingPosition)

// swiftlint:disable:next type_body_length
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed in a follow-on PR that migrates more functionality from BaseMapView into MapboxMap

open class BaseMapView: UIView, CameraViewDelegate {

/// The underlying renderer object responsible for rendering the map
public private(set) var __map: Map!
// mapbox map depends on MapInitOptions, which is not available until
// awakeFromNib() when instantiating BaseMapView from a xib or storyboard.
// This is the only reason that it is an implicitly-unwrapped optional var
// instead of a non-optional let.
public private(set) var mapboxMap: MapboxMap! {
didSet {
assert(oldValue == nil, "mapboxMap should only be set once.")
}
}

private let mapClient = DelegatingMapClient()
private let observer = DelegatingObserver()
Expand Down Expand Up @@ -50,7 +58,7 @@ open class BaseMapView: UIView, CameraViewDelegate {
/// The map's current camera
public var camera: CameraOptions {
get {
return __map.getCameraOptions(forPadding: nil)
return mapboxMap.cameraOptions
} set {
cameraView.camera = newValue
}
Expand Down Expand Up @@ -124,7 +132,7 @@ open class BaseMapView: UIView, CameraViewDelegate {
}

func jumpTo(camera: CameraOptions) {
__map.setCameraFor(camera)
mapboxMap.updateCamera(with: camera)
}

// MARK: Init
Expand All @@ -139,30 +147,31 @@ open class BaseMapView: UIView, CameraViewDelegate {

self.resourceOptions = mapInitOptions.resourceOptions

let resolvedMapOptions: MapOptions

let resolvedMapInitOptions: MapInitOptions
if mapInitOptions.mapOptions.size == nil {
// Update using the view's size
let other = mapInitOptions.mapOptions
resolvedMapOptions = MapOptions(__contextMode: other.__contextMode,
constrainMode: other.__constrainMode,
viewportMode: other.__viewportMode,
orientation: other.__orientation,
crossSourceCollisions: other.__crossSourceCollisions,
size: Size(width: Float(bounds.width), height: Float(bounds.height)),
pixelRatio: other.pixelRatio,
glyphsRasterizationOptions: other.glyphsRasterizationOptions)
let original = mapInitOptions.mapOptions
let resolvedMapOptions = MapOptions(
__contextMode: original.__contextMode,
constrainMode: original.__constrainMode,
viewportMode: original.__viewportMode,
orientation: original.__orientation,
crossSourceCollisions: original.__crossSourceCollisions,
size: Size(width: Float(bounds.width), height: Float(bounds.height)),
pixelRatio: original.pixelRatio,
glyphsRasterizationOptions: original.glyphsRasterizationOptions)
resolvedMapInitOptions = MapInitOptions(
resourceOptions: mapInitOptions.resourceOptions,
mapOptions: resolvedMapOptions)
} else {
resolvedMapOptions = mapInitOptions.mapOptions
resolvedMapInitOptions = mapInitOptions
}
mapClient.delegate = self
__map = Map(client: mapClient, mapOptions: resolvedMapOptions, resourceOptions: mapInitOptions.resourceOptions)

__map?.createRenderer()
mapboxMap = MapboxMap(mapClient: mapClient, mapInitOptions: resolvedMapInitOptions)

observer.delegate = self
let events = MapEvents.EventKind.allCases.map({ $0.rawValue })
__map.subscribe(for: observer, events: events)
mapboxMap.__map.subscribe(for: observer, events: events)

self.cameraView = CameraView(delegate: self)
self.addSubview(cameraView)
Expand All @@ -173,7 +182,7 @@ open class BaseMapView: UIView, CameraViewDelegate {
object: nil)

if let validStyleURI = styleURI {
__map?.setStyleURIForUri(validStyleURI.absoluteString)
mapboxMap.__map.setStyleURIForUri(validStyleURI.absoluteString)
}
}

Expand Down Expand Up @@ -224,9 +233,7 @@ open class BaseMapView: UIView, CameraViewDelegate {

public override func layoutSubviews() {
super.layoutSubviews()
let size = MapboxCoreMaps.Size(width: Float(bounds.size.width),
height: Float(bounds.size.height))
__map?.setSizeFor(size)
mapboxMap.size = bounds.size
}

func validateDisplayLink() {
Expand Down Expand Up @@ -326,7 +333,7 @@ open class BaseMapView: UIView, CameraViewDelegate {
public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D {
let view = view ?? self
let screenCoordinate = convert(point, from: view).screenCoordinate // Transform to view's coordinate space
return __map.coordinateForPixel(forPixel: screenCoordinate)
return mapboxMap.__map.coordinateForPixel(forPixel: screenCoordinate)
}

/**
Expand All @@ -340,7 +347,7 @@ open class BaseMapView: UIView, CameraViewDelegate {
*/
public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint {
let view = view ?? self
let point = __map.pixelForCoordinate(for: coordinate).point
let point = mapboxMap.__map.pixelForCoordinate(for: coordinate).point
let transformedPoint = convert(point, to: view)
return transformedPoint
}
Expand Down
Loading