Repository navigation
[core] Replace mbgl::MapChange with mbgl::MapObserver - #8377
Conversation
|
@brunoabinader, thanks for your PR! By analyzing this pull request, we identified @1ec5, @tmpsantos and @friedbunny to be potential reviewers. |
b3a3780 to
de9c074
Compare
There was a problem hiding this comment.
Suggest s/Region/Camera/g.
There was a problem hiding this comment.
Ack. For now I'm abstaining from renaming the public APIs for Qt & Android. For iOS & macOS I'm adding entries to CHANGELOG.md about the renaming.
There was a problem hiding this comment.
Renaming the public API for iOS and macOS would be a backwards-incompatible change that would require a major version bump. Fortunately, this PR doesn’t touch the public API (MGLMapView.h) at all, only the internal implementation of MGLMapView (MGLMapView.mm), so no changelog entry is required.
There was a problem hiding this comment.
Would it make sense to provide a boolean (or two-valued-enum) parameter to on*Change , rather than having separate on*Change and on*ChangeAnimated methods? Similarly with on*Rendering{Frame,Map}/on*Rendering{Frame,Map}FullyRendered.
There was a problem hiding this comment.
I think so - I'm adding two enums to MapObserver: CameraChangeMode and RenderMode.
There was a problem hiding this comment.
Is there a useful difference between on*RenderingFrame and on*RenderingMap?
There was a problem hiding this comment.
onWillStartRenderingMap() and onDidFinishRenderingMap() are based on MapKit’s -[MKMapViewDelegate mapViewWillStartRenderingMap:] (“when one or more tiles are revealed and require rendering”) and -[MKMapViewDelegate mapViewDidFinishRenderingMap:fullyRendered:] (“finishes rendering all of the currently visible tiles to the best of its ability”), which have analogues in our iOS and macOS SDKs.
If our iOS documentation is to be believed, on*RenderingFrame() would be called on each frame of a camera animation or property transition, even where no additional tiles need to be fetched and displayed. However, I don’t know for sure if that’s how we’ve implemented these notifications, given #2775.
/cc @friedbunny
There was a problem hiding this comment.
In terms of usefulness, we’ve found the “rendering frame” notifications to be useful in situations where the developer wants to synchronize a view atop the map or override some annotation view behavior that we apply on every frame. But the “rendering map” notifications remain more generally useful for knowing when it’s safe to snapshot a map view or have the UI change once the map is quiescent.
There was a problem hiding this comment.
In Objective-C, use BOOL (YES/NO) instead of bool (true/false).
There was a problem hiding this comment.
Remove “on” from the names of this method and others like it. Also, ensure that there’s a word before the parameter that describes the parameter, so that the meaning of the YES or NO is apparent at the call site: -regionWillChangeAnimated:.
There was a problem hiding this comment.
-cameraWillChangeAnimated: would also be acceptable.
The macOS SDK implementation of MGLMapViewDelegate already uses the term “camera” instead of “region”. The iOS SDK implementation blindly copied MapKit’s use of “region” without bringing over MapKit’s MKRegion struct.
We’ll want to fix the public interface when we’re ready for backwards-incompatible changes, but for now, either name works for this internal method.
There was a problem hiding this comment.
-mapViewWillStartLoadingMap
There was a problem hiding this comment.
-mapViewDidFinishRenderingMapFullyRendered:
There was a problem hiding this comment.
-mapViewDidFinishLoadingStyle
There was a problem hiding this comment.
iOS doesn’t need to do anything in response to source changes, since attribution is displayed on-demand. You can safely remove this method and make its caller a no-op.
There was a problem hiding this comment.
Pass in the mbgl::style::Source and rename this method to -sourceDidChange:.
There was a problem hiding this comment.
We should plumb res.error through to here or implement onResourceError() instead to allow the SDKs to provide more information about the failure. Currently, in order to fudge parity with MapKit, the iOS and macOS SDKs have to synthesize an uninformative NSError, but res.error’s message field would be perfect for this purpose.
There was a problem hiding this comment.
Same as above, I'd prefer if we could move this to a platform-specific refactor.
There was a problem hiding this comment.
This suggestion isn’t platform-specific but rather an improvement on the code being added in this PR. Tracking in #8398.
There was a problem hiding this comment.
I see - thanks for the clarification. Let's handle this in #8398 👍
de9c074 to
81b0a2b
Compare
|
|
||
| - (void)notifyGestureDidBegin { | ||
| [self notifyMapChange:mbgl::MapChangeRegionWillChange]; | ||
| bool animated = false; |
There was a problem hiding this comment.
s/bool/BOOL/ and s/false/NO/ (×2)
There was a problem hiding this comment.
I'm a bit confused - I've seen bool usage when the code is a glue between C++ and Objective-C, and BOOL on Objective-C code along this source file - should we open an issue then to fix this for all remaining bools?
There was a problem hiding this comment.
Ok, I think I got it now - this function is not part of the C++ glue and thus should use the Objective-C notation - got it :) Fixing now.
There was a problem hiding this comment.
👍 As a rule of thumb, in Objective-C++ code, if you’re inside an Objective-C class or category (look for @implementation and @end), use Objective-C types; if you’re inside a C++ class or struct, use C++ types. There are some exceptions: for example, I find it useful to use static_cast over C-style casts throughout Objective-C++ code. And std::vector can often be faster than NSMutableArray. This article suggests some more ways C++ can improve Objective-C code, but a lot of it is a matter of preference.
81b0a2b to
71eee82
Compare
71eee82 to
ff2be9f
Compare
|
Qt public API refactor handled in #8419. |
Implements
mbgl::MapObserver, replacingmbgl::MapChangeenumerator andmbgl::Backend::notifyMapChange. Nowmbgl::Backendinherits frommbgl::MapObserver, which provides non-pure virtual equivalents for the enumerator items.Caveats:
QMapboxGL::MapChangeenumerator from the public API.mbgl::MapChange- this is not necessary but finishing up this platform refactor can happen on a separate PR. Once we finish cleaning up the Android platform, then we can safely removembgl::MapChangesource code entirely.Added suggested reviewers for platform-specific patches as well as core changes - please replace yourself with someone else from the mobile team otherwise.
Fixes #6383.