Skip to content

Instantly share code, notes, and snippets.

View nixta's full-sized avatar

Nicholas Furness nixta

View GitHub Profile
@nixta
nixta / .htaccess
Last active March 19, 2024 22:52
.htaccess to add CORS to your website
# Add these three lines to CORSify your server for everyone.
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
@nixta
nixta / AGSGeometry+DecodeCompressedGeometry.swift
Last active December 9, 2022 18:06
Read polyline from ArcGIS Route Service compressed geometry.
extension AGSGeometry {
static func decodeCompressedGeometry(_ compressedString: String, spatialReference sr: AGSSpatialReference) -> AGSPolyline? {
// Break the string up into signed parts.
// The first part is a coefficient.
// Subsequent pairs of parts make up the remaining coordinates, encoded.
let pattern = #"((\+|\-)[^\+\-]+)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
return nil
}
@nixta
nixta / Bundle+ArcGISRuntimeSDKVersion.swift
Created September 2, 2020 16:56
Read and output ArcGIS Runtime SDK version text.
extension Bundle {
private static let agsBundle = AGSBundle()
/// An end-user printable string representation of the ArcGIS Bundle version shipped with the app.
///
/// For example, "2883"
static var sdkBundleVersion: String {
return (agsBundle?.object(forInfoDictionaryKey: "CFBundleVersion") as? String) ?? "?"
@nixta
nixta / AsyncAwait.swift
Last active December 1, 2021 15:57
Async/Await Example: Download Preplanned Offline Map
func downloadPreplannedOfflineMap() async throws {
guard let area = (try await task.getPreplannedMapAreas()).first else { return }
let params = try await task.defaultDownloadPreplannedOfflineMapParameters(with: area)
let job = task.downloadPreplannedOfflineMapJob(
with: params,
downloadDirectory: docsURL.appendingPathComponent(Date().ISO8601Format(), isDirectory: true)
)
@nixta
nixta / AGSTileInfo+CalculateTiles.swift
Last active August 31, 2021 15:34
Extension to calculate tile image extents overlapped by a given geometry
extension AGSTileInfo {
func calculateTiles(for geometry: AGSGeometry) -> [AGSTileKey: AGSEnvelope]? {
return calculateTiles(for: geometry.extent)?.filter({ item in
let env = item.value
return AGSGeometryEngine.geometry(geometry, intersects: env)
})
}
// Get the tile extents for the greatest level of detail. This is good for downloading tiles for
// elevation queries, but might not be the desired tile count for a range of LODs.
@nixta
nixta / AGSSingleFingerZoomGestureRecognizer.swift
Last active March 23, 2021 13:17
A Google-Maps like single-finger zoom gesture for the ArcGIS Runtime SDK for iOS. Awesome idea, Google Maps team! 👏👏👏
//
// AGSSingleFingerZoomGestureRecognizer.swift
//
// Created by Nicholas Furness on 6/17/16.
// Copyright © 2016 Esri. All rights reserved.
//
import Foundation
import ArcGIS
@nixta
nixta / 1-query.swift
Last active November 22, 2019 17:07
Custom Query
public enum QueryError: LocalizedError {
case couldNotParseJSON
case unexpectedJSONResponse
}
func doQuery(layerURL: URL, mapPoint: AGSPoint, fields: [String] = ["*"], returnGeometry: Bool = true, completion: (([AGSGraphic]?, Error?) -> Void)? = nil) {
var mapPointData: Data?
do {
let mapPointJSON = try mapPoint.toJSON()
mapPointData = try JSONSerialization.data(withJSONObject: mapPointJSON)
@nixta
nixta / ISSLocationDataSource.swift
Created May 1, 2019 21:52
A custom AGSLocationDataSource to integrate the International Space Station's realtime location into the ArcGIS Runtime
import Foundation
import ArcGIS
//MARK: - Custom AGSLocationDataSource
/// A custom AGSLocationDataSource that uses the public ISS Location API to return
/// realtime ISS locations at 5 second intervals.
class ISSLocationDataSource: AGSLocationDataSource {
@nixta
nixta / ViewController.swift
Last active November 10, 2017 18:38
How to drag a graphic with ArcGIS Runtime SDK for iOS
//
// ViewController.swift
// TestDrag
//
// Created by Nicholas Furness on 11/10/17.
// Copyright © 2017 Esri. All rights reserved.
//
import ArcGIS
@nixta
nixta / geofencing.js
Last active May 14, 2017 13:21
A PubNub Geofencing Block (See structure of sample services below at lines 16&17).
export default (request) => {
let query = require('codec/query_string');
// return if the block does not have anything to analyze
if (!query) {
return request.ok();
}
// Require console to print debug information
let console = require('console');