Skip to content

Commit

Permalink
Allow setting map backdrop on GeoMap
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed Sep 18, 2024
1 parent 471e819 commit 51d28ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions Sources/GeoDrawer/GeoMap+AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public class GeoMapView: NSView {
}
}


public var mapBackdrop: NSColor = .white {
didSet {
setNeedsDisplay(bounds)
}
}

public override var frame: NSRect {
didSet {
_drawer = nil
Expand Down Expand Up @@ -87,6 +92,7 @@ public class GeoMapView: NSView {
contents,
mapBackground: mapBackground.cgColor,
mapOutline: mapOutline.cgColor,
mapBackdrop: mapBackdrop.cgColor,
in: context
)
}
Expand All @@ -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] = []
Expand All @@ -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 {
Expand All @@ -130,6 +139,9 @@ public struct GeoMap: NSViewRepresentable {
if let mapOutline {
view.mapOutline = mapOutline
}
if let mapBackdrop {
view.mapBackdrop = mapBackdrop
}
return view
}

Expand All @@ -144,6 +156,9 @@ public struct GeoMap: NSViewRepresentable {
if let mapOutline {
view.mapOutline = mapOutline
}
if let mapBackdrop {
view.mapBackdrop = mapBackdrop
}
}

}
Expand Down
11 changes: 10 additions & 1 deletion Sources/GeoDrawer/GeoMap+UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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 {
Expand All @@ -143,6 +146,9 @@ public struct GeoMap: UIViewRepresentable {
if let mapOutline {
view.mapOutline = mapOutline
}
if let mapBackdrop {
view.backgroundColor = mapBackdrop
}
return view
}

Expand All @@ -157,6 +163,9 @@ public struct GeoMap: UIViewRepresentable {
if let mapOutline {
view.mapOutline = mapOutline
}
if let mapBackdrop {
view.backgroundColor = mapBackdrop
}
}

}
Expand Down

0 comments on commit 51d28ab

Please sign in to comment.