Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

add restrict camera example #302

Merged
merged 4 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions MapboxAndroidDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ dependencies {
gpservicesCompile 'com.google.firebase:firebase-crash:10.2.0'

// Mapbox dependencies
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar') {
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar') {
transitive = true
}

// Mapbox Android UI

compile 'com.mapbox.mapboxsdk:mapbox-android-ui:2.1.0'

// Mapbox Navigation SDK for Android
Expand Down
8 changes: 8 additions & 0 deletions MapboxAndroidDemo/src/gpservices/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>

<activity
android:name=".examples.camera.RestrictCameraActivity"
android:label="@string/activity_camera_restrict_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>
</application>
</manifest>
8 changes: 8 additions & 0 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>

<activity
android:name=".examples.camera.RestrictCameraActivity"
android:label="@string/activity_camera_restrict_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.mapbox.mapboxandroiddemo.examples.basics.SupportMapFragmentActivity;
import com.mapbox.mapboxandroiddemo.examples.camera.AnimateMapCameraActivity;
import com.mapbox.mapboxandroiddemo.examples.camera.BoundingBoxCameraActivity;
import com.mapbox.mapboxandroiddemo.examples.camera.RestrictCameraActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.ChoroplethZoomChangeActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.StyleCirclesCategoricallyActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.StyleLineIdentityPropertyActivity;
Expand Down Expand Up @@ -325,6 +326,12 @@ private void listItems(int id) {
new Intent(MainActivity.this, BoundingBoxCameraActivity.class),
R.string.activity_camera_bounding_box_url
));
exampleItemModel.add(new ExampleItemModel(
R.string.activity_camera_restrict_title,
R.string.activity_camera_restrict_description,
new Intent(MainActivity.this, RestrictCameraActivity.class),
R.string.activity_camera_restrict_url
));
currentCategory = R.id.nav_camera;
break;
case R.id.nav_offline:
Expand Down
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 MapboxAndroidDemo/src/main/res/layout/activity_camera_restrict.xml
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>
3 changes: 3 additions & 0 deletions MapboxAndroidDemo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<string name="activity_annotation_animated_marker_title">Animate marker position</string>
<string name="activity_camera_animate_title">Animate the map camera</string>
<string name="activity_camera_bounding_box_title">Fit camera in bounding box</string>
<string name="activity_camera_restrict_title">Restrict map panning</string>
<string name="activity_offline_simple_title">A simple offline map</string>
<string name="activity_offline_manager_title">Offline manager</string>
<string name="activity_query_feature_title">Query a map feature</string>
Expand Down Expand Up @@ -126,6 +127,7 @@
<string name="activity_annotation_animated_marker_description">Animate the marker to a new position on the map.</string>
<string name="activity_camera_animate_description">"Animate the map's camera position, tilt, bearing, and zoom."</string>
<string name="activity_camera_bounding_box_description">Position the camera so that all the given markers are in view.</string>
<string name="activity_camera_restrict_description">Prevent a map from being panned to a different place.</string>
<string name="activity_offline_simple_description">Download and view an offline map using the Mapbox Android SDK.</string>
<string name="activity_offline_manager_description">Download, view, navigate to, and delete an offline region.</string>
<string name="activity_query_feature_description">Click the map to add a marker at the location and display the maps property information for that feature.</string>
Expand Down Expand Up @@ -181,6 +183,7 @@
<string name="activity_annotation_animated_marker_url" translatable="false">http://i.imgur.com/XegvIKr.png</string>
<string name="activity_camera_animate_url" translatable="false">https://www.mapbox.com/android-sdk/images/animate-camera.gif</string>
<string name="activity_camera_bounding_box_url" translatable="false">http://i.imgur.com/A0JL21Q.png</string> <!-- https://www.mapbox.com/android-sdk/images/fit-bound-camera.gif -->
<string name="activity_camera_restrict_url" translatable="false">http://i.imgur.com/DSXAQQl.png</string>
<string name="activity_offline_simple_url" translatable="false">https://www.mapbox.com/android-sdk/images/offline-map.png</string>
<string name="activity_offline_manager_url" translatable="false">http://i.imgur.com/tDlcNIg.png</string>
<string name="activity_query_select_building_url" translatable="false">http://i.imgur.com/bImud7u.png</string>
Expand Down