From b72ed8f47b3cf3971ae2f5d9aaeb36b6f17f49dc Mon Sep 17 00:00:00 2001 From: PW Date: Mon, 22 Jan 2024 15:36:11 +0100 Subject: [PATCH] moving example to own file --- Sources/MapLibreSwiftUI/Examples/Layers.swift | 13 ------ Sources/MapLibreSwiftUI/Examples/Other.swift | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 Sources/MapLibreSwiftUI/Examples/Other.swift diff --git a/Sources/MapLibreSwiftUI/Examples/Layers.swift b/Sources/MapLibreSwiftUI/Examples/Layers.swift index 99e03f2..ee0205e 100644 --- a/Sources/MapLibreSwiftUI/Examples/Layers.swift +++ b/Sources/MapLibreSwiftUI/Examples/Layers.swift @@ -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) { diff --git a/Sources/MapLibreSwiftUI/Examples/Other.swift b/Sources/MapLibreSwiftUI/Examples/Other.swift new file mode 100644 index 0000000..0e7dec9 --- /dev/null +++ b/Sources/MapLibreSwiftUI/Examples/Other.swift @@ -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") + } +}