Created
May 31, 2020 17:58
-
-
Save ryanisnhp/312fb5b422fc7ffeac41bf5dd70f7f29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc func animatePolylineDashAnimation() { | |
//Iterate each valid coordinate on the path | |
if i < path.count() { | |
newPath.add(path.coordinate(at: i)) | |
newPolyline.path = newPath | |
newPolyline.strokeWidth = 4 | |
let dashLength = calculateDashLength(zoomLevel: mapView.camera.zoom) | |
let clearDashLength = Int(Double(dashLength) * 0.5) | |
let lengths = [dashLength, clearDashLength] // Play with this for dotted line | |
let greenSpan = GMSStrokeStyle.solidColor(UIColor(rgb: 0x38726E)) | |
let clearSpan = GMSStrokeStyle.solidColor(UIColor.clear) | |
newPolyline.spans = GMSStyleSpans(newPolyline.path!, [greenSpan, clearSpan], lengths as [NSNumber], .rhumb) | |
newPolyline.map = mapView | |
i += 1 | |
} else { | |
resetTimer() | |
startAnimationTimer() | |
} | |
} | |
func calculateDashLength(zoomLevel: Float) -> Int { | |
let maxDashLength : Float = 750000.0 | |
let a = zoomLevel < 18.0 ? powf(2.0, zoomLevel - 1) : powf(2.0, zoomLevel - 2) | |
return Int(maxDashLength / a) > 50 ? Int(maxDashLength / a) : 50 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment