Fix auto zoom issue #3391 Zoom level gets reset at every second. (#3564)

* Add method to check if curr location marker is vsible or not

* Recenter map if users see their current location marker

* Add new methods to Contract
This commit is contained in:
neslihanturan 2020-03-26 16:53:11 +02:00 committed by GitHub
parent 350e95b56a
commit e7efd7e162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View file

@ -71,6 +71,9 @@ public interface NearbyParentFragmentContract {
LatLng getLastLocation();
com.mapbox.mapboxsdk.geometry.LatLng getLastFocusLocation();
boolean isCurrentLocationMarkerVisible();
void setProjectorLatLngBounds();
}
interface NearbyListView {

View file

@ -50,6 +50,7 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Style;
@ -201,6 +202,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private boolean isVisibleToUser;
private MapboxMap.OnCameraMoveListener cameraMoveListener;
private fr.free.nrw.commons.location.LatLng lastFocusLocation;
private LatLngBounds latLngBounds;
@Override
@ -632,6 +634,22 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return lastFocusLocation==null?null:LocationUtils.commonsLatLngToMapBoxLatLng(lastFocusLocation);
}
@Override
public boolean isCurrentLocationMarkerVisible() {
if (latLngBounds == null) {
Timber.d("Map projection bounds are null");
return false;
} else {
Timber.d("Current location marker %s" , latLngBounds.contains(currentLocationMarker.getPosition()) ? "visible" : "invisible");
return latLngBounds.contains(currentLocationMarker.getPosition());
}
}
@Override
public void setProjectorLatLngBounds() {
latLngBounds = mapBox.getProjection().getVisibleRegion().latLngBounds;
}
@Override
public boolean isNetworkConnectionEstablished() {
return NetworkUtils.isInternetConnectionEstablished(getActivity());
@ -906,9 +924,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
private void handleLocationUpdate(fr.free.nrw.commons.location.LatLng latLng, LocationServiceManager.LocationChangeType locationChangeType){
setMapBoxPosition(latLng);
this.lastKnownLocation=latLng;
NearbyController.currentLocation=lastKnownLocation;
this.lastKnownLocation = latLng;
NearbyController.currentLocation = lastKnownLocation;
presenter.updateMapAndList(locationChangeType);
}
@ -941,14 +958,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
}
void setMapBoxPosition(fr.free.nrw.commons.location.LatLng latLng){
CameraPosition position = new CameraPosition.Builder()
.target(LocationUtils.commonsLatLngToMapBoxLatLng(latLng)) // Sets the new camera position
.zoom(ZOOM_LEVEL) // Same zoom level
.build();
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
}
public void backButtonClicked() {
presenter.backButtonClicked();
}

View file

@ -8,8 +8,6 @@ import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.List;
import javax.inject.Inject;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
@ -21,9 +19,7 @@ import fr.free.nrw.commons.nearby.MarkerPlaceGroup;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.NearbyFilterState;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.upload.UploadContract;
import fr.free.nrw.commons.utils.LocationUtils;
import fr.free.nrw.commons.wikidata.WikidataEditListener;
import timber.log.Timber;
@ -194,7 +190,7 @@ public class NearbyParentFragmentPresenter
nearbyParentFragmentView.populatePlaces(nearbyParentFragmentView.getCameraTarget());
} else { // Means location changed slightly, ie user is walking or driving.
Timber.d("Means location changed slightly");
if (!nearbyParentFragmentView.isSearchThisAreaButtonVisible()) { // Do not track users position if the user is checking around
if (nearbyParentFragmentView.isCurrentLocationMarkerVisible()){ // Means user wants to see their live location
nearbyParentFragmentView.recenterMap(curLatLng);
}
}
@ -259,6 +255,7 @@ public class NearbyParentFragmentPresenter
@Override
public void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng) {
nearbyParentFragmentView.setProjectorLatLngBounds();
// If our nearby markers are calculated at least once
if (NearbyController.latestSearchLocation != null) {
double distance =latLng.distanceTo