Mapbox-gl-native: Scale Bar is broken on zoom levels 1/2/3/4

Created on 3 Jul 2019  路  11Comments  路  Source: mapbox/mapbox-gl-native

Steps to reproduce

  1. Open the map
  2. Zoom

Expected behavior

  • Scale Bar is showing all zoom leves

Actual behavior

  • Scale Bars is broken on zoom levels 1/2/3/4

Configuration

Mapbox SDK versions: 5.1.1

Screenshot 2019-07-03 at 11 56 23

Screenshot 2019-07-03 at 11 56 35

archived bug iOS needs reproduction

All 11 comments

Thanks @racer1988!

Automatically hiding the scale bar at ~z1-z4 is actually intentional and is mildly documented:

The scale bar may not be shown at all zoom levels.

Here鈥檚 the logic that controls the allowable range of distances the scale bar can show:

https://github.com/mapbox/mapbox-gl-native/blob/12e0a6b0c67bc2356dbe83d7ab19efdd9a3dc2ea/platform/ios/src/MGLScaleBar.mm#L264-L283

We can consider this as a feature request, though 鈥斅爉uch as we鈥檙e adding visibility customization to the compass (https://github.com/mapbox/mapbox-gl-native/issues/9562#issuecomment-316772669), we could follow MapKit鈥檚 lead again and add a similar configuration option to the scale bar.

@friedbunny I am happy to it not be shown at zoom 1-4.
However this is a Bug.

The Scale Bar is shown Squashed.

check the screenshot. the arrow points to what is the visible scalebar

Ah, I see, apologies @racer1988... I can鈥檛 reproduce this bug, in that case. 馃槃 The labels do bunch up after the bar disappears (which isn鈥檛 great), but they also disappear very quickly (~hundreds of milliseconds) soon after.

Could you say more about how鈥檙e you鈥檙e using the scale bar? Is it enabled via MGLMapView.showsScale or more directly via MGLMapView.scaleBar.hidden?

I Hide the scalebar with a timer when the user stop zooming:

UIView.animate(withDuration: 0.3, delay: 0.0, options: .beginFromCurrentState, animations: { [weak self] in
            self?.mapView.scaleBar.alpha = 0.0
        }) { [weak self] _ in
            self?.mapView.showsScale = false
        }

and when the zoom starts I show it

mapView.scaleBar.alpha = 1.0
        mapView.showsScale = true

@friedbunny Found a way to reproduce consistently.
for me the squashed labels are disappearing only after the gesture is finished completely.

So if I zoom back and keep my fingers on the map, the labels stay squashed.

In that case the label and the bar should disappear together and not be indipendentely hidden (at different times)

private func handleZoomOnScale() {
        guard configuration.showsScale else {
            return
        }

        mapView.scaleBar.alpha = 1.0
        mapView.showsScale = true

        hideScaleTimer?.invalidate()
        hideScaleTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false, block: { [weak self] (timer) in
            guard timer.isValid else {
                return
            }

            self?.hideScale()
        })
    }

    private func hideScale(animated: Bool = true) {
        hideScaleTimer?.invalidate()
        hideScaleTimer = nil
        guard animated == true else {
            mapView.showsScale = false
            return
        }
        UIView.animate(withDuration: 0.3, delay: 0.0, options: .beginFromCurrentState, animations: { [weak self] in
            self?.mapView.scaleBar.alpha = 0.0
        }) { [weak self] _ in
            self?.mapView.showsScale = false
        }
    }

func mapView(_ mapView: MGLMapView, regionIsChangingWith reason: MGLCameraChangeReason) {

        if reason.contains(.gesturePinch) ||
            reason.contains(.gestureZoomIn) ||
            reason.contains(.gestureZoomOut) {
            handleZoomOnScale()
        }
}

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings