Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Neel Mistry committed Aug 30, 2021
1 parent bad8360 commit 7d941ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol {
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)

// Setup and create button for toggling accuracy ring
self.setupToggleShowAccuracyButton()

// Granularly configure the location puck with a `Puck2DConfiguration`
let configuration = Puck2DConfiguration(topImage: UIImage(named: "star"))
mapView.location.options.puckType = .puck2D(configuration)
Expand All @@ -25,25 +28,23 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol {
guard let self = self else { return }

if let currentLocation = self.mapView.location.latestLocation {
let cameraOptions = CameraOptions(center: currentLocation.coordinate, zoom: 17.0)
let cameraOptions = CameraOptions(center: currentLocation.coordinate, zoom: 18.0)
self.mapView.camera.ease(to: cameraOptions, duration: 2.0)
}
})

// Setup a toggle button to show how to toggle the accuracy radius
mapView.mapboxMap.onEvery(.cameraChanged, handler: { [weak self] _ in
guard let self = self else { return }
guard let self = self,
let button = self.toggleAccuracyRadiusButton else {
return
}

if self.mapView.cameraState.zoom >= 18.0 {
button.isHidden = false

if self.mapView.cameraState.zoom >= 17.0 {
if let button = self.toggleAccuracyRadiusButton {
button.isHidden = false
} else {
self.setupToggleShowAccuracyButton()
}
} else {
if let button = self.toggleAccuracyRadiusButton {
button.isHidden = true
}
button.isHidden = true
}
})
}
Expand All @@ -57,11 +58,11 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol {
@objc func showHideAccuracyRadius() {
var configuration = Puck2DConfiguration(topImage: UIImage(named: "star"))
if shouldToggleAccuracyRadius {
configuration.showAccuracyRing = true
configuration.showsAccuracyRing = true
shouldToggleAccuracyRadius = false
self.toggleAccuracyRadiusButton!.setTitle("Disable Accuracy Radius", for: .normal)
} else {
configuration.showAccuracyRing = false
configuration.showsAccuracyRing = false
shouldToggleAccuracyRadius = true
self.toggleAccuracyRadiusButton!.setTitle("Enable Accuracy Radius", for: .normal)
}
Expand All @@ -82,7 +83,6 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol {
// Constraints
button.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20.0).isActive = true
button.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20.0).isActive = true
button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
button.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 650.0).isActive = true

self.toggleAccuracyRadiusButton = button
Expand Down
8 changes: 4 additions & 4 deletions Sources/MapboxMaps/Location/Pucks/Puck2D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public struct Puck2DConfiguration: Equatable {
public var scale: Value<Double>?

/// Flag determining if the horizontal accuracy ring should be shown arround the Puck. default value is false
public var showAccuracyRing: Bool
public var showsAccuracyRing: Bool

public init(topImage: UIImage? = nil,
bearingImage: UIImage? = nil,
shadowImage: UIImage? = nil,
scale: Value<Double>? = nil,
showAccuracyRing: Bool = false) {
showsAccuracyRing: Bool = false) {
self.topImage = topImage
self.bearingImage = bearingImage
self.shadowImage = shadowImage
self.scale = scale
self.showAccuracyRing = showAccuracyRing
self.showsAccuracyRing = showsAccuracyRing
}

internal var resolvedTopImage: UIImage? {
Expand Down Expand Up @@ -193,7 +193,7 @@ internal extension Puck2D {
layer.bearingTransition = StyleTransition(duration: 0, delay: 0)

// Horizontal accuracy ring is an optional visual for the 2D Puck
if configuration.showAccuracyRing {
if configuration.showsAccuracyRing {
layer.accuracyRadius = .constant(location.horizontalAccuracy)
layer.accuracyRadiusColor = .constant(ColorRepresentable(color: UIColor(red: 0.537, green: 0.812, blue: 0.941, alpha: 0.3)))
layer.accuracyRadiusBorderColor = .constant(ColorRepresentable(color: .lightGray))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
puckBearingSource: .heading,
locationSupportableMapView: self.mapView!,
style: style,
configuration: Puck2DConfiguration(showAccuracyRing: true))
configuration: Puck2DConfiguration(showsAccuracyRing: true))
do {
try puck.createPreciseLocationIndicatorLayer(location: location)
} catch {
Expand Down

0 comments on commit 7d941ef

Please sign in to comment.