Mapbox-gl-native: Move compass view [iOS]

Created on 9 Feb 2017  路  7Comments  路  Source: mapbox/mapbox-gl-native

Hello, is there possible to move compass view to another place?

iOS

Most helpful comment

you should override viewDidLayoutSubviews() method and reset location for compassView
ex:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    var centerPoint = self.mapView.compassView.center
    centerPoint.y += compassOriginY
    self.mapView.compassView.center = centerPoint
}

All 7 comments

This seems to be a duplicate of #8003
The first option in https://github.com/mapbox/mapbox-gl-native/issues/8003#issuecomment-278644190 is not a possible fix for this issue, however, the second option would work.

Closing in favor of #8003

I've actually found a nifty solution to adjust the top constraint in Swift 3.0.

    // var get set so that compass doesn't get change upon re-layout
    private var compassOriginY: CGFloat = 44

    override func updateConstraints() {
        super.updateConstraints()

        // Get constrait for the top edge
        for constraint in self.constraints where constraint.firstItem as? NSObject == self.compassView {

            constraint.constant = compassOriginY
        }
    }

Amazingly, you can access the trailing constraint (x axis) by changing constraint.firstItem to .secondItem too!

you should override viewDidLayoutSubviews() method and reset location for compassView
ex:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    var centerPoint = self.mapView.compassView.center
    centerPoint.y += compassOriginY
    self.mapView.compassView.center = centerPoint
}

How can I move the compass in Android?

How can I change compassView bounds ?

Is it just me, or did this stop working? Fine for a long time for me, but now it wants to move the compass back to the default position.

@Tapestes same for me

Was this page helpful?
0 / 5 - 0 ratings