Skip to content

Commit

Permalink
Add stylable marker view (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni authored and Bobby Sudekum committed Aug 30, 2017
1 parent a0decd0 commit 622dc4c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
35DC9D8D1F431E59001ECD64 /* route.json in Resources */ = {isa = PBXBuildFile; fileRef = C52D09CD1DEF5E5100BE3C5C /* route.json */; };
35DC9D8F1F4321CC001ECD64 /* route-with-lanes.json in Resources */ = {isa = PBXBuildFile; fileRef = 35DC9D8E1F4321CC001ECD64 /* route-with-lanes.json */; };
35DC9D911F4323AA001ECD64 /* LanesContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DC9D901F4323AA001ECD64 /* LanesContainerView.swift */; };
35E407681F5625FF00EFC814 /* StyleKitMarker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35E407671F5625FF00EFC814 /* StyleKitMarker.swift */; };
35F611C41F1E1C0500C43249 /* FeedbackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F611C31F1E1C0500C43249 /* FeedbackViewController.swift */; };
6441B16A1EFC64E50076499F /* WaypointConfirmationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6441B1691EFC64E50076499F /* WaypointConfirmationViewController.swift */; };
64847A041F04629D003F3A69 /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64847A031F04629D003F3A69 /* Feedback.swift */; };
Expand Down Expand Up @@ -405,6 +406,7 @@
35D825FD1E6A2EC60088F83B /* MapboxNavigation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapboxNavigation.h; sourceTree = "<group>"; };
35DC9D8E1F4321CC001ECD64 /* route-with-lanes.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "route-with-lanes.json"; sourceTree = "<group>"; };
35DC9D901F4323AA001ECD64 /* LanesContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanesContainerView.swift; sourceTree = "<group>"; };
35E407671F5625FF00EFC814 /* StyleKitMarker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StyleKitMarker.swift; sourceTree = "<group>"; };
35F611C31F1E1C0500C43249 /* FeedbackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackViewController.swift; sourceTree = "<group>"; };
6441B1691EFC64E50076499F /* WaypointConfirmationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WaypointConfirmationViewController.swift; sourceTree = "<group>"; };
64847A031F04629D003F3A69 /* Feedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Feedback.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -785,6 +787,7 @@
351BEBED1E5BCC63006FE110 /* StyleKitArrows.swift */,
351BEBEF1E5BCC63006FE110 /* TurnArrowView.swift */,
35DC9D901F4323AA001ECD64 /* LanesContainerView.swift */,
35E407671F5625FF00EFC814 /* StyleKitMarker.swift */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -1357,6 +1360,7 @@
C5000A931EC25C6E00563EA9 /* Abbreviations.swift in Sources */,
35C9973F1E732C1B00544D1C /* RouteVoiceController.swift in Sources */,
351BEBFC1E5BCC63006FE110 /* NavigationViewController.swift in Sources */,
35E407681F5625FF00EFC814 /* StyleKitMarker.swift in Sources */,
C588C3C21F33882100520EF2 /* String.swift in Sources */,
351BEBFB1E5BCC63006FE110 /* RouteTableViewHeaderView.swift in Sources */,
C53208AB1E81FFB900910266 /* NavigationMapView.swift in Sources */,
Expand Down
48 changes: 48 additions & 0 deletions MapboxNavigation/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,51 @@ public class StatusView: UIView {
}
}
}


/// :nodoc:
@objc(MBMarkerView)
public class MarkerView: UIView {

// Sets the inner color on the pin.
public dynamic var innerColor: UIColor = .white {
didSet {
setNeedsDisplay()
}
}

// Sets the shadow color under the marker view.
public dynamic var shadowColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.1) {
didSet {
setNeedsDisplay()
}
}

// Sets the color on the marker view.
public dynamic var pinColor: UIColor = #colorLiteral(red: 0.1493228376, green: 0.2374534607, blue: 0.333029449, alpha: 1) {
didSet {
setNeedsDisplay()
}
}

// Sets the stroke color on the marker view.
public dynamic var strokeColor: UIColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0) {
didSet {
setNeedsDisplay()
}
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: 39, height: 51)
}

public override func layoutSubviews() {
super.layoutSubviews()
backgroundColor = .clear
}

override public func draw(_ rect: CGRect) {
super.draw(rect)
StyleKitMarker.drawMarker(innerColor: innerColor, shadowColor: shadowColor, pinColor: pinColor, strokeColor: strokeColor)
}
}
71 changes: 71 additions & 0 deletions MapboxNavigation/StyleKitMarker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// StyleKitMarker.swift
// ProjectName
//
// Created by AuthorName on 8/30/17.
// Copyright © 2017 Mapbox. All rights reserved.
//
// Generated by PaintCode
// http://www.paintcodeapp.com
//



import UIKit

public class StyleKitMarker : NSObject {

//// Drawing Methods

@objc dynamic public class func drawMarker(frame: CGRect = CGRect(x: 57, y: 27, width: 50, height: 50), innerColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000), shadowColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000), pinColor: UIColor = UIColor(red: 0.290, green: 0.565, blue: 0.886, alpha: 1.000), strokeColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()!

//// Group
//// Oval 2 Drawing
context.saveGState()
context.setAlpha(0.1)

let oval2Path = UIBezierPath(ovalIn: CGRect(x: 10, y: 40.61, width: 19, height: 8))
shadowColor.setFill()
oval2Path.fill()

context.restoreGState()


//// Group 2
//// Bezier 2 Drawing
let bezier2Path = UIBezierPath()
bezier2Path.move(to: CGPoint(x: 18.04, y: 43.43))
bezier2Path.addCurve(to: CGPoint(x: 20.96, y: 43.43), controlPoint1: CGPoint(x: 18.85, y: 44.18), controlPoint2: CGPoint(x: 20.16, y: 44.17))
bezier2Path.addCurve(to: CGPoint(x: 37, y: 19.55), controlPoint1: CGPoint(x: 20.96, y: 43.43), controlPoint2: CGPoint(x: 37, y: 29.24))
bezier2Path.addCurve(to: CGPoint(x: 19.5, y: 2), controlPoint1: CGPoint(x: 37, y: 9.86), controlPoint2: CGPoint(x: 29.16, y: 2))
bezier2Path.addCurve(to: CGPoint(x: 2, y: 19.55), controlPoint1: CGPoint(x: 9.84, y: 2), controlPoint2: CGPoint(x: 2, y: 9.86))
bezier2Path.addCurve(to: CGPoint(x: 18.04, y: 43.43), controlPoint1: CGPoint(x: 2, y: 29.24), controlPoint2: CGPoint(x: 18.04, y: 43.43))
bezier2Path.close()
bezier2Path.usesEvenOddFillRule = true
pinColor.setFill()
bezier2Path.fill()


//// Bezier 3 Drawing
let bezier3Path = UIBezierPath()
bezier3Path.move(to: CGPoint(x: 18.04, y: 43.43))
bezier3Path.addCurve(to: CGPoint(x: 20.96, y: 43.43), controlPoint1: CGPoint(x: 18.85, y: 44.18), controlPoint2: CGPoint(x: 20.16, y: 44.17))
bezier3Path.addCurve(to: CGPoint(x: 37, y: 19.55), controlPoint1: CGPoint(x: 20.96, y: 43.43), controlPoint2: CGPoint(x: 37, y: 29.24))
bezier3Path.addCurve(to: CGPoint(x: 19.5, y: 2), controlPoint1: CGPoint(x: 37, y: 9.86), controlPoint2: CGPoint(x: 29.16, y: 2))
bezier3Path.addCurve(to: CGPoint(x: 2, y: 19.55), controlPoint1: CGPoint(x: 9.84, y: 2), controlPoint2: CGPoint(x: 2, y: 9.86))
bezier3Path.addCurve(to: CGPoint(x: 18.04, y: 43.43), controlPoint1: CGPoint(x: 2, y: 29.24), controlPoint2: CGPoint(x: 18.04, y: 43.43))
bezier3Path.close()
strokeColor.setStroke()
bezier3Path.lineWidth = 3
bezier3Path.stroke()


//// Oval Drawing
let ovalPath = UIBezierPath(ovalIn: CGRect(x: 12.5, y: 12.16, width: 14, height: 14))
innerColor.setFill()
ovalPath.fill()
}

}

0 comments on commit 622dc4c

Please sign in to comment.