diff --git a/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift new file mode 100644 index 0000000..8a57aef --- /dev/null +++ b/Sources/MapLibreSwiftDSL/Style Layers/Circle.swift @@ -0,0 +1,79 @@ +import Foundation +import InternalUtils +import MapLibre +import MapLibreSwiftMacros + +@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 + 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) + + 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.radius + result.circleColor = definition.color + + result.circleStrokeWidth = definition.strokeWidth + result.circleStrokeColor = definition.strokeColor + + + return result + } +} 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 ee0205e..31ab9ab 100644 --- a/Sources/MapLibreSwiftUI/Examples/Layers.swift +++ b/Sources/MapLibreSwiftUI/Examples/Layers.swift @@ -58,6 +58,21 @@ 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) + .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)) + .iconColor(constant: .white) + } + .ignoresSafeArea(.all) + .previewDisplayName("Circles with Symbols") // FIXME: This appears to be broken upstream; waiting for a new release // MapView(styleURL: demoTilesURL) {