Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLatLngBounds is poorly named #1513

Closed
1ec5 opened this issue Aug 11, 2023 · 4 comments
Closed

setLatLngBounds is poorly named #1513

1ec5 opened this issue Aug 11, 2023 · 4 comments
Labels

Comments

@1ec5
Copy link
Contributor

1ec5 commented Aug 11, 2023

#1455 adds the methods -[MLNMapView setLatLngBounds:] and -[MLNMapView clearLatLnBounds], which are poorly named. Effectively, the iOS/macOS SDK now has a method named after the Android SDK’s LatLngBounds class, which makes little sense. That class is analogous to the MLNCoordinateBounds struct on iOS/macOS, so it should be called something like setCoordinateBounds.

Better yet, it should be modeled as a property called something more descriptive like viewableCoordinateBounds. As it is, this is a write-only property, nearly unprecedented in any Objective-C framework. “Clearing” the coordinate bounds could be tricky because MLNCoordinateBounds is a struct, which can’t nullable (optional) in Objective-C. Typically, this library has dealt with that issue by allowing the property to be set to a magic value of some kind. In this case, MLNGeometry.h could define a constant MLNCoordinateBoundsWorld that encompasses the entire coordinate system.

Regardless, there should not be any symbol with “LatLngBounds” in its name. This violates multiple Cocoa naming conventions, including the prohibition on superfluous abbreviations.

@louwers louwers added the iOS label Aug 11, 2023
@louwers
Copy link
Collaborator

louwers commented Aug 11, 2023

Thanks for sharing your perspective. I think the naming comes from the internal C++ API that is called, not the Android SDK. That said your arguments for changing the API make sense and I would be happy to merge an alternate API before the next release if someone make a PR for it.

Related issue which argues to smooth over the differences between the platform SDKs #1462

@1ec5
Copy link
Contributor Author

1ec5 commented Aug 11, 2023

I think the naming comes from the internal C++ API that is called, not the Android SDK.

You’re right that it’s a little more complex than I described earlier. mbgl::LatLngBounds was originally called BoundingBox but was renamed to LatLngBounds in mapbox/mapbox-gl-native@78cbab9 as part of mapbox/mapbox-gl-native#1018 mapbox/mapbox-gl-native#1021. Consistency with GL JS was given as the reason.1 GL JS got the term from Leaflet (mapbox/mapbox-gl-js#369), and Leaflet probably got the term from Google Maps. However, on the mobile platforms, the LatLngBounds terminology was never exposed to external developers until the Android SDK later renamed CoordinateBounds to LatLngBounds, again for consistency with Google Maps: mapbox/mapbox-gl-native#2896 (comment).

So in short, this method is named after something in Google Maps. Consistency with other platforms is one thing, but this method is very inconsistent with other parts of this library and the language it’s written in. After all, MLNCoordinateBounds is named after CLLocationCoordinate2D – the iOS/macOS SDK uses this type from Core Location rather than defining its own LatLng type. @JulianBissekkou, given your work on #1455, would you be open to revisiting that API design?

Footnotes

  1. At the time, the Android SDK still called it BoundingBox. That was introduced in Android Geo API Initial Setup mapbox/mapbox-gl-native#878, but you can follow the history all the way back to tobrun/mapbox-android-sdk@4913abb osmdroid/osmdroid@c0449ad. At some point, a redundant CoordinateBounds type was introduced, but it was removed for Remove CoordinateBounds mapbox/mapbox-gl-native#2896.

@JulianBissekkou
Copy link
Collaborator

@1ec5
Thanks for your Feedback. Sure we can rename and adjust the naming of the API for the upcoming 6.x.x release.
I will describe the platform consistency goals more in the corresponding issue.

josxha added a commit to josxha/flutter-maplibre-gl that referenced this issue May 16, 2024
This method has been removed shortly before the release of v6. Therefore reverting the change made in maplibre@0d43206.

Reverted in: maplibre/maplibre-native#2024
Discussion in: maplibre/maplibre-native#1513
@louwers
Copy link
Collaborator

louwers commented Jun 11, 2024

This didn't make the cut because there was a typo in the method name.

A PR with another name is welcome.

@louwers louwers closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants