Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting map backdrop on GeoMap #25

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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