From 6e8416c10c6f4386ef27416a892b3c0b50bcbcb0 Mon Sep 17 00:00:00 2001 From: PW Date: Mon, 22 Jan 2024 13:41:17 +0100 Subject: [PATCH 1/4] Basic CircleStyleLayer --- .../Style Layers/Circle.swift | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Sources/MapLibreSwiftDSL/Style Layers/Circle.swift diff --git a/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift new file mode 100644 index 0000000..9912a1d --- /dev/null +++ b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift @@ -0,0 +1,80 @@ +import Foundation +import InternalUtils +import MapLibre +import MapLibreSwiftMacros + +@MLNStyleProperty("circleRadius", supportsInterpolation: true) +@MLNStyleProperty("circleColor", supportsInterpolation: false) +@MLNStyleProperty("circleStrokeWidth", supportsInterpolation: true) +@MLNStyleProperty("circleStrokeColor", supportsInterpolation: true) +public struct CircleStyleLayer: SourceBoundStyleLayerDefinition { + public let identifier: String + public var insertionPosition: LayerInsertionPosition = .aboveOthers + public var isVisible: Bool = true + public var maximumZoomLevel: Float? = nil + public var minimumZoomLevel: Float? = nil + + public var source: StyleLayerSource + + public init(identifier: String, source: Source) { + self.identifier = identifier + self.source = .source(source) + } + + public init(identifier: String, source: MLNSource) { + self.identifier = identifier + self.source = .mglSource(source) + } + + public func makeStyleLayer(style: MLNStyle) -> StyleLayer { + let styleSource = addSource(to: style) + + // Register the images with the map style + return CircleStyleLayerInternal(definition: self, mglSource: styleSource) + } + + // MARK: - Modifiers + +} + +private struct CircleStyleLayerInternal: StyleLayer { + private var definition: CircleStyleLayer + private let mglSource: MLNSource + + public var identifier: String { definition.identifier } + public var insertionPosition: LayerInsertionPosition { + get { definition.insertionPosition } + set { definition.insertionPosition = newValue } + } + public var isVisible: Bool { + get { definition.isVisible } + set { definition.isVisible = newValue } + + } + public var maximumZoomLevel: Float? { + get { definition.maximumZoomLevel } + set { definition.maximumZoomLevel = newValue } + } + public var minimumZoomLevel: Float? { + get { definition.minimumZoomLevel } + set { definition.minimumZoomLevel = newValue } + } + + init(definition: CircleStyleLayer, mglSource: MLNSource) { + self.definition = definition + self.mglSource = mglSource + } + + public func makeMLNStyleLayer() -> MLNStyleLayer { + let result = MLNCircleStyleLayer(identifier: identifier, source: mglSource) + + result.circleRadius = definition.circleRadius + + result.circleStrokeColor = definition.circleStrokeColor + result.circleStrokeWidth = definition.circleStrokeWidth + + result.circleColor = definition.circleColor + + return result + } +} From d71bec432907a0274463a7e6baa65b69cc8a40e7 Mon Sep 17 00:00:00 2001 From: PW Date: Tue, 23 Jan 2024 13:25:27 +0100 Subject: [PATCH 2/4] adding example --- Sources/MapLibreSwiftUI/Examples/Layers.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/MapLibreSwiftUI/Examples/Layers.swift b/Sources/MapLibreSwiftUI/Examples/Layers.swift index ee0205e..7cba97a 100644 --- a/Sources/MapLibreSwiftUI/Examples/Layers.swift +++ b/Sources/MapLibreSwiftUI/Examples/Layers.swift @@ -58,6 +58,20 @@ struct Layer_Previews: PreviewProvider { } .ignoresSafeArea(.all) .previewDisplayName("Rotated Symbols (Dynamic)") + + MapView(styleURL: demoTilesURL) { + // Simple symbol layer demonstration with an icon + CircleStyleLayer(identifier: "simple-circles", source: pointSource) + .circleRadius(constant: 16) + .circleColor(constant: .systemRed) + .circleStrokeWidth(constant: 2) + .circleStrokeColor(constant: .white) + . + SymbolStyleLayer(identifier: "simple-symbols", source: pointSource) + .iconImage(constant: UIImage(systemName: "mappin")!) + } + .ignoresSafeArea(.all) + .previewDisplayName("Circles with Symbols") // FIXME: This appears to be broken upstream; waiting for a new release // MapView(styleURL: demoTilesURL) { From e44102ba1a2c33269eafe409932ebf61207331b3 Mon Sep 17 00:00:00 2001 From: PW Date: Sat, 27 Jan 2024 21:26:18 +0100 Subject: [PATCH 3/4] adding iconColor for symbols, better circle example --- Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift | 3 +++ Sources/MapLibreSwiftUI/Examples/Layers.swift | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift b/Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift index 29ddac3..f0baaf8 100644 --- a/Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift +++ b/Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift @@ -4,6 +4,8 @@ import MapLibre import MapLibreSwiftMacros @MLNStyleProperty("iconRotation", supportsInterpolation: true) +@MLNStyleProperty("iconColor", supportsInterpolation: true) + public struct SymbolStyleLayer: SourceBoundStyleLayerDefinition { public let identifier: String public var insertionPosition: LayerInsertionPosition = .aboveOthers @@ -99,6 +101,7 @@ private struct SymbolStyleLayerInternal: StyleLayer { result.iconImageName = definition.iconImageName result.iconRotation = definition.iconRotation + result.iconColor = definition.iconColor return result } diff --git a/Sources/MapLibreSwiftUI/Examples/Layers.swift b/Sources/MapLibreSwiftUI/Examples/Layers.swift index 7cba97a..d1b79b1 100644 --- a/Sources/MapLibreSwiftUI/Examples/Layers.swift +++ b/Sources/MapLibreSwiftUI/Examples/Layers.swift @@ -66,9 +66,10 @@ struct Layer_Previews: PreviewProvider { .circleColor(constant: .systemRed) .circleStrokeWidth(constant: 2) .circleStrokeColor(constant: .white) - . + SymbolStyleLayer(identifier: "simple-symbols", source: pointSource) - .iconImage(constant: UIImage(systemName: "mappin")!) + .iconImage(constant: UIImage(systemName: "mappin")!.withRenderingMode(.alwaysTemplate)) + .iconColor(constant: .white) } .ignoresSafeArea(.all) .previewDisplayName("Circles with Symbols") From 72ab59e6aa9aa0954dc9a0b5e0dc8d85eda96b43 Mon Sep 17 00:00:00 2001 From: PW Date: Sun, 28 Jan 2024 17:03:01 +0100 Subject: [PATCH 4/4] removing comment, swifty names --- .../MapLibreSwiftDSL/Style Layers/Circle.swift | 17 ++++++++--------- Sources/MapLibreSwiftUI/Examples/Layers.swift | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift index 9912a1d..8a57aef 100644 --- a/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift +++ b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift @@ -3,10 +3,10 @@ import InternalUtils import MapLibre import MapLibreSwiftMacros -@MLNStyleProperty("circleRadius", supportsInterpolation: true) -@MLNStyleProperty("circleColor", supportsInterpolation: false) -@MLNStyleProperty("circleStrokeWidth", supportsInterpolation: true) -@MLNStyleProperty("circleStrokeColor", supportsInterpolation: true) +@MLNStyleProperty("radius", supportsInterpolation: true) +@MLNStyleProperty("color", supportsInterpolation: false) +@MLNStyleProperty("strokeWidth", supportsInterpolation: true) +@MLNStyleProperty("strokeColor", supportsInterpolation: false) public struct CircleStyleLayer: SourceBoundStyleLayerDefinition { public let identifier: String public var insertionPosition: LayerInsertionPosition = .aboveOthers @@ -29,7 +29,6 @@ public struct CircleStyleLayer: SourceBoundStyleLayerDefinition { public func makeStyleLayer(style: MLNStyle) -> StyleLayer { let styleSource = addSource(to: style) - // Register the images with the map style return CircleStyleLayerInternal(definition: self, mglSource: styleSource) } @@ -68,12 +67,12 @@ private struct CircleStyleLayerInternal: StyleLayer { public func makeMLNStyleLayer() -> MLNStyleLayer { let result = MLNCircleStyleLayer(identifier: identifier, source: mglSource) - result.circleRadius = definition.circleRadius + result.circleRadius = definition.radius + result.circleColor = definition.color - result.circleStrokeColor = definition.circleStrokeColor - result.circleStrokeWidth = definition.circleStrokeWidth + result.circleStrokeWidth = definition.strokeWidth + result.circleStrokeColor = definition.strokeColor - result.circleColor = definition.circleColor return result } diff --git a/Sources/MapLibreSwiftUI/Examples/Layers.swift b/Sources/MapLibreSwiftUI/Examples/Layers.swift index d1b79b1..31ab9ab 100644 --- a/Sources/MapLibreSwiftUI/Examples/Layers.swift +++ b/Sources/MapLibreSwiftUI/Examples/Layers.swift @@ -62,10 +62,10 @@ struct Layer_Previews: PreviewProvider { MapView(styleURL: demoTilesURL) { // Simple symbol layer demonstration with an icon CircleStyleLayer(identifier: "simple-circles", source: pointSource) - .circleRadius(constant: 16) - .circleColor(constant: .systemRed) - .circleStrokeWidth(constant: 2) - .circleStrokeColor(constant: .white) + .radius(constant: 16) + .color(constant: .systemRed) + .strokeWidth(constant: 2) + .strokeColor(constant: .white) SymbolStyleLayer(identifier: "simple-symbols", source: pointSource) .iconImage(constant: UIImage(systemName: "mappin")!.withRenderingMode(.alwaysTemplate))