diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp')
5 files changed, 190 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index d582719af6..0c289b84e9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -294,7 +294,7 @@ <activity android:name=".activity.maplayout.NavigationDrawerActivity" android:description="@string/description_navigation_drawer" - android:label="@string/title_activity_navigation_drawer" + android:label="@string/activity_navigation_drawer" android:theme="@style/AppTheme.ActionBar.Transparent"> <meta-data android:name="@string/category" @@ -309,6 +309,14 @@ android:value="@string/category_style" /> </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.GeoJsonClusteringActivity" android:description="@string/description_geojson_clustering" android:label="@string/activity_geojson_clustering"> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java index f49407626d..8b1aa42d34 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java @@ -125,15 +125,19 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView drawable.setColorFilter(redColor, PorterDuff.Mode.SRC_IN); Icon icon = IconFactory.getInstance(this).fromDrawable(drawable); + List<MarkerViewOptions> markerOptionsList = new ArrayList<>(); for (int i = 0; i < amount; i++) { randomIndex = random.nextInt(mLocations.size()); LatLng latLng = mLocations.get(randomIndex); - mapboxMap.addMarker(new MarkerViewOptions() + markerOptionsList.add(new MarkerViewOptions() .position(latLng) .icon(icon) .title(String.valueOf(i)) .snippet(formatter.format(latLng.getLatitude()) + ", " + formatter.format(latLng.getLongitude()))); } + for (MarkerViewOptions markerViewOptions : markerOptionsList) { + mapboxMap.addMarker(markerViewOptions); + } } private void showGlMarkers(int amount) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java new file mode 100644 index 0000000000..dd4a10e88c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java @@ -0,0 +1,137 @@ +package com.mapbox.mapboxsdk.testapp.activity.style; + +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; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; + +import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.constants.Style; +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.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.testapp.R; + +import java.net.MalformedURLException; +import java.net.URL; + +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 MapView mapView; + private Layer circleLayer; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_circlelayer); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(@NonNull final MapboxMap map) { + mapboxMap = map; + 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 e) { + Log.e(MapboxConstants.TAG, "That's not an url... " + e.getMessage()); + } + + circleLayer = new CircleLayer("circleLayer", "point"); + circleLayer.setProperties( + circleColor(ResourcesCompat.getColor(getResources(), R.color.primary_dark, getTheme())), + circleRadius(getResources().getDimension(R.dimen.circle_size)) + ); + + // lets add a circle below labels! + mapboxMap.addLayer(circleLayer, "waterway-label"); + } else { + // change size and color + circleLayer = mapboxMap.getLayer("circleLayer"); + 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); + } + } + }); + } + }); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_circlelayer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_circlelayer.xml new file mode 100644 index 0000000000..086b18fea1 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_circlelayer.xml @@ -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_below="@id/toolbar" + android:layout_width="match_parent" + app:center_latitude="52.519003" + app:center_longitude="13.400972" + app:style_url="@string/style_mapbox_streets" + app:zoom="16" + android:layout_height="match_parent"/> + + <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_add_24dp" + app:backgroundTint="@android:color/white" /> + +</RelativeLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index d8f2edd85e..b72dd9a2ae 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -61,7 +61,8 @@ <string name="activity_query_rendered_feature_properties">Query feature properties</string> <string name="activity_query_rendered_features_box_count">Count features in box</string> <string name="activity_query_rendered_features_box_highlight">Highlight features in box</string> - <string name="title_activity_navigation_drawer">Android SDK View integration</string> + <string name="activity_circle">Add Circle</string> + <string name="activity_navigation_drawer">Android SDK View integration</string> <!-- Description --> <string name="description_user_location_tracking">Tracks the location of the user</string> @@ -100,6 +101,7 @@ <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_geojson_clustering">Use GeoJson sources and dynamic layers to cluster information</string> <string name="description_print">Shows how to print a map</string> <string name="description_navigation_drawer">Test animation of Android SDK View components</string> |