From bafd7d35349fb4dfb9e117970b990fa824e1591c Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Mon, 25 Nov 2024 10:22:07 +1100 Subject: [PATCH 1/2] Add NSImage variant of `GeoDrawer.drawImage` --- ...awer+UIKit.swift => GeoDrawer+Image.swift} | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) rename Sources/GeoDrawer/{GeoDrawer+UIKit.swift => GeoDrawer+Image.swift} (55%) diff --git a/Sources/GeoDrawer/GeoDrawer+UIKit.swift b/Sources/GeoDrawer/GeoDrawer+Image.swift similarity index 55% rename from Sources/GeoDrawer/GeoDrawer+UIKit.swift rename to Sources/GeoDrawer/GeoDrawer+Image.swift index c33b082..fefb802 100644 --- a/Sources/GeoDrawer/GeoDrawer+UIKit.swift +++ b/Sources/GeoDrawer/GeoDrawer+Image.swift @@ -1,5 +1,5 @@ // -// GeoDrawer+UIKit.swift +// GeoDrawer+Image.swift // // // Created by Adrian Schönig on 2/12/2022. @@ -10,8 +10,6 @@ #if canImport(UIKit) import UIKit -// MARK: - Image drawing - extension GeoDrawer { /// Generates an image drawing the provided contents according to the configured @@ -44,4 +42,37 @@ extension GeoDrawer { } +#elseif canImport(AppKit) +import AppKit + +extension GeoDrawer { + + /// Generates an image drawing the provided contents according to the configured + /// projection, zoom and edge insets. When providing the different colours, the background of + /// the map projection itself will be drawn, too. + /// + /// - Parameters: + /// - contents: GeoJSON contents to draw + /// - mapBackground: Background of the map itself + /// - mapOutline: Stroke colour around the map + /// - mapBackdrop: Background to draw outside the map / projection bounds + /// - Returns: New image + public func drawImage(_ contents: [Content], mapBackground: NSColor? = nil, mapOutline: NSColor? = nil, mapBackdrop: NSColor? = nil) -> NSImage { + + let cgSize = CGSize(width: size.width, height: size.height) + return NSImage(size: cgSize, flipped: false) { _ in + guard let context = NSGraphicsContext.current?.cgContext else { return false } + self.draw( + contents, + mapBackground: mapBackground?.cgColor, + mapOutline: mapOutline?.cgColor, + mapBackdrop: mapBackdrop?.cgColor, + in: context + ) + return true + } + } + +} + #endif From 604f33d345c8299616f618b0be7904c0f0b5ab3a Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Mon, 25 Nov 2024 10:52:34 +1100 Subject: [PATCH 2/2] Fix regression in GHA by building for iOS simulator instead --- .github/workflows/swift.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 16583b6..c03dc88 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -60,4 +60,4 @@ jobs: - name: Build run: | cd Examples - xcodebuild build -scheme 'Cassini' -destination 'name=iPhone 14' -sdk iphoneos + xcodebuild build -scheme 'Cassini' -destination 'platform=iOS Simulator,name=iPhone 14' -sdk iphonesimulator