<?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 Re: Zoom to location in Swift Maps SDK Questions</title>
    <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273569#M47</link>
    <description>&lt;P&gt;Oh Awesome! I'm already using the MapViewReader for and identify operation so that will be super simple to implement. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 14:48:08 GMT</pubDate>
    <dc:creator>GBreen</dc:creator>
    <dc:date>2023-03-30T14:48:08Z</dc:date>
    <item>
      <title>Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273511#M42</link>
      <description>&lt;P&gt;I'm really liking the new SwiftUI implementation but I'm having trouble with one thing. I have a button to zoom to the current location. In order to do that I set a viewpoint and it works the first time. But if I move and try to tap it again it doesn't zoom. The workaround is I watch the viewpoint for changes and set it back to nil immediately. Is this the best way to implement zooming or is there some other way to do it? I can't find anything in the docs for it. Here's the example code:&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;struct MapZoomTestView: View {
    @StateObject private var map: Map = {
        let map = Map(basemapStyle: .arcGISTopographic)
        
        map.initialViewpoint = Viewpoint(latitude: 34.02700, longitude: -118.80500, scale: 72_000)
        
        return map
    }()
    @State var viewpoint: Viewpoint? = nil
    let locationDisplay = LocationDisplay(dataSource: SystemLocationDataSource())
    
    init() {
        ArcGISEnvironment.apiKey = APIKey("")
    }
    
    var body: some View {
        MapView(map: map, viewpoint: viewpoint)
            .locationDisplay(locationDisplay)
            .task {
                let locationManager = CLLocationManager()
                if locationManager.authorizationStatus == .notDetermined {
                    locationManager.requestWhenInUseAuthorization()
                }
                
                do {
                    try await locationDisplay.dataSource.start()
                } catch {
                    print("Current Location Cannot Be Shown")
                }
            }
            .overlay(alignment: .bottomLeading) {
                Button {
                    guard let location = locationDisplay.location else {
                        return
                    }
                    
                    viewpoint = Viewpoint(center: location.position, scale: 10_000)
                } label: {
                    Image(systemName: "paperplane.fill")
                }
                .frame(width: 50, height: 50, alignment: .center)
                .background(.regularMaterial)
                .cornerRadius(25.0)
                .padding([.leading, .bottom])
            }
            .onChange(of: viewpoint) { newValue in
                guard newValue != nil else {
                    return
                }
                
                viewpoint = nil
            }
            .ignoresSafeArea()
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 30 Mar 2023 13:33:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273511#M42</guid>
      <dc:creator>GBreen</dc:creator>
      <dc:date>2023-03-30T13:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273541#M43</link>
      <description>&lt;P&gt;I accomplish this by setting the locationDisplay.autoPanMode. &amp;nbsp;Not sure if that is your desired outcome or not.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;appData&lt;/SPAN&gt;.&lt;SPAN&gt;locationDisplay&lt;/SPAN&gt;.autoPanMode = .recenter&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:07:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273541#M43</guid>
      <dc:creator>DuanePfeiffer</dc:creator>
      <dc:date>2023-03-30T14:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273545#M44</link>
      <description>&lt;P&gt;Yeah I thought about that too but then the map follows the user where I just want them to be able to decide when to zoom, not auto pan. I could do something like below but that seems just as hacky&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;locationDisplay.autoPanMode = .recenter
locationDisplay.autoPanMode = .off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:11:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273545#M44</guid>
      <dc:creator>GBreen</dc:creator>
      <dc:date>2023-03-30T14:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273546#M45</link>
      <description>&lt;P&gt;Also I would like a solution that can be used to zoom to other geometries as well, not just the current location if that makes sense.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:12:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273546#M45</guid>
      <dc:creator>GBreen</dc:creator>
      <dc:date>2023-03-30T14:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273568#M46</link>
      <description>&lt;P&gt;What you have works with the beta release. As you have noticed, this isn't ideal. &amp;nbsp;Final (200.1) should be released soon and there will be a much better way to achieve what you are looking for via a MapViewReader and the associated proxy:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;    var body: some View {
        MapViewReader { proxy in
            MapView(map: map, viewpoint: viewpoint)
                .locationDisplay(locationDisplay)
                .task {
                    let locationManager = CLLocationManager()
                    if locationManager.authorizationStatus == .notDetermined {
                        locationManager.requestWhenInUseAuthorization()
                    }
                    
                    do {
                        try await locationDisplay.dataSource.start()
                    } catch {
                        print("Current Location Cannot Be Shown")
                    }
                }
                .overlay(alignment: .bottomLeading) {
                    Button {
                        guard let location = locationDisplay.location else {
                            return
                        }
                        Task {
                            await proxy.setViewpointCenter(location.position, scale: 10_000)
                        }
                    } label: {
                        Image(systemName: "paperplane.fill")
                    }
                    .frame(width: 50, height: 50, alignment: .center)
                    .background(.regularMaterial)
                    .cornerRadius(25.0)
                    .padding([.leading, .bottom])
                }
                .ignoresSafeArea()
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: the call above that sets the viewpoint (`proxy.setViewpointCenter(:scale:)`) will actually animate to the new viewpoint. &amp;nbsp;You can tell that because it's an async call. There will also be an un-animated setViewpoint function on the proxy once we release 200.1.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273568#M46</guid>
      <dc:creator>rolson_esri</dc:creator>
      <dc:date>2023-03-30T14:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273569#M47</link>
      <description>&lt;P&gt;Oh Awesome! I'm already using the MapViewReader for and identify operation so that will be super simple to implement. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 14:48:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1273569#M47</guid>
      <dc:creator>GBreen</dc:creator>
      <dc:date>2023-03-30T14:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to location</title>
      <link>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1280297#M61</link>
      <description>&lt;P&gt;With the 200.1 release, we have a&amp;nbsp;&lt;A href="https://developers.arcgis.com/swift/sample-code/change-viewpoint/" target="_self"&gt;Change viewpoint&lt;/A&gt;&amp;nbsp;sample that shows this API. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 17:15:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/swift-maps-sdk-questions/zoom-to-location/m-p/1280297#M61</guid>
      <dc:creator>Ting</dc:creator>
      <dc:date>2023-04-19T17:15:42Z</dc:date>
    </item>
  </channel>
</rss>

