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

Commit

Permalink
[android] - ensure that camera is invalidated before generating telem…
Browse files Browse the repository at this point in the history
…etry event
  • Loading branch information
Łukasz Paczos committed Jun 1, 2018
1 parent a5a8661 commit 37b27d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mapbox.android.telemetry.MapEventFactory;
import com.mapbox.android.telemetry.MapState;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MathUtils;
Expand Down Expand Up @@ -885,20 +886,20 @@ private void zoomAnimated(boolean zoomIn, PointF zoomFocalPoint, boolean runImme
}

private void sendTelemetryEvent(String eventType, PointF focalPoint) {
if (isZoomValid(transform)) {
MapEventFactory mapEventFactory = new MapEventFactory();
LatLng latLng = projection.fromScreenLocation(focalPoint);
MapState state = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
state.setGesture(eventType);
Telemetry.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, state));
CameraPosition cameraPosition = transform.getCameraPosition();
if (cameraPosition != null) {
double zoom = cameraPosition.zoom;
if (isZoomValid(zoom)) {
MapEventFactory mapEventFactory = new MapEventFactory();
LatLng latLng = projection.fromScreenLocation(focalPoint);
MapState state = new MapState(latLng.getLatitude(), latLng.getLongitude(), zoom);
state.setGesture(eventType);
Telemetry.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, state));
}
}
}

private boolean isZoomValid(Transform transform) {
if (transform == null) {
return false;
}
double mapZoom = transform.getZoom();
private boolean isZoomValid(double mapZoom) {
return mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ void setOnCameraChangeListener(@Nullable MapboxMap.OnCameraChangeListener listen

// Zoom in or out

double getZoom() {
return cameraPosition.zoom;
}

double getRawZoom() {
return mapView.getZoom();
}
Expand Down

0 comments on commit 37b27d2

Please sign in to comment.