Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hactar committed Apr 29, 2024
1 parent 4d69cd5 commit 486013d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
9 changes: 6 additions & 3 deletions Sources/MapLibreSwiftDSL/ShapeDataBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ public enum ShapeData {

public struct ShapeSource: Source {
public let identifier: String
public let options: [MLNShapeSourceOption : Any]?
public let options: [MLNShapeSourceOption: Any]?
let data: ShapeData

public init(identifier: String, options: [MLNShapeSourceOption : Any]? = nil, @ShapeDataBuilder _ makeShapeDate: () -> ShapeData) {
public init(
identifier: String,
options: [MLNShapeSourceOption: Any]? = nil,
@ShapeDataBuilder _ makeShapeDate: () -> ShapeData
) {
self.identifier = identifier
self.options = options
data = makeShapeDate()

}

public func makeMGLSource() -> MLNSource {
Expand Down
4 changes: 0 additions & 4 deletions Sources/MapLibreSwiftDSL/Style Layers/Circle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import MapLibreSwiftMacros
@MLNStyleProperty<Double>("strokeWidth", supportsInterpolation: true)
@MLNStyleProperty<UIColor>("strokeColor", supportsInterpolation: false)
public struct CircleStyleLayer: SourceBoundVectorStyleLayerDefinition {

public let identifier: String
public var insertionPosition: LayerInsertionPosition = .aboveOthers
public var isVisible: Bool = true
Expand All @@ -35,8 +34,6 @@ public struct CircleStyleLayer: SourceBoundVectorStyleLayerDefinition {
}

// MARK: - Modifiers


}

private struct CircleStyleLayerInternal: StyleLayer {
Expand Down Expand Up @@ -80,7 +77,6 @@ private struct CircleStyleLayerInternal: StyleLayer {

result.predicate = definition.predicate


return result
}
}
3 changes: 1 addition & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ private struct LineStyleLayerInternal: StyleLayer {
result.lineCap = definition.lineCap
result.lineWidth = definition.lineWidth
result.lineJoin = definition.lineJoin

result.predicate = definition.predicate


return result
}
Expand Down
12 changes: 5 additions & 7 deletions Sources/MapLibreSwiftDSL/Style Layers/Style Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,30 @@ public protocol SourceBoundStyleLayerDefinition: StyleLayerDefinition {
var source: StyleLayerSource { get set }
}


/// Based on MLNVectorStyleLayer
public protocol SourceBoundVectorStyleLayerDefinition: SourceBoundStyleLayerDefinition {
/**
The style layer’s predicate.

Use the style layer’s predicate to include only the features in the source
layer that satisfy a condition that you define.

See the *Predicates and Expressions*
guide for details about the predicate syntax supported by this class.
*/
var predicate: NSPredicate? { get set }

func predicate(_ predicate: NSPredicate) -> Self
}

extension SourceBoundVectorStyleLayerDefinition {
public func predicate(_ predicate: NSPredicate) -> Self {
public extension SourceBoundVectorStyleLayerDefinition {
func predicate(_ predicate: NSPredicate) -> Self {
modified(self) { it in
it.predicate = predicate
}
}
}


extension SourceBoundStyleLayerDefinition {
func addSource(to style: MLNStyle) -> MLNSource {
let tmpSource: MLNSource
Expand Down
6 changes: 2 additions & 4 deletions Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ private struct SymbolStyleLayerInternal: StyleLayer {
result.text = definition.text
result.textColor = definition.textColor
result.textFontSize = definition.textFontSize

result.iconAllowsOverlap = definition.iconAllowsOverlap

result.predicate = definition.predicate


result.predicate = definition.predicate

return result
}
Expand Down
30 changes: 16 additions & 14 deletions Sources/MapLibreSwiftUI/Examples/Layers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ let pointSource = ShapeSource(identifier: "points") {
let clustered = ShapeSource(identifier: "points", options: [.clustered: true, .clusterRadius: 44]) {
// Uses the DSL to quickly construct point features inline
MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 48.2082, longitude: 16.3719))

MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 48.3082, longitude: 16.3719))

MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 48.2082, longitude: 16.9719))

MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 48.0082, longitude: 17.9719))
}

Expand Down Expand Up @@ -89,37 +89,39 @@ let clustered = ShapeSource(identifier: "points", options: [.clustered: true, .c
}

#Preview("Clustered Circles with Symbols") {
@State var camera = MapViewCamera.center(CLLocationCoordinate2D(latitude: 48.2082, longitude: 16.3719), zoom: 5, direction: 0)
@State var camera = MapViewCamera.center(
CLLocationCoordinate2D(latitude: 48.2082, longitude: 16.3719),
zoom: 5,
direction: 0
)
return MapView(styleURL: demoTilesURL, camera: $camera) {
// Clusters pins when they would touch

// Cluster == YES shows only those pins that are clustered, using .text
CircleStyleLayer(identifier: "simple-circles-clusters", source: clustered)
.radius(16)
.color(.systemRed)
.strokeWidth(2)
.strokeColor(.white)
.predicate(NSPredicate(format: "cluster == YES"))

SymbolStyleLayer(identifier: "simple-symbols-clusters", source: clustered)
.textColor(.white)
.text(expression: NSExpression(format: "CAST(point_count, 'NSString')"))
.predicate(NSPredicate(format: "cluster == YES"))



// Cluster != YES shows only those pins that are not clustered, using an icon
CircleStyleLayer(identifier: "simple-circles-non-clusters", source: clustered)
.radius(16)
.color(.systemRed)
.strokeWidth(2)
.strokeColor(.white)
.predicate(NSPredicate(format: "cluster != YES"))

SymbolStyleLayer(identifier: "simple-symbols-non-clusters", source: clustered)
.iconImage(UIImage(systemName: "mappin")!.withRenderingMode(.alwaysTemplate))
.iconColor(.white)
.predicate(NSPredicate(format: "cluster != YES"))


SymbolStyleLayer(identifier: "simple-symbols-non-clusters", source: clustered)
.iconImage(UIImage(systemName: "mappin")!.withRenderingMode(.alwaysTemplate))
.iconColor(.white)
.predicate(NSPredicate(format: "cluster != YES"))
}
.ignoresSafeArea(.all)
}
Expand Down

0 comments on commit 486013d

Please sign in to comment.