Skip to content

Instantly share code, notes, and snippets.

View AdamLantz's full-sized avatar
🎉
Having a blast!

Adam Lantz AdamLantz

🎉
Having a blast!
View GitHub Profile
@chriswhong
chriswhong / README.md
Last active October 18, 2023 09:37
Clickable Markers in MapboxGL

This example shows how to extend mapboxGL's Marker class to add custom functionality on click.

Why?

MapboxGL has a very convenient Marker class that can be used to quickly get markers on the map with a few lines of code (versus the more complex method of adding sources and layers). They behave a bit differently from the rest of the map features because they are actually HTML elements overlaid on the map canvas.

The stock markers are great, and they are SVG so you can color them by passing in a color option! However, the only interactivity you can easily set up is a popup. When you google 'clickable markers', the examples you find are all using symbol layers with queryRenderedFeatures.

I wanted to trigger navigation in a single page app using the stock Markers and determined a simple extension of the class would help me accomplish this. You can also see these markers in action at https://paintthetown.chriswhong.com

@krooked
krooked / UIImageCropAlphaExtension.swift
Last active November 8, 2022 08:10
Swift: UIImage Crop Alpha
import Foundation
import UIKit
/* Extension for croping transparent pixels
example:
let image: UIImage = UIImage(imageLiteral: "YOUR_IMAGE")
let uiImageView = UIImageView(image: image.cropImageByAlpha())
view.addSubview(uiImageView)
Code was basically done here: