Skip to content

Commit

Permalink
[MAPSIOS-1385] Unify StyleDSL and SwiftUI (#2099)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksproger authored Apr 16, 2024
1 parent efe377c commit 65ddb4a
Show file tree
Hide file tree
Showing 100 changed files with 2,846 additions and 2,321 deletions.
135 changes: 67 additions & 68 deletions Apps/Examples/Examples/SwiftUI Examples/DynamicStylingExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,81 +36,81 @@ struct DynamicStylingExample: View {
@State var viewport: Viewport = .exampleOverview

var body: some View {
Map(viewport: $viewport)
.mapStyle(mapStyle) {
if customAtmosphere {
Atmosphere()
.range(start: 0, end: 12)
.horizonBlend(0.1)
.starIntensity(0.2)
.color(StyleColor(red: 240, green: 196, blue: 152, alpha: 1)!)
.highColor(StyleColor(red: 221, green: 209, blue: 197, alpha: 1)!)
.spaceColor(StyleColor(red: 153, green: 180, blue: 197, alpha: 1)!)
}

if customLights {
DirectionalLight(id: "directional-light")
.intensity(0.5)
.direction(azimuthal: 210, polar: 30)
.directionTransition(.zero)
.castShadows(true)
.shadowIntensity(1)
AmbientLight(id: "ambient-light")
.color(.lightGray)
.intensity(0.5)
}
Map(viewport: $viewport) {
if customAtmosphere {
Atmosphere()
.range(start: 0, end: 12)
.horizonBlend(0.1)
.starIntensity(0.2)
.color(StyleColor(red: 240, green: 196, blue: 152, alpha: 1)!)
.highColor(StyleColor(red: 221, green: 209, blue: 197, alpha: 1)!)
.spaceColor(StyleColor(red: 153, green: 180, blue: 197, alpha: 1)!)
}

if let connectionFeatures {
ConnectionComponent(data: connectionFeatures, kind: connectionKind, color: connectionColor)
}
if customLights {
DirectionalLight(id: "directional-light")
.intensity(0.5)
.direction(azimuthal: 210, polar: 30)
.directionTransition(.zero)
.castShadows(true)
.shadowIntensity(1)
AmbientLight(id: "ambient-light")
.color(.lightGray)
.intensity(0.5)
}

if let pinFeatures {
LazyGeoJSON(id: "points", features: pinFeatures)
StyleImage(id: "pin-icon", image: pinIcon.image)
SymbolLayer(id: "pin", source: "points")
.iconImage("pin-icon")
if styleTransitions {
TransitionOptions(duration: 5)
}
}
if let connectionFeatures {
ConnectionComponent(data: connectionFeatures, kind: connectionKind, color: connectionColor)
}

if let route {
RouteLine(id: "LA-SF", featureRef: route)
if let pinFeatures {
LazyGeoJSON(id: "points", features: pinFeatures)
StyleImage(id: "pin-icon", image: pinIcon.image)
SymbolLayer(id: "pin", source: "points")
.iconImage("pin-icon")
if styleTransitions {
TransitionOptions(duration: 5)
}

ModelsComponent()
}
.additionalSafeAreaInsets(.bottom, settingsHeight)
.onLayerTapGesture("connection-fill") { _, _ in
connectionColor = .random
return true
}
.debugOptions(.camera)
.ignoresSafeArea()
.safeOverlay(alignment: .bottom) {
settingsBody
.onChangeOfSize { settingsHeight = $0.height }
}
.safeOverlay(alignment: .trailing) {
MapStyleSelectorButton(mapStyle: $mapStyle)
}
.onChange(of: cities) { _ in updateFeatures() }
.onAppear {
updateFeatures()
loadRoute()
connectionColor = .random

if let route {
RouteLine(id: "LA-SF", featureRef: route)
}
.toolbar {
ToolbarItem {
Menu {
Button("Overview") { viewport = .exampleOverview }
Button("Models") { viewport = .modelsOverview }
Button("Route") { viewport = .routeOverview }
} label: {
Text("Jump to...")
}

ModelsComponent()
}
.mapStyle(mapStyle)
.additionalSafeAreaInsets(.bottom, settingsHeight)
.onLayerTapGesture("connection-fill") { _, _ in
connectionColor = .random
return true
}
.debugOptions(.camera)
.ignoresSafeArea()
.safeOverlay(alignment: .bottom) {
settingsBody
.onChangeOfSize { settingsHeight = $0.height }
}
.safeOverlay(alignment: .trailing) {
MapStyleSelectorButton(mapStyle: $mapStyle)
}
.onChange(of: cities) { _ in updateFeatures() }
.onAppear {
updateFeatures()
loadRoute()
connectionColor = .random
}
.toolbar {
ToolbarItem {
Menu {
Button("Overview") { viewport = .exampleOverview }
Button("Models") { viewport = .modelsOverview }
Button("Route") { viewport = .routeOverview }
} label: {
Text("Jump to...")
}
}
}
}


Expand Down Expand Up @@ -233,7 +233,6 @@ struct RouteLine: MapStyleContent {
.lineBorderColor("#327AC2")
.lineEmissiveStrength(1)
.slot("middle")

}
}

Expand Down
Loading

0 comments on commit 65ddb4a

Please sign in to comment.