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 Sep 28, 2018
1 parent 155da74 commit a365a37
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 1 deletion.
7 changes: 7 additions & 0 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.dds.AnimatedDashLineActivity"
android:label="@string/activity_dds_animated_dash_line_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.dds.StyleLineIdentityPropertyActivity"
android:label="@string/activity_dds_style_line_identity_property_title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.mapbox.mapboxandroiddemo.examples.camera.BoundingBoxCameraActivity;
import com.mapbox.mapboxandroiddemo.examples.camera.RestrictCameraActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.AddRainFallStyleActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.AnimatedDashLineActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.BathymetryActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.ChoroplethJsonVectorMixActivity;
import com.mapbox.mapboxandroiddemo.examples.dds.ChoroplethZoomChangeActivity;
Expand Down Expand Up @@ -819,7 +820,11 @@ private void listItems(int id) {
R.string.activity_dds_expression_integration_description,
new Intent(MainActivity.this, ExpressionIntegrationActivity.class),
R.string.activity_dds_expression_integration_url, true, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.string.activity_dds_animated_dash_line_title,
R.string.activity_dds_animated_dash_line_description,
new Intent(MainActivity.this, AnimatedDashLineActivity.class),
R.string.activity_dds_animated_dash_line_url, false, BuildConfig.MIN_SDK_VERSION));
currentCategory = R.id.nav_dds;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package com.mapbox.mapboxandroiddemo.examples.dds;

// #-code-snippet: animated-dash-line full-java

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
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.LineLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.net.MalformedURLException;
import java.net.URL;

import static com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_ROUND;
import static com.mapbox.mapboxsdk.style.layers.Property.LINE_JOIN_ROUND;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;

/**
* Create an effect of animated and moving LineLayer dashes by rapidly adjusting the
* dash and gap lengths.
*/
public class AnimatedDashLineActivity extends AppCompatActivity implements OnMapReadyCallback {

private MapView mapView;
private MapboxMap mapboxMap;
private Handler handler;
private String tag = "AnimatedDashLine";
private RefreshDashAndGapRunnable refreshDashAndGapRunnable;
private int animationSpeedMillseconds = 50;

@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_animated_dash_line);

handler = new Handler();
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}

@Override
public void onMapReady(MapboxMap mapboxMap) {
AnimatedDashLineActivity.this.mapboxMap = mapboxMap;
initBikePathLayer();
Log.d(tag, "onMapReady: here 1");
Runnable runnable = new RefreshDashAndGapRunnable();
Log.d(tag, "onMapReady: runnable made");
handler.postDelayed(runnable, animationSpeedMillseconds);
Log.d(tag, "onMapReady: here 2");
}

private void initBikePathLayer() {
try {
GeoJsonSource geoJsonSource = new GeoJsonSource("animated_line_source", new URL(
"https://raw.githubusercontent.com/Chicago/osd-bike-routes/master/data/Bikeroutes.geojson"
));
mapboxMap.addSource(geoJsonSource);
LineLayer animatedDashBikeLineLayer = new LineLayer("animated_line_layer_id", "animated_line_source");
animatedDashBikeLineLayer.withProperties(
lineWidth(4.5f),
lineColor(Color.parseColor("#bf42f4")),
lineCap(LINE_CAP_ROUND),
lineJoin(LINE_JOIN_ROUND)
);
mapboxMap.addLayer(animatedDashBikeLineLayer);
} catch (MalformedURLException malformedUrlException) {
Log.d("AnimatedDashLine", "Check the URL: " + malformedUrlException.getMessage());
}
}

