This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add restrict camera example * Adjusted bounds and added crosshair method to example's activity * Adjusted map target and zoom in XML layout * Checkstyle adjustment: removing unused imports
- Loading branch information
Showing
7 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...mo/src/main/java/com/mapbox/mapboxandroiddemo/examples/camera/RestrictCameraActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.mapbox.mapboxandroiddemo.examples.camera; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
|
||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
import com.mapbox.mapboxsdk.annotations.Marker; | ||
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 com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
|
||
public class RestrictCameraActivity extends AppCompatActivity implements OnMapReadyCallback { | ||
|
||
private static final LatLngBounds AUSTRALIA_BOUNDS = new LatLngBounds.Builder() | ||
.include(new LatLng(-9.136343, 109.372126)) | ||
.include(new LatLng(-44.640488, 158.590484)) | ||
.build(); | ||
|
||
private MapView mapView; | ||
private MapboxMap mapboxMap; | ||
private Marker marker; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Mapbox access token is configured here. This needs to be called either in your application | ||
// object or in the same activity which contains the mapview. | ||
Mapbox.getInstance(this, getString(R.string.access_token)); | ||
|
||
// This contains the MapView in XML and needs to be called after the account manager | ||
setContentView(R.layout.activity_camera_restrict); | ||
|
||
mapView = (MapView) findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(this); | ||
} | ||
|
||
@Override | ||
public void onMapReady(MapboxMap mapboxMap) { | ||
this.mapboxMap = mapboxMap; | ||
|
||
// Set bounds to Iceland | ||
mapboxMap.setLatLngBoundsForCameraTarget(AUSTRALIA_BOUNDS); | ||
mapboxMap.setMinZoomPreference(2); | ||
|
||
// Visualise bounds area | ||
showBoundsArea(); | ||
|
||
showCrosshair(); | ||
|
||
} | ||
|
||
private void showBoundsArea() { | ||
PolygonOptions boundsArea = new PolygonOptions() | ||
.add(AUSTRALIA_BOUNDS.getNorthWest()) | ||
.add(AUSTRALIA_BOUNDS.getNorthEast()) | ||
.add(AUSTRALIA_BOUNDS.getSouthEast()) | ||
.add(AUSTRALIA_BOUNDS.getSouthWest()); | ||
boundsArea.alpha(0.25f); | ||
boundsArea.fillColor(Color.RED); | ||
mapboxMap.addPolygon(boundsArea); | ||
} | ||
|
||
private void 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 onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
MapboxAndroidDemo/src/main/res/layout/activity_camera_restrict.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".examples.camera.BoundingBoxCameraActivity"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
mapbox:mapbox_cameraTargetLat="-26.145" | ||
mapbox:mapbox_cameraTargetLng="134.312" | ||
mapbox:mapbox_cameraZoom="2" | ||
mapbox:mapbox_styleUrl="@string/mapbox_style_satellite_streets"/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters