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

Commit

Permalink
initial additions
Browse files Browse the repository at this point in the history
  • Loading branch information
langsmith committed Oct 14, 2018
1 parent 0bb9ed9 commit 61055e3
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.javaservices.IsochoneActivity"
android:label="@string/activity_java_services_isochrone_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.styles.ShowHideLayersActivity"
android:label="@string/activity_styles_show_hide_layer_title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.mapbox.mapboxandroiddemo.examples.extrusions.RotationExtrusionActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.DirectionsActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.GeocodingActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.IsochoneActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.MapMatchingActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.MatrixApiActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.OptimizationActivity;
Expand Down Expand Up @@ -857,6 +858,14 @@ private void initializeModels() {
null,
R.string.activity_java_services_geocoding_url, false, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.id.nav_java_services,
R.string.activity_java_services_isochrone_title,
R.string.activity_java_services_isochrone_description,
new Intent(MainActivity.this, IsochoneActivity.class),
null,
R.string.activity_java_services_isochrone_url, false, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.id.nav_snapshot_image_generator,
R.string.activity_image_generator_snapshot_notification_title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.mapbox.mapboxandroiddemo.examples.javaservices;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.layers.LineLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.net.URL;

import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
import static com.mapbox.mapboxsdk.style.expressions.Expression.geometryType;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;

/**
* See how far a car can travel in certain time periods by requesting information from the Mapbox
* Isochrone API (https://www.mapbox.com/api-documentation/#isochrone)
*/
public class IsochoneActivity extends AppCompatActivity {

private MapView mapView;
private MapboxMap mapboxMap;
private static final String GEOJSON_SOURCE_ID = "GEOJSON_SOURCE_ID";

@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 access token is configured.
setContentView(R.layout.activity_isochrone);

mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
IsochoneActivity.this.mapboxMap = mapboxMap;
initIsochroneGeoJsonSource();
initFillLayer();
initLineLayer();
}
});
}

private void initIsochroneGeoJsonSource() {
try {
// Retrieve GeoJSON information from the Mapbox Isochrone API
GeoJsonSource source = new GeoJsonSource(GEOJSON_SOURCE_ID, new URL("https://api.mapbox.com/isochrone/v1/"
+ "mapbox/driving/" + "-122.43817518306757,37.762834146042294?access_token="
+ getString(R.string.access_token) + "&polygons=false&" + "contours_minutes=5,10,15&contours_colors"
+ "=6706ce,04e813,4286f4"));

// Add the GeoJsonSource to map
mapboxMap.addSource(source);

} catch (Throwable throwable) {
Log.e("IsochoneActivity", "Couldn't add GeoJsonSource to map", throwable);
}
}

private void initFillLayer() {
// Create and style a FillLayer based on information in the Isochrone API response
FillLayer isochoneFillLayer = new FillLayer("polygon", GEOJSON_SOURCE_ID);
isochoneFillLayer.setProperties(
fillColor(get("color")),
fillOpacity(get("fillOpacity")));
isochoneFillLayer.setFilter(eq(geometryType(), literal("Polygon")));
isochoneFillLayer.setFilter(eq(literal("$type"), literal("Polygon")));
mapboxMap.addLayer(isochoneFillLayer);
}

private void initLineLayer() {
// Create and style a LineLayer based on information in the Isochrone API response
LineLayer isochoneLineLayer = new LineLayer("points", GEOJSON_SOURCE_ID);
isochoneLineLayer.setProperties(
lineColor(get("color")),
lineWidth(5f),
lineOpacity(get("opacity")));
isochoneLineLayer.setFilter(eq(literal("$type"), literal("LineString")));
mapboxMap.addLayer(isochoneLineLayer);
}

@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}

@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

@Override
public void onPause() {
super.onPause();
mapView.onPause();
}

@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}

@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}

@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
18 changes: 18 additions & 0 deletions MapboxAndroidDemo/src/main/res/layout/activity_isochrone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.javaservices.IsochoneActivity">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="37.7749"
mapbox:mapbox_cameraTargetLng="-122.4194"
mapbox:mapbox_cameraZoom="11"
mapbox:mapbox_styleUrl="@string/mapbox_style_light" />

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<string name="activity_java_services_static_image_description">Use Mapbox Java Services to build a url and download a static map.</string>
<string name="activity_java_services_matrix_api_description">Use the Directions Matrix API to receive driving times between 2-25 different locations.</string>
<string name="activity_java_services_geocoding_description">Use the Geocoding API to receive information about specific coordinates.</string>
<string name="activity_java_services_isochrone_description">Use the Isochrone API to receive information about how far you can travel within a given time.</string>
<string name="activity_plugins_traffic_plugin_description">Use the traffic plugin to display live car congestion data on top of a map.</string>
<string name="activity_plugins_building_plugin_description">Use the building plugin to easily display 3D building height</string>
<string name="activity_location_location_component_description">Use the location component to easily show a user\'s location on the map</string>
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/titles_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="activity_java_services_static_image_title">Download a static map</string>
<string name="activity_java_services_maxtrix_api_title">Retrieve travel times between many points</string>
<string name="activity_java_services_geocoding_title">Make a geocode request</string>
<string name="activity_java_services_isochrone_title">Make a isochrone request</string>
<string name="activity_plugins_traffic_plugin_title">Display real-time traffic</string>
<string name="activity_plugins_building_plugin_title">Display buildings in 3D</string>
<string name="activity_location_location_component_title">Show a user\'s location</string>
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/urls_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<string name="activity_java_services_optimization_url" translatable="false">http://i.imgur.com/guEQtlP.jpg</string>
<string name="activity_java_services_matrix_url" translatable="false">https://i.imgur.com/65RlfRZ.png</string>
<string name="activity_java_services_geocoding_url" translatable="false">https://i.imgur.com/9xl3EF8.png</string>
<string name="activity_java_services_isochrone_url" translatable="false">https://i.imgur.com/FHkeL7m.png</string>
<string name="activity_plugins_traffic_plugin_url" translatable="false">http://i.imgur.com/HRriOVR.png</string>
<string name="activity_plugins_building_plugin_url" translatable="false">http://i.imgur.com/Vcu67UR.png</string>
<string name="activity_location_location_component_url" translatable="false">https://i.imgur.com/77PVsni.png</string>
Expand Down

0 comments on commit 61055e3

Please sign in to comment.