-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for FillStyleLayer (#66)
* Add support for FillStyleLayer. * linting
- Loading branch information
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Sources/MapLibreSwiftDSL/Style Layers/FillStyleLayer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Foundation | ||
import InternalUtils | ||
import MapLibre | ||
import MapLibreSwiftMacros | ||
|
||
// TODO: Other properties and their modifiers | ||
@MLNStyleProperty<UIColor>("fillColor", supportsInterpolation: true) | ||
@MLNStyleProperty<UIColor>("fillOutlineColor", supportsInterpolation: true) | ||
@MLNStyleProperty<Float>("fillOpacity", supportsInterpolation: true) | ||
public struct FillStyleLayer: SourceBoundVectorStyleLayerDefinition { | ||
public let identifier: String | ||
public let sourceLayerIdentifier: 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 var predicate: NSPredicate? | ||
|
||
public init(identifier: String, source: Source) { | ||
self.identifier = identifier | ||
self.source = .source(source) | ||
sourceLayerIdentifier = nil | ||
} | ||
|
||
public init(identifier: String, source: MLNSource, sourceLayerIdentifier: String? = nil) { | ||
self.identifier = identifier | ||
self.source = .mglSource(source) | ||
self.sourceLayerIdentifier = sourceLayerIdentifier | ||
} | ||
|
||
public func makeStyleLayer(style: MLNStyle) -> StyleLayer { | ||
let styleSource = addSource(to: style) | ||
|
||
return FillStyleLayerInternal(definition: self, mglSource: styleSource) | ||
} | ||
} | ||
|
||
private struct FillStyleLayerInternal: StyleLayer { | ||
private var definition: FillStyleLayer | ||
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: FillStyleLayer, mglSource: MLNSource) { | ||
self.definition = definition | ||
self.mglSource = mglSource | ||
} | ||
|
||
public func makeMLNStyleLayer() -> MLNStyleLayer { | ||
let result = MLNFillStyleLayer(identifier: identifier, source: mglSource) | ||
|
||
result.fillColor = definition.fillColor | ||
result.fillOutlineColor = definition.fillOutlineColor | ||
result.fillOpacity = definition.fillOpacity | ||
|
||
result.predicate = definition.predicate | ||
|
||
return result | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/MapLibreSwiftUI/Examples/FillStyleLayerPreviews.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import MapLibre | ||
import MapLibreSwiftDSL | ||
import SwiftUI | ||
|
||
@available(iOS 17.0, *) | ||
#Preview { | ||
@Previewable let source = ShapeSource(identifier: "fillSource") { | ||
MLNPolygonFeature(coordinates: austriaPolygon, count: UInt(austriaPolygon.count)) | ||
} | ||
MapView(styleURL: demoTilesURL, camera: .constant(.center(austriaPolygon.first!, zoom: 4))) { | ||
FillStyleLayer(identifier: "fillLayer", source: source) | ||
.fillColor(.red) | ||
.fillOpacity(0.5) | ||
.fillOutlineColor(.blue) | ||
} | ||
|
||
.ignoresSafeArea(.all) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters