code refractor - moved boundries method into mapUtils

This commit is contained in:
Adam Domagalski 2018-11-12 19:26:41 +01:00
parent bca8cb782b
commit 8083b67fc4
2 changed files with 44 additions and 34 deletions

View File

@ -97,13 +97,6 @@ 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;
@ -152,7 +145,8 @@ public class MapActivity extends BaseActivity
return true;
});
setMapBoundsArea();
mapUtils.setMapBoundsArea(getApplicationContext() , mapboxMap, mapView);
setOnMapLongClickListener();
// addStaticLayer();
}
@ -444,31 +438,6 @@ public class MapActivity extends BaseActivity
);
}
private void setMapBoundsArea() {
// 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);
}
@SuppressWarnings({"MissingPermission"})
private void enableLocationPlugin() {
@ -623,7 +592,6 @@ public class MapActivity extends BaseActivity
message = "Network Error!";
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
}

View File

@ -2,15 +2,55 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
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 java.io.IOException;
import java.io.InputStream;
public class mapUtils {
// 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();
// Map Bounds Area
public static void setMapBoundsArea(Context context , MapboxMap mapboxMap, MapView mapView) {
// 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(context);
crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
crosshair.setBackgroundColor(Color.GREEN);
mapView.addView(crosshair);
}
// Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
@ -26,6 +66,7 @@ public class mapUtils {
}
}
// read file to JSON
public static String loadJsonFromAsset(Context context, String filename) {
// Using this method to load in GeoJSON files from the assets folder.
try {
@ -41,4 +82,5 @@ public class mapUtils {
return null;
}
}
}