Skip to content

Commit b6233a0

Browse files
authored
Merge pull request #17 from hactar/circlelayer
CircleStyleLayer + SymbolStyleLayer.iconColor
2 parents a8a2792 + 72ab59e commit b6233a0

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}

Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import MapLibre
44
import MapLibreSwiftMacros
55

66
@MLNStyleProperty<Double>("iconRotation", supportsInterpolation: true)
7+
@MLNStyleProperty<UIColor>("iconColor", supportsInterpolation: true)
8+
79
public struct SymbolStyleLayer: SourceBoundStyleLayerDefinition {
810
public let identifier: String
911
public var insertionPosition: LayerInsertionPosition = .aboveOthers
@@ -99,6 +101,7 @@ private struct SymbolStyleLayerInternal: StyleLayer {
99101

100102
result.iconImageName = definition.iconImageName
101103
result.iconRotation = definition.iconRotation
104+
result.iconColor = definition.iconColor
102105

103106
return result
104107
}

Sources/MapLibreSwiftUI/Examples/Layers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ struct Layer_Previews: PreviewProvider {
5858
}
5959
.ignoresSafeArea(.all)
6060
.previewDisplayName("Rotated Symbols (Dynamic)")
61+
62+
MapView(styleURL: demoTilesURL) {
63+
// Simple symbol layer demonstration with an icon
64+
CircleStyleLayer(identifier: "simple-circles", source: pointSource)
65+
.radius(constant: 16)
66+
.color(constant: .systemRed)
67+
.strokeWidth(constant: 2)
68+
.strokeColor(constant: .white)
69+
70+
SymbolStyleLayer(identifier: "simple-symbols", source: pointSource)
71+
.iconImage(constant: UIImage(systemName: "mappin")!.withRenderingMode(.alwaysTemplate))
72+
.iconColor(constant: .white)
73+
}
74+
.ignoresSafeArea(.all)
75+
.previewDisplayName("Circles with Symbols")
6176

6277
// FIXME: This appears to be broken upstream; waiting for a new release
6378
// MapView(styleURL: demoTilesURL) {

0 commit comments

Comments
 (0)