Skip to content

Commit

Permalink
moving example to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
hactar committed Jan 22, 2024
1 parent f4c5ac3 commit b72ed8f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
13 changes: 0 additions & 13 deletions Sources/MapLibreSwiftUI/Examples/Layers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,6 @@ struct Layer_Previews: PreviewProvider {
}
.ignoresSafeArea(.all)
.previewDisplayName("Rotated Symbols (Dynamic)")

MapView(styleURL: demoTilesURL) {
// Demonstrates how to use the unsafeMapModifier to set MLNMapView properties that have not been exposed as modifiers yet.
SymbolStyleLayer(identifier: "simple-symbols", source: pointSource)
.iconImage(constant: UIImage(systemName: "mappin")!)
}
.unsafeMapViewModifier({ mapView in
// Not all properties have modifiers yet. Until they do, you can use this 'escape hatch' to the underlying MLNMapView. Be careful: if you modify properties that the DSL controls already, they may be overridden. This modifier is a "hack", not a final function.
mapView.logoView.isHidden = false
mapView.compassViewPosition = .topLeft
})
.ignoresSafeArea(.all)
.previewDisplayName("Unsafe MapView Modifier")

// FIXME: This appears to be broken upstream; waiting for a new release
// MapView(styleURL: demoTilesURL) {
Expand Down
40 changes: 40 additions & 0 deletions Sources/MapLibreSwiftUI/Examples/Other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import CoreLocation
import MapLibre
import MapLibreSwiftDSL
import SwiftUI

struct Other_Previews: PreviewProvider {
static var previews: some View {
let demoTilesURL = URL(string: "https://demotiles.maplibre.org/style.json")!

// A collection of points with various
// attributes
let pointSource = ShapeSource(identifier: "points") {
// Uses the DSL to quickly construct point features inline
MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 51.47778, longitude: -0.00139))

MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0)) { feature in
feature.attributes["icon"] = "missing"
feature.attributes["heading"] = 45
}

MLNPointFeature(coordinate: CLLocationCoordinate2D(latitude: 39.02001, longitude: 1.482148)) { feature in
feature.attributes["icon"] = "club"
feature.attributes["heading"] = 145
}
}

MapView(styleURL: demoTilesURL) {
// Demonstrates how to use the unsafeMapModifier to set MLNMapView properties that have not been exposed as modifiers yet.
SymbolStyleLayer(identifier: "simple-symbols", source: pointSource)
.iconImage(constant: UIImage(systemName: "mappin")!)
}
.unsafeMapViewModifier({ mapView in
// Not all properties have modifiers yet. Until they do, you can use this 'escape hatch' to the underlying MLNMapView. Be careful: if you modify properties that the DSL controls already, they may be overridden. This modifier is a "hack", not a final function.
mapView.logoView.isHidden = false
mapView.compassViewPosition = .topLeft
})
.ignoresSafeArea(.all)
.previewDisplayName("Unsafe MapView Modifier")
}
}

0 comments on commit b72ed8f

Please sign in to comment.