Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CircleStyleLayer + SymbolStyleLayer.iconColor #17

Merged
merged 8 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions Sources/MapLibreSwiftDSL/Style Layers/Circle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Foundation
import InternalUtils
import MapLibre
import MapLibreSwiftMacros

@MLNStyleProperty<Double>("radius", supportsInterpolation: true)
@MLNStyleProperty<UIColor>("color", supportsInterpolation: false)
@MLNStyleProperty<Double>("strokeWidth", supportsInterpolation: true)
@MLNStyleProperty<UIColor>("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
}
}
3 changes: 3 additions & 0 deletions Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import MapLibre
import MapLibreSwiftMacros

@MLNStyleProperty<Double>("iconRotation", supportsInterpolation: true)
@MLNStyleProperty<UIColor>("iconColor", supportsInterpolation: true)

public struct SymbolStyleLayer: SourceBoundStyleLayerDefinition {
public let identifier: String
public var insertionPosition: LayerInsertionPosition = .aboveOthers
Expand Down Expand Up @@ -99,6 +101,7 @@ private struct SymbolStyleLayerInternal: StyleLayer {

result.iconImageName = definition.iconImageName
result.iconRotation = definition.iconRotation
result.iconColor = definition.iconColor

return result
}
Expand Down
15 changes: 15 additions & 0 deletions Sources/MapLibreSwiftUI/Examples/Layers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading