0

I have a main controller with code like this setting up a Mapbox in a portion of the screen, and it works... However the code as documented does not ever trigger the camera viewport moved or tapped. Am I missing a step?

The onCameraChange shows in the log once and not when I pan around the map world.

import UIKit
import MapboxMaps
class ViewController: UIViewController, MapInitOptionsProvider, URLSessionDelegate {
 
 private var mapView: MapView!
 private var cancellables: Set<AnyCancelable> = []
 
 public func mapInitOptions() -> MapInitOptions {
 //TODO... never called???
 let cameraOptions = CameraOptions(center: CLLocationCoordinate2D(latitude: NUMBER, longitude: NUMBER), zoom: 1)
 
 //return a custom MapInitOptions
 return MapInitOptions(
 cameraOptions: cameraOptions,
 styleURI: .light)// StyleURI(rawValue: "mapbox://my/favorite/style/goes/here..."))
 }
 override func viewDidLoad() {
 let defaults = UserDefaults.standard
 
 super.viewDidLoad()
 self.mapView = MapView(frame: view.bounds)
 self.mapView.mapboxMap.mapStyle = MapStyle(uri:StyleURI(rawValue: "mapbox://my-favorite-style")!)
 self.mapView.mapboxMap.onCameraChanged.observe { [weak self] cameraChanged in
 guard let self else { return }
 updateMap()
 print("onCameraChange")
 }.store(in: &cancellables)
 self.mapView.gestures.onMapTap.observe { [unowned self] context in
 print("onMapTap")
 updateMap()
 }.store(in: &cancellables)
 ...
 
asked Oct 22, 2024 at 0:28

1 Answer 1

0

It turns out it needed IBOutlet as described here:

https://www.youtube.com/watch?app=desktop&v=CVqdylyDSao

So within viewcontroller:

@IBOutlet var nameOfview: MapView!

and nameOfview can be referenced.

answered Oct 23, 2024 at 0:33
Sign up to request clarification or add additional context in comments.

1 Comment

Please mark your answer as Accepted.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.