Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Scale control #1278

Closed
1ec5 opened this issue Apr 15, 2015 · 10 comments
Closed

Scale control #1278

1ec5 opened this issue Apr 15, 2015 · 10 comments
Assignees
Labels
feature GL JS parity For feature parity with Mapbox GL JS iOS Mapbox Maps SDK for iOS MapKit parity For feature parity with MapKit on iOS or macOS
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Apr 15, 2015

Apple Maps (but not MKMapView itself) shows a scale (in both miles and kilometers) in the top-left corner of the map view while you pinch to zoom in or out. A scale would be a useful feature to bake into MGLMapView, either off by default or off except while you pinch. It would help to give context, especially since GL doesn’t snap the zoom level to increments and allows very high zoom levels.

@1ec5 1ec5 added feature iOS Mapbox Maps SDK for iOS labels Apr 15, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Oct 28, 2015

Correction: MKMapView.showsScale = YES turns on a persistent scale at the top-left corner.

@Bluezen
Copy link

Bluezen commented Jun 29, 2016

Hi @1ec5 ! Do you know if there is a plan to add this feature in an upcoming release?

If not, how would you recommend me to proceed with the current iOS SDK 3.2.3 if I wanted to show a simple scale ?
Adding a custom UIView on top of the MKMapView which, on every Map position changes (-mapViewRegionIsChanging: -mapView:regionDidChangeAnimated: ), uses visibleCoordinateBounds (or something else ?) to extrapolate and update its display?

@1ec5
Copy link
Contributor Author

1ec5 commented Jun 29, 2016

We haven't scheduled this feature into an upcoming release yet, but we aren't opposed to getting the feature in if someone steps up with an implementation.

In the meantime, you have the right idea with the delegate methods (although you might find -mapViewDidFinishRenderingFrame:fullyRendered: to be more predictable). In terms of calculating the width of the scale's indicators, I'd use -[MGLMapView metersPerPointAtLatitude:], passing in the current center latitude.

If you come up with an implementation that you feel would be appropriate for the SDK, we'd be happy to consider your PR.

@Bluezen
Copy link

Bluezen commented Jun 29, 2016

Thanks for pointing out -[MGLMapView metersPerPointAtLatitude:] and mapViewDidFinishRenderingFrame:fullyRendered !

Okay, if I am satisfied with my implementation I will propose a PR.

@friedbunny
Copy link
Contributor

friedbunny commented Jul 5, 2016

Somewhat relatedly, here’s a quick way to get the geographic distance spanned by the entire map view:

func mapView(mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
     let screenWidthInPoints = Double(mapView.bounds.size.width)
     let metersPerPoint = mapView.metersPerPointAtLatitude(mapView.centerCoordinate.latitude)
     let screenDistanceInMeters = Int(screenWidthInPoints * metersPerPoint)

     print("\(screenWidthInPoints) × \(metersPerPoint) = \(screenDistanceInMeters)m")
}
// Portrait iPhone 6++++
414.0 × 4.87247101190374 = 2017m
// Rotate to landscape
736.0 × 4.87247101190374 = 3586m

@1ec5 1ec5 added the GL JS parity For feature parity with Mapbox GL JS label Aug 19, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Aug 19, 2016

This is GL JS parity issue now that mapbox/mapbox-gl-js#2940 has landed.

@1ec5 1ec5 added the MapKit parity For feature parity with MapKit on iOS or macOS label Aug 19, 2016
@jfirebaugh jfirebaugh changed the title Show a scale on the map (off by default) Scale control Sep 27, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Oct 7, 2016

An Android equivalent is being implemented in #6555.

@andrewstay
Copy link

Could you please update on the progress on this feature?

@frederoni frederoni mentioned this issue Dec 14, 2016
3 tasks
@frederoni
Copy link
Contributor

Work towards this issue is happening in #7432

@boundsj boundsj added this to the ios-v3.5.0 milestone Feb 2, 2017
@1ec5 1ec5 modified the milestones: ios-v3.5.0, ios-v3.6.0 Mar 9, 2017
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 5, 2017

The scale bar is being implemented in #7631.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature GL JS parity For feature parity with Mapbox GL JS iOS Mapbox Maps SDK for iOS MapKit parity For feature parity with MapKit on iOS or macOS
Projects
None yet
Development

No branches or pull requests

6 participants