Skip to content

Instantly share code, notes, and snippets.

View avi-c's full-sized avatar

Avi Cieplinski avi-c

  • San Francisco, CA
View GitHub Profile
@avi-c
avi-c / Pulsing Line Animation
Created October 13, 2020 19:30
Mapbox Maps SDK code snippet for a repeating, pulsing animation along a line. Shown here animating a route line from the Mapbox Navigation SDK
// Use runtime styling to animate a repeating pulsing animation on an MGLMapView
class MyAnimationDemoClass {
var animationTimer: Timer?
var lineLayers = [MGLLineStyleLayer]() // Array to hold the Line style layers we created so they can be reused to repeat the animation
// This function will animate a set of line segments and return the duration of the entire animation.
// The duration can be used to set up a repeating timer to trigger the animation again if you want it to loop
private func animateByStep(style: MGLStyle, shapes: [LineString]) -> TimeInterval {
guard shapes.count > 0 else { return 0 }
@avi-c
avi-c / MGL_MATCH for icon opacity
Created October 15, 2020 20:08
Swift code showing how to set the opacity of a MGLSymbolStyleLayer based on a feature property
private func applyOpacity(style: MGLStyle) {
// NSExpression *iconOpacityStyle =
// [NSExpression expressionWithFormat:@"MGL_MATCH(%@, %@, %f, %f)", selectedAttributeName, selectedAttributeValue,
// selectedIconOpacity, deselectedIconOpacity];
// works for the Nav V5 style to fade away all the road shields that aren't for I-280
if let symbolLayer = style.layer(withIdentifier: "road-number-shield-navigation") as? MGLSymbolStyleLayer {
let selectedAttributeName = "ref"
let selectedAttributeValue = "280"
let selectedIconOpacity = NSExpression(forConstantValue: NSNumber(1.0))
@avi-c
avi-c / gist:9ba7e78b996973dc95c1898b2bfcae9d
Last active May 12, 2021 18:14
Recipe for exporting KML for routes from My Maps to a GPX file
Go to My Maps in google maps
In one of your Maps, add a turn by turn directions step for the route you want
Right click the top level My Maps window that contains the steps
Select "Export as KML"
Check the KML box and save the file
Open downloaded file in BBEdit or other powerful text editor
Copy out only the portion of the file that is the long list of coordinates and place it in it's own file without the rest of the KML.
In BBEdit, use the find regular expression: (.*?),(.*?),0 and the replace regular expression: <wpt lat="\2" lon="\1"/> to transform the KML coordinate representation into the GPX waypoint format needed by Xcode
Prepend the GPX JSON tags in the following 2 lines:
<?xml version="1.0"?>