private class RefreshDashAndGapRunnable implements Runnable {

private float valueOne, valueTwo, valueThree, valueFour, ValueFive;
private float dashLength = 1;
private float gapLength = 3;

// We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
// LineAtlas
private float totalNumberOfSteps = 40;

// A # of totalNumberOfSteps proportional to the dashLength are devoted to manipulating the dash
private float dashSteps = totalNumberOfSteps * dashLength / (gapLength + dashLength);

// A # of totalNumberOfSteps proportional to the gapLength are devoted to manipulating the gap
private float gapSteps = totalNumberOfSteps - dashSteps;

// The current currentStep #
private int currentStep = 0;

private String TAG = "AnimatedDashLine";

@Override
public void run() {
Log.d(TAG, "RefreshDashAndGapRunnable run: ");
currentStep = currentStep + 1;
if (currentStep >= totalNumberOfSteps) {
currentStep = 0;
}
if (currentStep < dashSteps) {
valueOne = currentStep / dashSteps;
valueTwo = (1 - valueOne) * dashLength;
valueThree = gapLength;
valueFour = valueOne * dashLength;
ValueFive = 0;
} else {
valueOne = (currentStep - dashSteps) / (gapSteps);
valueTwo = 0;
valueThree = (1 - valueOne) * gapLength;
valueFour = dashLength;
ValueFive = valueOne * gapLength;
}
Log.d(TAG, "RefreshDashAndGapRunnable run: here");

Float[] newFloatArray = new Float[] {valueTwo, valueThree, valueFour, ValueFive};

mapboxMap.getLayer("animated_line_layer_id").setProperties(
lineDasharray(newFloatArray));
Log.d(TAG, "RefreshDashAndGapRunnable run: layer done being gotten");
handler.postDelayed(this, animationSpeedMillseconds);
}
}

// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

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

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

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

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

@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
handler.removeCallbacks(refreshDashAndGapRunnable);
refreshDashAndGapRunnable = null;
handler = null;
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
// #-end-code-snippet: animated-dash-line full-java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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.annotations.DrawMarkerActivity">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="41.87811"
mapbox:mapbox_cameraTargetLng="-87.629798"
mapbox:mapbox_styleUrl="@string/mapbox_style_dark"
mapbox:mapbox_cameraZoom="13"/>

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="activity_dds_bathymetry_description">Use data-driven styling to show bathymetry (water depth) data</string>
<string name="activity_dds_info_window_symbol_layer_description">Use SymbolLayer and icons to show data in a BubbleLayout "info window".</string>
<string name="activity_dds_expression_integration_description">Use multiple expressions to visualize unit change in data.</string>
<string name="activity_dds_animated_dash_line_description">Animated the gap size of a LineLayer for the appearance of moving lines.</string>
<string name="activity_annotation_marker_description">Create a default marker with an InfoWindow.</string>
<string name="activity_annotation_custom_marker_description">Create a marker with a custom icon using the Mapbox Maps SDK.</string>
<string name="activity_annotation_geojson_line_description">Draw a polyline by parsing a GeoJSON file with the Mapbox Maps SDK.</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 @@ -45,6 +45,7 @@
<string name="activity_dds_info_window_symbol_layer_title">Symbol layer info window</string>
<string name="activity_dds_image_clustering_title">SymbolLayer clustering</string>
<string name="activity_dds_expression_integration_title">Temperature change</string>
<string name="activity_dds_animated_dash_line_title">Animated line layer</string>
<string name="activity_annotation_marker_title">Draw a marker</string>
<string name="activity_annotation_custom_marker_title">Draw a custom marker icon</string>
<string name="activity_annotation_geojson_line_title">Draw a GeoJSON line</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 @@ -46,6 +46,7 @@
<string name="activity_dds_info_window_symbol_layer_url" translatable="false">https://i.imgur.com/qYoqgDk.png</string>
<string name="activity_dds_image_clustering_url" translatable="false">https://i.imgur.com/KjgNcS0.png</string>
<string name="activity_dds_expression_integration_url" translatable="false">https://imgur.com/YiBeH0I.png</string>
<string name="activity_dds_animated_dash_line_url" translatable="false">https://i.imgur.com/9JTOUQL.png</string>>>>>>>> 11b1f2b0... initial additions
<string name="activity_annotation_marker_url" translatable="false">http://i.imgur.com/X59UoaY.png</string>
<string name="activity_annotation_custom_marker_url" translatable="false">http://i.imgur.com/BIHtPwJ.png</string>
<string name="activity_annotation_geojson_line_url" translatable="false">http://i.imgur.com/rIFjsrH.png</string>
Expand Down

0 comments on commit a365a37

Please sign in to comment.