Map bound area for WMI added
This commit is contained in:
parent
d1a249e5cf
commit
bca8cb782b
@ -14,10 +14,12 @@ import android.support.design.widget.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;
|
||||
|
||||
@ -29,9 +31,11 @@ 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;
|
||||
@ -93,7 +97,14 @@ public class MapActivity extends BaseActivity
|
||||
private HashMap<String, Marker> markerHash = new HashMap<>();
|
||||
private Set<String> previousCoordsIds = new HashSet<>();
|
||||
|
||||
// Boundires
|
||||
private static final LatLngBounds WMI_BOUNDS = new LatLngBounds.Builder()
|
||||
.include(new LatLng(52.467886048833094, 16.92912980245876))
|
||||
.include(new LatLng(52.46548540224137, 16.925255680881094))
|
||||
.build();
|
||||
|
||||
|
||||
// Camera Animation params
|
||||
private int zoomParam = 17;
|
||||
private int bearingParam = 180;
|
||||
private int tiltParam = 30;
|
||||
@ -136,13 +147,12 @@ public class MapActivity extends BaseActivity
|
||||
MapActivity.this.mapboxMap = mapboxMap;
|
||||
mStatusChecker.run();
|
||||
enableLocationPlugin();
|
||||
|
||||
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||
createMarkerModal(marker.getTitle());
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
setMapBoundsArea();
|
||||
setOnMapLongClickListener();
|
||||
// addStaticLayer();
|
||||
}
|
||||
@ -179,25 +189,7 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
showError(error);
|
||||
}
|
||||
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
}else {
|
||||
message = "Network Error!";
|
||||
}
|
||||
|
||||
|
||||
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// Manual loc selection on long tap
|
||||
private void setOnMapLongClickListener() {
|
||||
|
||||
final boolean[] cancel = {false};
|
||||
@ -349,7 +341,7 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
if(coordsList.isEmpty()) {
|
||||
Log.e(tag, "200 empty []");
|
||||
mapboxMap.clear();
|
||||
//mapboxMap.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -452,61 +444,31 @@ public class MapActivity extends BaseActivity
|
||||
);
|
||||
}
|
||||
|
||||
private void setMapBoundsArea() {
|
||||
|
||||
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
// Set bounds to WMI
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
|
||||
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);
|
||||
|
||||
|
||||
// showCrosshair
|
||||
View crosshair = new View(this);
|
||||
crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
|
||||
crosshair.setBackgroundColor(Color.GREEN);
|
||||
mapView.addView(crosshair);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() {
|
||||
return R.layout.activity_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_map;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MissingPermission"})
|
||||
private void enableLocationPlugin() {
|
||||
@ -571,6 +533,61 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() {
|
||||
return R.layout.activity_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
@ -591,4 +608,22 @@ public class MapActivity extends BaseActivity
|
||||
// finish();
|
||||
// }
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
showError(error);
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
}else {
|
||||
message = "Network Error!";
|
||||
}
|
||||
|
||||
|
||||
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user