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