From 51d28ab0b267396ae8dc813327708ce268053a53 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Wed, 18 Sep 2024 10:34:48 +1000 Subject: [PATCH] Allow setting map backdrop on GeoMap --- Sources/GeoDrawer/GeoMap+AppKit.swift | 19 +++++++++++++++++-- Sources/GeoDrawer/GeoMap+UIKit.swift | 11 ++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Sources/GeoDrawer/GeoMap+AppKit.swift b/Sources/GeoDrawer/GeoMap+AppKit.swift index ecf21af..a586c80 100644 --- a/Sources/GeoDrawer/GeoMap+AppKit.swift +++ b/Sources/GeoDrawer/GeoMap+AppKit.swift @@ -52,7 +52,12 @@ public class GeoMapView: NSView { } } - + public var mapBackdrop: NSColor = .white { + didSet { + setNeedsDisplay(bounds) + } + } + public override var frame: NSRect { didSet { _drawer = nil @@ -87,6 +92,7 @@ public class GeoMapView: NSView { contents, mapBackground: mapBackground.cgColor, mapOutline: mapOutline.cgColor, + mapBackdrop: mapBackdrop.cgColor, in: context ) } @@ -95,13 +101,14 @@ public class GeoMapView: NSView { @available(macOS 10.15, *) public struct GeoMap: NSViewRepresentable { - public init(contents: [GeoDrawer.Content] = [], projection: Projection = Projections.Equirectangular(), zoomTo: GeoJSON.BoundingBox? = nil, insets: GeoProjector.EdgeInsets = .zero, mapBackground: NSColor? = nil, mapOutline: NSColor? = nil) { + public init(contents: [GeoDrawer.Content] = [], projection: Projection = Projections.Equirectangular(), zoomTo: GeoJSON.BoundingBox? = nil, insets: GeoProjector.EdgeInsets = .zero, mapBackground: NSColor? = nil, mapOutline: NSColor? = nil, mapBackdrop: NSColor? = nil) { self.contents = contents self.projection = projection self.zoomTo = zoomTo self.insets = insets self.mapBackground = mapBackground self.mapOutline = mapOutline + self.mapBackdrop = mapBackdrop } public var contents: [GeoDrawer.Content] = [] @@ -116,6 +123,8 @@ public struct GeoMap: NSViewRepresentable { public var mapOutline: NSColor? = nil + public var mapBackdrop: NSColor? = nil + public typealias NSViewType = GeoMapView public func makeNSView(context: Context) -> GeoMapView { @@ -130,6 +139,9 @@ public struct GeoMap: NSViewRepresentable { if let mapOutline { view.mapOutline = mapOutline } + if let mapBackdrop { + view.mapBackdrop = mapBackdrop + } return view } @@ -144,6 +156,9 @@ public struct GeoMap: NSViewRepresentable { if let mapOutline { view.mapOutline = mapOutline } + if let mapBackdrop { + view.mapBackdrop = mapBackdrop + } } } diff --git a/Sources/GeoDrawer/GeoMap+UIKit.swift b/Sources/GeoDrawer/GeoMap+UIKit.swift index 8120c82..6410244 100644 --- a/Sources/GeoDrawer/GeoMap+UIKit.swift +++ b/Sources/GeoDrawer/GeoMap+UIKit.swift @@ -108,13 +108,14 @@ public class GeoMapView: UIView { @available(iOS 13.0, visionOS 1.0, *) public struct GeoMap: UIViewRepresentable { - public init(contents: [GeoDrawer.Content] = [], projection: Projection = Projections.Equirectangular(), zoomTo: GeoJSON.BoundingBox? = nil, insets: GeoProjector.EdgeInsets = .zero, mapBackground: UIColor? = nil, mapOutline: UIColor? = nil) { + public init(contents: [GeoDrawer.Content] = [], projection: Projection = Projections.Equirectangular(), zoomTo: GeoJSON.BoundingBox? = nil, insets: GeoProjector.EdgeInsets = .zero, mapBackground: UIColor? = nil, mapOutline: UIColor? = nil, mapBackdrop: UIColor? = nil) { self.contents = contents self.projection = projection self.zoomTo = zoomTo self.insets = insets self.mapBackground = mapBackground self.mapOutline = mapOutline + self.mapBackdrop = mapBackdrop } public var contents: [GeoDrawer.Content] = [] @@ -129,6 +130,8 @@ public struct GeoMap: UIViewRepresentable { public var mapOutline: UIColor? = nil + public var mapBackdrop: UIColor? = nil + public typealias UIViewType = GeoMapView public func makeUIView(context: Context) -> GeoMapView { @@ -143,6 +146,9 @@ public struct GeoMap: UIViewRepresentable { if let mapOutline { view.mapOutline = mapOutline } + if let mapBackdrop { + view.backgroundColor = mapBackdrop + } return view } @@ -157,6 +163,9 @@ public struct GeoMap: UIViewRepresentable { if let mapOutline { view.mapOutline = mapOutline } + if let mapBackdrop { + view.backgroundColor = mapBackdrop + } } }