-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] - zoom to rounded levels #8299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,14 +155,18 @@ void onPostMapReady() { | |
/** | ||
* Called when the user | ||
*/ | ||
void onUpdate() { | ||
CameraPosition cameraPosition = transform.invalidateCameraPosition(); | ||
uiSettings.update(cameraPosition); | ||
// FIXME introduce update method with camera position | ||
void onUpdateRegionChange() { | ||
trackingSettings.update(); | ||
annotationManager.update(); | ||
} | ||
|
||
void onUpdateFullyRendered() { | ||
CameraPosition cameraPosition = transform.invalidateCameraPosition(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of moving these lines into a private method?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what you mean, this is as simplistic as a method can be: void onUpdateFullyRendered() {
CameraPosition cameraPosition = transform.invalidateCameraPosition();
if (cameraPosition != null) {
uiSettings.update(cameraPosition);
}
moving one line of code to another method is overthinking it + this is high traffic code, being able to not have additional method invocations is a win. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strive to leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if I follow this is neither a public or protected method.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or |
||
if (cameraPosition != null) { | ||
uiSettings.update(cameraPosition); | ||
} | ||
} | ||
|
||
// Style | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,13 +182,17 @@ void zoom(boolean zoomIn, float x, float y) { | |
// Cancel any animation | ||
cancelTransitions(); | ||
|
||
if (zoomIn) { | ||
mapView.scaleBy(2.0, x, y, MapboxConstants.ANIMATION_DURATION); | ||
} else { | ||
mapView.scaleBy(0.5, x, y, MapboxConstants.ANIMATION_DURATION); | ||
CameraPosition cameraPosition = invalidateCameraPosition(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of extracting this code into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me patch this up |
||
if (cameraPosition != null) { | ||
zoom(cameraPosition, zoomIn, x, y); | ||
} | ||
} | ||
|
||
private void zoom(@NonNull CameraPosition cameraPosition, boolean zoomIn, float x, float y) { | ||
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1)); | ||
mapView.setZoom(newZoom, x, y, MapboxConstants.ANIMATION_DURATION); | ||
} | ||
|
||
void setZoom(double zoom) { | ||
mapView.setZoom(zoom); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about decomposing the conditional to make the intention clearer?
We normally end up with long methods and the length of a method is in itself a factor that makes it harder to read (using conditions increase the difficulty even more).
The problem usually lies in the fact that the code tells you what happens but can easily obscure why it happens.
Decomposing the conditional you highlight the condition and make it clearly what you are branching on. You also highlight the reason for the branching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is high traffic code, every small performance gain we can get, we should leverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? Do you think that adding new methods could affect the performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, very much, would love to explore this by profiling and measuring the difference. For now, to get the release out the door, would love to get this PR merged. Feel free to ticket this separately so we don't lose track of it.