Begin statistics creation
This commit is contained in:
@@ -11,6 +11,51 @@ struct MapImageCreator {
|
||||
scale: CGFloat = 2.0,
|
||||
lineWidth: CGFloat = 5,
|
||||
paddingFactor: Double = 1.2,
|
||||
lineColor: NSColor = .systemBlue
|
||||
) -> (image: NSImage, imagePoints: [CGPoint])? {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
||||
var result: (image: NSImage, imagePoints: [CGPoint])?
|
||||
|
||||
self.createMapSnapshot(
|
||||
size: layoutSize,
|
||||
scale: scale,
|
||||
lineWidth: lineWidth,
|
||||
paddingFactor: paddingFactor,
|
||||
lineColor: lineColor
|
||||
) { res in
|
||||
result = res
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
semaphore.wait()
|
||||
return result
|
||||
}
|
||||
|
||||
func createMapSnapshot(
|
||||
size layoutSize: CGSize,
|
||||
scale: CGFloat = 2.0,
|
||||
lineWidth: CGFloat = 5,
|
||||
paddingFactor: Double = 1.2,
|
||||
lineColor: NSColor = .systemBlue
|
||||
) async -> (image: NSImage, imagePoints: [CGPoint])? {
|
||||
await withCheckedContinuation { c in
|
||||
self.createMapSnapshot(
|
||||
size: layoutSize,
|
||||
scale: scale,
|
||||
lineWidth: lineWidth,
|
||||
paddingFactor: paddingFactor,
|
||||
lineColor: lineColor
|
||||
) { c.resume(returning: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
func createMapSnapshot(
|
||||
size layoutSize: CGSize,
|
||||
scale: CGFloat = 2.0,
|
||||
lineWidth: CGFloat = 5,
|
||||
paddingFactor: Double = 1.2,
|
||||
lineColor: NSColor = .systemBlue,
|
||||
completion: @escaping ((image: NSImage, imagePoints: [CGPoint])?) -> Void
|
||||
) {
|
||||
guard !locations.isEmpty else {
|
||||
@@ -61,7 +106,7 @@ struct MapImageCreator {
|
||||
path.line(to: point)
|
||||
}
|
||||
|
||||
NSColor.systemBlue.setStroke()
|
||||
lineColor.setStroke()
|
||||
path.lineWidth = lineWidth * scale
|
||||
path.stroke()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user