|
| 1 | +import Foundation |
| 2 | +import InternalUtils |
| 3 | +import MapLibre |
| 4 | +import MapLibreSwiftMacros |
| 5 | + |
| 6 | +@MLNStyleProperty<Double>("radius", supportsInterpolation: true) |
| 7 | +@MLNStyleProperty<UIColor>("color", supportsInterpolation: false) |
| 8 | +@MLNStyleProperty<Double>("strokeWidth", supportsInterpolation: true) |
| 9 | +@MLNStyleProperty<UIColor>("strokeColor", supportsInterpolation: false) |
| 10 | +public struct CircleStyleLayer: SourceBoundStyleLayerDefinition { |
| 11 | + public let identifier: String |
| 12 | + public var insertionPosition: LayerInsertionPosition = .aboveOthers |
| 13 | + public var isVisible: Bool = true |
| 14 | + public var maximumZoomLevel: Float? = nil |
| 15 | + public var minimumZoomLevel: Float? = nil |
| 16 | + |
| 17 | + public var source: StyleLayerSource |
| 18 | + |
| 19 | + public init(identifier: String, source: Source) { |
| 20 | + self.identifier = identifier |
| 21 | + self.source = .source(source) |
| 22 | + } |
| 23 | + |
| 24 | + public init(identifier: String, source: MLNSource) { |
| 25 | + self.identifier = identifier |
| 26 | + self.source = .mglSource(source) |
| 27 | + } |
| 28 | + |
| 29 | + public func makeStyleLayer(style: MLNStyle) -> StyleLayer { |
| 30 | + let styleSource = addSource(to: style) |
| 31 | + |
| 32 | + return CircleStyleLayerInternal(definition: self, mglSource: styleSource) |
| 33 | + } |
| 34 | + |
| 35 | + // MARK: - Modifiers |
| 36 | + |
| 37 | +} |
| 38 | + |
| 39 | +private struct CircleStyleLayerInternal: StyleLayer { |
| 40 | + private var definition: CircleStyleLayer |
| 41 | + private let mglSource: MLNSource |
| 42 | + |
| 43 | + public var identifier: String { definition.identifier } |
| 44 | + public var insertionPosition: LayerInsertionPosition { |
| 45 | + get { definition.insertionPosition } |
| 46 | + set { definition.insertionPosition = newValue } |
| 47 | + } |
| 48 | + public var isVisible: Bool { |
| 49 | + get { definition.isVisible } |
| 50 | + set { definition.isVisible = newValue } |
| 51 | + |
| 52 | + } |
| 53 | + public var maximumZoomLevel: Float? { |
| 54 | + get { definition.maximumZoomLevel } |
| 55 | + set { definition.maximumZoomLevel = newValue } |
| 56 | + } |
| 57 | + public var minimumZoomLevel: Float? { |
| 58 | + get { definition.minimumZoomLevel } |
| 59 | + set { definition.minimumZoomLevel = newValue } |
| 60 | + } |
| 61 | + |
| 62 | + init(definition: CircleStyleLayer, mglSource: MLNSource) { |
| 63 | + self.definition = definition |
| 64 | + self.mglSource = mglSource |
| 65 | + } |
| 66 | + |
| 67 | + public func makeMLNStyleLayer() -> MLNStyleLayer { |
| 68 | + let result = MLNCircleStyleLayer(identifier: identifier, source: mglSource) |
| 69 | + |
| 70 | + result.circleRadius = definition.radius |
| 71 | + result.circleColor = definition.color |
| 72 | + |
| 73 | + result.circleStrokeWidth = definition.strokeWidth |
| 74 | + result.circleStrokeColor = definition.strokeColor |
| 75 | + |
| 76 | + |
| 77 | + return result |
| 78 | + } |
| 79 | +} |
0 commit comments