Created
January 27, 2025 15:10
-
-
Save ryancoughlin/cffdf414ea49f53fbe8a8cfb187551b5 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
import UIKit | |
import MapboxMaps | |
class SSTColorUtil { | |
private static let colors = DatasetType.sst.config.colorScale | |
static func getContourLineExpression(min minTemp: Double, max maxTemp: Double) -> Exp { | |
let range = maxTemp - minTemp | |
var stops: [Exp.Argument] = [] | |
for (index, color) in colors.enumerated() { | |
let temp = minTemp + (range * Double(index) / Double(colors.count - 1)) | |
stops.append(.number(temp)) | |
stops.append(.string(color)) | |
} | |
return Exp(operator: .interpolate, arguments: [ | |
.expression(Exp(operator: .linear, arguments: [])), | |
.expression(Exp(operator: .get, arguments: [.string("temperature")])), | |
] + stops) | |
} | |
static func getLineWidth(isHovered: Bool = false, strength: String? = nil) -> Double { | |
if isHovered { return 5.0 } | |
switch strength { | |
case "strong": return 2.0 | |
case "moderate": return 1.0 | |
default: return 0.75 | |
} | |
} | |
} | |
// Helper for string chunking | |
extension StringProtocol { | |
func chunks(ofCount count: Int) -> [SubSequence] { | |
var chunks: [SubSequence] = [] | |
var i = startIndex | |
while i < endIndex { | |
let j = index(i, offsetBy: count, limitedBy: endIndex) ?? endIndex | |
chunks.append(self[i..<j]) | |
i = j | |
} | |
return chunks | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment