From 8083b67fc4da44a28f8113f5bfe128ea6bcfe3b5 Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Mon, 12 Nov 2018 19:26:41 +0100 Subject: [PATCH] code refractor - moved boundries method into mapUtils --- .../wmi/findmytutor/activity/MapActivity.java | 36 +--------------- .../uam/wmi/findmytutor/utils/mapUtils.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 45f86c8..188d98d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -97,13 +97,6 @@ public class MapActivity extends BaseActivity private HashMap markerHash = new HashMap<>(); private Set 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(); } } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java index a58ca10..0ca9381 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java @@ -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 { // 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; } } + }