Skip to content

Commit

Permalink
Merge pull request #17 from hactar/circlelayer
Browse files Browse the repository at this point in the history
CircleStyleLayer + SymbolStyleLayer.iconColor
  • Loading branch information
ianthetechie authored Jan 28, 2024
2 parents a8a2792 + 72ab59e commit b6233a0
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
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

0 comments on commit b6233a0

Please sign in to comment.