Stack Overflow Asked by desmeit on December 18, 2021
I have styled the user location icon according to these docs:
https://docs.mapbox.com/ios/maps/examples/user-location-annotation/
It works, but although I worked with camera and pitch, it is displayed in two dimensions. How can i make it that it is in the right perspective of the camera and the pitch effect works?
I added MGLMapCamera with this code:
func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
// Wait for the map to load before initiating the first camera movement.
mapView.camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, altitude: 200, pitch: 50, heading: 0)
}
Isn’t there a camera option mode like gps for Android?
https://docs.mapbox.com/android/maps/examples/location-component-camera-options/
I found a solution.
As far as I can see, there is no way to set this with an option. So I solved it manually:
First, I create an image:
private func setupLayers() {
if arrow == nil {
arrow = CALayer()
let myImage = UIImage(named: "arrow")?.cgImage
arrow.bounds = CGRect(x: 0, y: 0, width: size, height: size)
arrow.contents = myImage
layer.addSublayer(arrow)
}
}
Then I use MGLRadiansFromDegrees to convert from radians to degrees and transform the image with every update:
override func update() {
// Convert Optional to Double
let camerapitch = Double(mapView?.camera.pitch ?? 0)
let pitch: CGFloat = MGLRadiansFromDegrees(camerapitch)
layer.transform = CATransform3DMakeRotation(pitch, 1, 0, 0)
}
Answered by desmeit on December 18, 2021
If you want the annotation view to tilt with the map view, you can use the MGLAnnotationView:scalesWithViewingDistance property. This determines whether the annotation view grows and shrinks as the distance between the viewpoint and the annotation view changes on a tilted map.
When the value of this property is YES and the map is tilted, the annotation view appears smaller if it is towards the top of the view (closer to the horizon) and larger if it is towards the bottom of the view (closer to the viewpoint).
Answered by invaderzizim on December 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP