Skip to content

Instantly share code, notes, and snippets.

View derickito's full-sized avatar

Erick Del Orbe derickito

View GitHub Profile
@derickito
derickito / Annotations.swift
Created October 24, 2018 00:21
Function to find the annotations that intersect with an array of selections using Apple's PDFKit in iOS
func annotationsIn(selections: [PDFSelection]) -> [PDFAnnotation] {
if selections.count == 0 { return [] }
var results: [PDFAnnotation] = []
for selection in selections {
//See if rect matches the annotations in this page
let page = selection.pages.first!
let bounds = selection.bounds(for: page)
for annotation in page.annotations {
if bounds.intersects(annotation.bounds) {
results.append(annotation)
@derickito
derickito / PDFViewController.swift
Last active June 5, 2023 07:03
iOS PDFKit: How to add a highlight annotation
override func viewDidLoad() {
createMenu()
}
private func createMenu() {
let highlightItem = UIMenuItem(title: "Highlight", action: #selector(highlight(_:)))
UIMenuController.shared.menuItems = [highlightItem]
}
@objc private func highlight(_ sender: UIMenuController?) {
@derickito
derickito / gist:5767911
Last active December 18, 2015 10:19
This function converts a Google Maps V3 (Javascript API) of MVCArray of lats and longs (MVCArray<LatLng>) to Well Known Text (WKT). The result will be something like POLYGON((50 0, 0 20, 10 10, 50 0))
function MVCToWKT(arr){
var result = 'POLYGON(';
for(ring = 0; ring < arr.length; ring++) {
var strRing = '(';
for(i = 0; i < arr.getAt(ring).length; i++) {
strRing += (i > 0 ? ", " : "") + arr.getAt(ring).getAt(i).lng() + ' ' + arr.getAt(ring).getAt(i).lat();
}
//Add the first point to the end to close polygon
strRing += ', '+arr.getAt(ring).getAt(0).lng() + ' ' + arr.getAt(ring).getAt(0).lat();
strRing += ')';