<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Swift Layer List Examples in Swift Maps SDK Questions</title>
    <link>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276127#M53</link>
    <description>&lt;P&gt;Are there any examples of building a layer list from a web map, particularly one with group layers?&amp;nbsp; I am get the layers from map.operationalLayers to show in a List view, but am struggling with getting the sublayer for group layers to appear as children, since the .&amp;nbsp; The layer list is not part of the toolkit, are there plans to have add one in the future?&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2023 12:36:02 GMT</pubDate>
    <dc:creator>Justin_Greco</dc:creator>
    <dc:date>2023-04-06T12:36:02Z</dc:date>
    <item>
      <title>Swift Layer List Examples</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276127#M53</link>
      <description>&lt;P&gt;Are there any examples of building a layer list from a web map, particularly one with group layers?&amp;nbsp; I am get the layers from map.operationalLayers to show in a List view, but am struggling with getting the sublayer for group layers to appear as children, since the .&amp;nbsp; The layer list is not part of the toolkit, are there plans to have add one in the future?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 12:36:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276127#M53</guid>
      <dc:creator>Justin_Greco</dc:creator>
      <dc:date>2023-04-06T12:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Swift Layer List Examples</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276167#M54</link>
      <description>&lt;P&gt;Was a bit easier than I had thought.&amp;nbsp; Here is a code sample:&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;import SwiftUI
import ArcGIS
struct LayerView: View {
    var map: Map
    var body: some View {
        List {
            ForEach(map.operationalLayers, id:\.self) { layer in
                SublayerView(layer: layer)
            }
        }
        .onAppear {
            //make all group layers visible by default
            map.operationalLayers.forEach { layer in
                if (layer.subLayerContents.count &amp;gt; 0) {
                    layer.isVisible = true
                    layer.subLayerContents.forEach { sublayer in
                        if (sublayer.subLayerContents.count &amp;gt; 0) {
                            sublayer.isVisible = true
                        }
                    }
                }
            }
        }
    }
}

struct SublayerView: View {
    var layer: Layer
    @State private var expanded: Bool = false
    var body: some View {
        if (layer.subLayerContents.count &amp;gt; 0) {
            DisclosureGroup(layer.name, isExpanded: $expanded) {
                ForEach(layer.subLayerContents.reversed(), id:\.self.name) {
                    sublayer in
                    if (sublayer.subLayerContents.count &amp;gt; 0) {
                        SublayerView(layer: sublayer as! Layer)
                    } else {
                        Toggle(isOn: Binding&amp;lt;Bool&amp;gt;(get: {sublayer.isVisible}, set: {sublayer.isVisible = $0
                        })) {
                            Text(sublayer.name)
                        }
                    }
                }
            }
        } else {
            Toggle(isOn: Binding&amp;lt;Bool&amp;gt;(get: {layer.isVisible}, set: {layer.isVisible = $0})) {
                Text(layer.name)
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Apr 2023 14:30:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276167#M54</guid>
      <dc:creator>Justin_Greco</dc:creator>
      <dc:date>2023-04-06T14:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Swift Layer List Examples</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276543#M55</link>
      <description>&lt;P&gt;Hello! Thank you for your question and I'm glad you found a solution. A legend or "layers list" is something that we will be implementing in the Swift Toolkit at some point, but there's no firm release date yet.&lt;/P&gt;&lt;P&gt;In the meantime, you solution looks good! You can also take a look at the v100.15 Toolkit's &lt;A href="https://github.com/Esri/arcgis-runtime-toolkit-ios/tree/main/Documentation/LegendViewController" target="_self"&gt;LegendViewController&lt;/A&gt;, and the actual &lt;A href="https://github.com/Esri/arcgis-runtime-toolkit-ios/blob/main/Sources/ArcGISToolkit/LegendViewController.swift" target="_self"&gt;code&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;There are a few things in that code that may be of interest, depending on your requirements:&lt;/P&gt;&lt;P&gt;- Including base maps in the layers list&lt;/P&gt;&lt;P&gt;- Ensuring the Map and Layers are loaded prior to displaying the list&lt;/P&gt;&lt;P&gt;- Displaying symbol swatches for layers&lt;/P&gt;&lt;P&gt;- Hiding/showing scale-dependent layers depending on map scale (applicable primarily for Legends).&lt;/P&gt;&lt;P&gt;Nice work! If you have any more questions, please reach out!&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 14:49:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1276543#M55</guid>
      <dc:creator>MarkDostal</dc:creator>
      <dc:date>2023-04-07T14:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Swift Layer List Examples</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1279221#M60</link>
      <description>&lt;P&gt;Thank you Mark.&amp;nbsp; I was able to incorporate a legend and a opacity slider.&amp;nbsp; Here is some code in case anyone else is trying to do the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;import SwiftUI
import ArcGIS
class LegendSwatch: ObservableObject, Identifiable , Hashable {
    static func == (lhs: LegendSwatch, rhs: LegendSwatch) -&amp;gt; Bool {
        return lhs.label == rhs.label &amp;amp;&amp;amp; lhs.swatch == rhs.swatch
    }
    @Published var label: String
    @Published var swatch: UIImage

    init(label: String, swatch: UIImage) {
        self.label = label
        self.swatch = swatch
    }
    func hash(into hasher: inout Hasher) {
        hasher.combine(label)
        hasher.combine(swatch)
    }
}
struct LayerInfoView: View {
    @State var layer: Layer
    @State private var swatches: [LegendSwatch] = []
    var body: some View {
        ScrollView {
            VStack {
                Text("Opacity")
                Slider(value: $layer.opacity, in: 0...1, step: 0.1) {
                    
                }
               minimumValueLabel: {
                   Text("0%")
               } maximumValueLabel: {
                   Text("100%")
               }
                ForEach(swatches, id: \.self) { swatch in
                    HStack {
                        Image(uiImage: swatch.swatch)
                        Text(swatch.label)
                    }
                }
            }
        }
        .task {
            let infos: [LegendInfo] = try! await layer.legendInfos
            infos.forEach { info in
                Task {
                    let swatch = try? await info.symbol?.makeSwatch(scale: 1.0)
                    self.swatches.append(LegendSwatch(label: info.name, swatch: swatch!))
                }
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Apr 2023 13:18:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/swift-layer-list-examples/m-p/1279221#M60</guid>
      <dc:creator>Justin_Greco</dc:creator>
      <dc:date>2023-04-17T13:18:56Z</dc:date>
    </item>
  </channel>
</rss>

