[android] - Show bus stops and route Circle Layer Activity (#7402)
This commit is contained in:
@@ -335,16 +335,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.CircleLayerActivity"
|
||||
android:description="@string/description_circle"
|
||||
android:label="@string/activity_circle">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.SymbolLayerActivity"
|
||||
android:description="@string/description_symbol_layer"
|
||||
android:label="@string/activity_symbol_layer">
|
||||
android:description="@string/description_circle_layer"
|
||||
android:label="@string/activity_circle_layer">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
@@ -14,35 +14,41 @@ import timber.log.Timber;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.in;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
|
||||
/**
|
||||
* Example to add a circle as a layer using runtime style API, contains adding
|
||||
* GeoJSON as source that contains 1 Feature with a Point geometry, adding a circle layer and
|
||||
* changing circle layer properties as size and colors.
|
||||
*/
|
||||
public class CircleLayerActivity extends AppCompatActivity {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private static final String[] STOPS_FOR_ROUTE = new String[] {"99009", "99131", "99049", "99039", "99029", "99019",
|
||||
"98079", "98069", "97099", "97089", "97079", "97069", "97209", "97059", "97049", "97039", "97019", "96069",
|
||||
"96059", "96049", "96099", "96089", "96079", "85079", "85089", "85069", "85059", "85099", "84069", "84059",
|
||||
"84049", "84039", "84029", "84019", "83099", "83079", "83059", "83049", "83029", "82069", "82049", "82029",
|
||||
"82109", "81069", "81049", "81029", "80089", "80069", "80049", "80039", "80029", "01319", "01219", "01129",
|
||||
"01059", "01119", "01019", "04159", "04149", "04229", "04239", "05059", "05049", "05039", "05019", "10589"};
|
||||
|
||||
private MapView mapView;
|
||||
private Layer circleLayer;
|
||||
private MapboxMap mapboxMap;
|
||||
private CircleLayer layer;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_circlelayer);
|
||||
setContentView(R.layout.activity_circle_layer);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
@@ -59,40 +65,50 @@ public class CircleLayerActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource("bus_stop",
|
||||
new URL("https://raw.githubusercontent.com/cheeaun/busrouter-sg/master/data/2/bus-stops.geojson")));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e("That's not an url... ", malformedUrlException);
|
||||
}
|
||||
|
||||
layer = new CircleLayer("stops_layer", "bus_stop");
|
||||
layer.setProperties(
|
||||
circleColor(Color.parseColor("#FF9800")),
|
||||
circleRadius(1.0f)
|
||||
);
|
||||
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(CircleLayerActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (circleLayer == null) {
|
||||
// first time
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource("point", new URL("https://gist.githubusercontent.com/anonymous/87eca90e80a72b1b42be9d0201ec3c8e/raw/acbb46384fd56044a504f122950d0637d98b4e7a/map.geojson")));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(
|
||||
"That's not an url... " + malformedUrlException.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
circleLayer = new CircleLayer("circleLayer", "point");
|
||||
circleLayer.setProperties(
|
||||
circleColor(ResourcesCompat.getColor(getResources(), R.color.primary_dark, getTheme())),
|
||||
circleRadius(getResources().getDimension(R.dimen.circle_size))
|
||||
);
|
||||
// filter out stops for our route
|
||||
layer.setFilter(in("number", STOPS_FOR_ROUTE));
|
||||
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.addLayer(circleLayer, "waterway-label");
|
||||
} else {
|
||||
// change size and color
|
||||
circleLayer.setProperties(
|
||||
circleRadius(mapView.getTag() == null
|
||||
? getResources().getDimension(R.dimen.activity_horizontal_margin)
|
||||
: getResources().getDimension(R.dimen.circle_size)),
|
||||
circleColor(mapView.getTag() == null ? ResourcesCompat.getColor(
|
||||
getResources(), R.color.blue_accent, getTheme()) : ResourcesCompat.getColor(
|
||||
getResources(), R.color.green_accent, getTheme())));
|
||||
mapView.setTag(mapView.getTag() == null ? mapboxMap : null);
|
||||
// add route as a line
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource("bus_route",
|
||||
new URL("https://gist.githubusercontent.com/tobrun/7fbc0fe7e9ffea509f7608cda2601d5d/raw/"
|
||||
+ "a4b8cc289020f91fa2e1553524820054395e36f5/line.geojson")));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e("That's not an url... ", malformedUrlException);
|
||||
}
|
||||
LineLayer lineLayer = new LineLayer("route_layer", "bus_route");
|
||||
mapboxMap.addLayer(lineLayer, "stops_layer");
|
||||
|
||||
// move camera to start route
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(1.3896777, 103.9874997))
|
||||
.bearing(225)
|
||||
.tilt(45)
|
||||
.zoom(13)
|
||||
.build()
|
||||
), 1750);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -151,4 +167,4 @@ public class CircleLayerActivity extends AppCompatActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,16c0,0.88 0.39,1.67 1,2.22L5,20c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1h8v1c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1.78c0.61,-0.55 1,-1.34 1,-2.22L20,6c0,-3.5 -3.58,-4 -8,-4s-8,0.5 -8,4v10zM7.5,17c-0.83,0 -1.5,-0.67 -1.5,-1.5S6.67,14 7.5,14s1.5,0.67 1.5,1.5S8.33,17 7.5,17zM16.5,17c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM18,11L6,11L6,6h12v5z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar"
|
||||
app:mapbox_cameraTargetLat="1.350057"
|
||||
app:mapbox_cameraTargetLng="103.849218"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_dark"
|
||||
app:mapbox_cameraZoom="10"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_directions_bus_black_24dp"
|
||||
app:backgroundTint="@android:color/white" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_input_24dp"
|
||||
app:backgroundTint="@android:color/white" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</LinearLayout>
|
||||
@@ -58,6 +58,7 @@
|
||||
<string name="activity_minmax_zoom">Min/Max Zoom</string>
|
||||
<string name="activity_viewpager">ViewPager</string>
|
||||
<string name="activity_runtime_style">Runtime Style</string>
|
||||
<string name="activity_circle_layer">Circle layer</string>
|
||||
<string name="activity_style_file">Local Style file</string>
|
||||
<string name="activity_geojson_clustering">GeoJson Clustering</string>
|
||||
<string name="activity_geojson_realtime">Add live realtime data</string>
|
||||
@@ -66,7 +67,6 @@
|
||||
<string name="activity_query_rendered_features_box_count">Count features in box</string>
|
||||
<string name="activity_query_rendered_features_box_symbol_count">Count symbols in box</string>
|
||||
<string name="activity_query_rendered_features_box_highlight">Highlight features in box</string>
|
||||
<string name="activity_circle">Add Circle</string>
|
||||
<string name="activity_symbol_layer">Symbols</string>
|
||||
<string name="activity_add_sprite">Add Custom Sprite</string>
|
||||
<string name="activity_navigation_drawer">Android SDK View integration</string>
|
||||
@@ -113,7 +113,6 @@
|
||||
<string name="description_location_picker">Use a fixed Marker to select your location</string>
|
||||
<string name="description_viewpager">Use SupportMapFragments in a ViewPager</string>
|
||||
<string name="description_runtime_style">Adopt the map style on the fly</string>
|
||||
<string name="description_circle">Use GeoJson source to show a circle</string>
|
||||
<string name="description_symbol_layer">Manipulate symbols at runtime</string>
|
||||
<string name="description_custom_sprite">Use a custom sprite in a Symbol Layer</string>
|
||||
<string name="description_geojson_clustering">Use GeoJson sources and dynamic layers to cluster information</string>
|
||||
@@ -130,6 +129,7 @@
|
||||
<string name="description_style_file">Use a local file as the style</string>
|
||||
<string name="description_map_in_dialog">Display a map inside a dialog fragment</string>
|
||||
<string name="description_marker_view_rectangle">Marker Views within a rectangle</string>
|
||||
<string name="description_circle_layer">Show bus stops and route in Singapore</string>
|
||||
|
||||
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
|
||||
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
|
||||
@@ -236,4 +236,4 @@
|
||||
<string name="menuitem_title_rotate_gesture_enabled">Enable rotate gestures</string>
|
||||
<string name="menuitem_title_scroll_gesture_enabled">Enable scroll gestures</string>
|
||||
|
||||
</resources>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user