bound area improvment, toggle bounding box in menu fab
This commit is contained in:
parent
5d3ba7e1a1
commit
fd9cb37fb3
@ -258,7 +258,6 @@ public abstract class BaseActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean onQueryTextChange(String input) {
|
||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
executeUserListSearch(input);
|
||||
|
@ -10,16 +10,16 @@ import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -31,11 +31,7 @@ import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
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.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||
@ -67,6 +63,7 @@ import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
|
||||
@ -125,6 +122,7 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
@ -145,12 +143,29 @@ public class MapActivity extends BaseActivity
|
||||
return true;
|
||||
});
|
||||
|
||||
mapUtils.setMapBoundsArea(getApplicationContext() , mapboxMap, mapView);
|
||||
|
||||
setToggleMapBoundsArea();
|
||||
setOnMapLongClickListener();
|
||||
// addStaticLayer();
|
||||
}
|
||||
|
||||
private void setToggleMapBoundsArea() {
|
||||
|
||||
mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
|
||||
|
||||
FloatingActionButton toggleBoundsAreaFab = findViewById(R.id.fab_toggle_bound_area);
|
||||
toggleBoundsAreaFab.setOnClickListener(view -> {
|
||||
if (toggleBoundsAreaFab.getTitle().equals("Bounds OFF")) {
|
||||
toggleBoundsAreaFab.setTitle("Bounds ON");
|
||||
mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, false);
|
||||
} else {
|
||||
toggleBoundsAreaFab.setTitle("Bounds OFF");
|
||||
mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void createMarkerModal(String userId) {
|
||||
disposable.add(userService.getUserById(userId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -364,8 +379,6 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
String newLabel = element.getLabel();
|
||||
@ -447,44 +460,42 @@ public class MapActivity extends BaseActivity
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
Log.e(tag, "enableLocationPlugin true");
|
||||
|
||||
FloatingActionButton myLocationButton = findViewById(R.id.myLocationButton);
|
||||
myLocationButton.setVisibility(View.VISIBLE);
|
||||
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.trackingGesturesManagement(true)
|
||||
.trackingGesturesManagement(false)
|
||||
.accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
|
||||
.build();
|
||||
|
||||
// Get an instance of the component
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
|
||||
//Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
|
||||
Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
|
||||
|
||||
// Activate with options
|
||||
locationComponent.activateLocationComponent(this, options);
|
||||
// Enable to make component visible
|
||||
|
||||
// Enable to make component visible + camera animation
|
||||
// https://www.mapbox.com/android-docs/maps/overview/location-component/
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
|
||||
// Set the component's camera mode
|
||||
locationComponent.setCameraMode(CameraMode.TRACKING);
|
||||
locationComponent.setCameraMode(CameraMode.NONE);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
// Button 4 centring
|
||||
FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
|
||||
myLocFAB.setVisibility(View.VISIBLE);
|
||||
myLocFAB.setOnClickListener(v -> {
|
||||
|
||||
Location lastKnownLocation = locationComponent.getLastKnownLocation();
|
||||
if (lastKnownLocation != null) {
|
||||
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())) // Sets the new camera position
|
||||
.zoom(zoomParam) // Sets the zoom
|
||||
.bearing(bearingParam) // Rotate the camera
|
||||
.tilt(tiltParam) // Set the camera tilt
|
||||
.build(); // Creates a CameraPosition from the builder
|
||||
|
||||
mapboxMap.animateCamera(CameraUpdateFactory
|
||||
.newCameraPosition(position), 4000);
|
||||
mapUtils.makeNewCamera(mapboxMap,
|
||||
lastKnownLocation.getLatitude(),
|
||||
lastKnownLocation.getLongitude(),
|
||||
zoomParam,
|
||||
bearingParam,
|
||||
tiltParam,
|
||||
4000);
|
||||
}
|
||||
|
||||
// Camera aniamtion
|
||||
|
@ -7,11 +7,16 @@ import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
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.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -24,30 +29,54 @@ public class mapUtils {
|
||||
.include(new LatLng(52.46548540224137, 16.925255680881094))
|
||||
.build();
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setMapBoundsArea(Context context , MapboxMap mapboxMap, MapView mapView) {
|
||||
private static final PolygonOptions boundsArea = new PolygonOptions()
|
||||
.add(WMI_BOUNDS.getNorthWest())
|
||||
.add(WMI_BOUNDS.getNorthEast())
|
||||
.add(WMI_BOUNDS.getSouthEast())
|
||||
.add(WMI_BOUNDS.getSouthWest())
|
||||
.alpha(0.1f)
|
||||
.fillColor(Color.YELLOW);
|
||||
// For adding and removing
|
||||
private static Polygon polygon;
|
||||
private static View crosshair;
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
|
||||
|
||||
if (check) {
|
||||
// Set bounds to WMI
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0,4000);
|
||||
mapboxMap.setMinZoomPreference(16); // TODO export to map config
|
||||
|
||||
// Visualise bounds area
|
||||
// showBoundsArea
|
||||
PolygonOptions boundsArea = new PolygonOptions()
|
||||
.add(WMI_BOUNDS.getNorthWest())
|
||||
.add(WMI_BOUNDS.getNorthEast())
|
||||
.add(WMI_BOUNDS.getSouthEast())
|
||||
.add(WMI_BOUNDS.getSouthWest());
|
||||
boundsArea.alpha(0.1f);
|
||||
boundsArea.fillColor(Color.YELLOW);
|
||||
mapboxMap.addPolygon(boundsArea);
|
||||
|
||||
|
||||
polygon = mapboxMap.addPolygon(boundsArea);
|
||||
// showCrosshair
|
||||
View crosshair = new View(context);
|
||||
crosshair = new View(context);
|
||||
crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
|
||||
crosshair.setBackgroundColor(Color.GREEN);
|
||||
mapView.addView(crosshair);
|
||||
} else {
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(null);
|
||||
mapboxMap.setMinZoomPreference(2);
|
||||
mapboxMap.removePolygon(polygon);
|
||||
mapView.removeView(crosshair);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration){
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(new LatLng(lat, lon)) // Sets the new camera position
|
||||
.zoom(zoomParam) // Sets the zoom
|
||||
.bearing(bearingParam) // Rotate the camera
|
||||
.tilt(tiltParam) // Set the camera tilt
|
||||
.build(); // Creates a CameraPosition from the builder
|
||||
|
||||
mapboxMap.animateCamera(CameraUpdateFactory
|
||||
.newCameraPosition(position), duration);
|
||||
}
|
||||
|
||||
// Function for marker animation
|
||||
|
@ -42,13 +42,11 @@
|
||||
mapbox:srcCompat="@android:drawable/ic_dialog_map"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/myLocationButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:background="@color/half_black"
|
||||
android:backgroundTint="@color/materialDarkGrey"
|
||||
android:src="@android:drawable/ic_menu_mylocation"
|
||||
@ -92,13 +90,13 @@
|
||||
fab:fab_title="@string/fab_title_parks" />
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_toggle_attractions"
|
||||
android:id="@+id/fab_toggle_bound_area"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_colorNormal="@color/mapboxRed"
|
||||
fab:fab_colorPressed="@color/mapboxWhite"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_title="@string/fab_title_attractions" />
|
||||
fab:fab_title="@string/fab_title_bound_area" />
|
||||
</com.getbase.floatingactionbutton.FloatingActionsMenu>
|
||||
|
||||
|
||||
|
@ -43,7 +43,6 @@
|
||||
<!--PulsingLayerOpacityColorActivity activity-->
|
||||
<string name="fab_title_hotels">Hotele</string>
|
||||
<string name="fab_title_parks">Parkingi</string>
|
||||
<string name="fab_title_attractions">Atrakcje</string>
|
||||
<string name="app_name">FindMyTutor</string>
|
||||
<string name="title_activity_startup">Find My Tutor</string>
|
||||
|
||||
@ -128,6 +127,7 @@
|
||||
<string name="user_location_permission_explanation">Ta aplikacja potrzebuje uprawnień do lokalizacji.</string>
|
||||
<string name="settings_category_status">Ustawienia statusu</string>
|
||||
<string name="settings_category_manuallocation">Ręczny wybór lokalizacji</string>
|
||||
<string name="fab_title_bound_area">Bounds OFF</string>
|
||||
</resources>
|
||||
|
||||
|
||||
|
@ -170,7 +170,7 @@
|
||||
<!--PulsingLayerOpacityColorActivity activity-->
|
||||
<string name="fab_title_hotels">TODO</string>
|
||||
<string name="fab_title_parks">THIS</string>
|
||||
<string name="fab_title_attractions">TOO</string>
|
||||
<string name="fab_title_bound_area">Bounds OFF</string>
|
||||
<string name="select_a_location">Select a location</string>
|
||||
<string name="user_location_permission_explanation">This app needs location permissions in order to show its functionality.</string>
|
||||
<string name="user_location_permission_not_granted">You didn\'t grant location permissions.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user