Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasemapGallery - Revise example and tutorial #687

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Examples/Examples/BasemapGalleryExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
/// The `Map` displayed in the `MapView`.
@State private var map = Map(basemapStyle: .arcGISImagery)

/// A Boolean value indicating whether to show the basemap gallery.
@State private var showBasemapGallery = false

/// The initial viewpoint of the map.
let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
/// A Boolean value indicating whether the basemap gallery is presented.
@State private var basemapGalleryIsPresented = false

/// The initial list of basemaps.
@State private var basemaps = makeBasemapGalleryItems()

/// The `Map` displayed in the `MapView`.
@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
.sheet(isPresented: $showBasemapGallery) {
MapView(map: map)
.sheet(isPresented: $basemapGalleryIsPresented) {
VStack(alignment: .trailing) {
doneButton
.padding()
Expand All @@ -45,7 +46,7 @@ struct BasemapGalleryExampleView: View {
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Toggle(isOn: $showBasemapGallery) {
Toggle(isOn: $basemapGalleryIsPresented) {
Image("basemap", label: Text("Show base map"))
}
}
Expand All @@ -57,7 +58,7 @@ struct BasemapGalleryExampleView: View {
/// This is especially useful for when the sheet is open an iPhone in landscape.
private var doneButton: some View {
Button {
showBasemapGallery.toggle()
basemapGalleryIsPresented.toggle()
} label: {
Text("Done")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import SwiftUI
import ArcGIS
import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
@State private var map = Map(basemapStyle: .arcGISImagery)

let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
MapView(map: map)
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import SwiftUI
import ArcGIS
import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
@State private var map = Map(basemapStyle: .arcGISImagery)

let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)

@State private var basemaps = makeBasemapGalleryItems()

@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
MapView(map: map)
}

private static func makeBasemapGalleryItems() -> [BasemapGalleryItem] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import SwiftUI
import ArcGIS
import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
@State private var map = Map(basemapStyle: .arcGISImagery)

@State private var showBasemapGallery = false

let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
@State private var basemapGalleryIsPresented = false

@State private var basemaps = makeBasemapGalleryItems()

@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
.sheet(isPresented: $showBasemapGallery) {
MapView(map: map)
.sheet(isPresented: $basemapGalleryIsPresented) {
BasemapGallery(items: basemaps, geoModel: map)
.style(.grid(maxItemWidth: 100))
.padding()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import SwiftUI
import ArcGIS
import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
@State private var map = Map(basemapStyle: .arcGISImagery)

@State private var showBasemapGallery = false

let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
@State private var basemapGalleryIsPresented = false

@State private var basemaps = makeBasemapGalleryItems()

@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
.sheet(isPresented: $showBasemapGallery) {
MapView(map: map)
.sheet(isPresented: $basemapGalleryIsPresented) {
BasemapGallery(items: basemaps, geoModel: map)
.style(.grid(maxItemWidth: 100))
.padding()
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Toggle(isOn: $showBasemapGallery) {
Toggle(isOn: $basemapGalleryIsPresented) {
Image("basemap", label: Text("Show base map"))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import SwiftUI
import ArcGIS
import ArcGISToolkit
import SwiftUI

struct BasemapGalleryExampleView: View {
@State private var map = Map(basemapStyle: .arcGISImagery)

@State private var showBasemapGallery = false

let initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
@State private var basemapGalleryIsPresented = false

@State private var basemaps = makeBasemapGalleryItems()

@State private var map: Map = {
let map = Map(basemapStyle: .arcGISImagery)
map.initialViewpoint = Viewpoint(
center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
scale: 1_000_000
)
return map
}()

var body: some View {
MapView(map: map, viewpoint: initialViewpoint)
.sheet(isPresented: $showBasemapGallery) {
MapView(map: map)
.sheet(isPresented: $basemapGalleryIsPresented) {
VStack(alignment: .trailing) {
doneButton
.padding()
Expand All @@ -27,7 +29,7 @@ struct BasemapGalleryExampleView: View {
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Toggle(isOn: $showBasemapGallery) {
Toggle(isOn: $basemapGalleryIsPresented) {
Image("basemap", label: Text("Show base map"))
}
}
Expand All @@ -36,7 +38,7 @@ struct BasemapGalleryExampleView: View {

private var doneButton: some View {
Button {
showBasemapGallery.toggle()
basemapGalleryIsPresented.toggle()
} label: {
Text("Done")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
@Steps {
@Step {
To begin, set up the parent view.
Initialize a map with a basemap style, create member variable to control when the gallery is shown or hidden and pick an initial viewpoint.
Finally, add a `MapView` to the body of view, passing in the map and initial viewpoint.
Initialize a map with a basemap style and an initial viewpoint.
Create a member variable to control when the gallery is shown or hidden.
Finally, add a `MapView` to the body of view, passing in the map.
@Code(name: "BasemapGalleryExampleView.swift", file: BasemapGalleryStep1)
}

Expand Down