summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style
diff options
context:
space:
mode:
authorCameron Mace <cameron@mapbox.com>2016-12-16 16:19:15 -0500
committerGitHub <noreply@github.com>2016-12-16 16:19:15 -0500
commit20b958301eb208fe9ed0ae8edfb14b6f3741d8f2 (patch)
tree94ae0ce250cda159be13f9a21cc70c92d4908974 /platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style
parentf95b4838ea816b9da0c151a953a1f98f97c79a39 (diff)
downloadqtlocation-mapboxgl-20b958301eb208fe9ed0ae8edfb14b6f3741d8f2.tar.gz
Adds checkstyle to CI (#7442)
* adds checkstyle to CI * fixed gradlew path * resolved testapp checkstyle violations * added back mapboxMap variable for test * checkstyle annotations * checkstyle SDK round 1 * maps package checkstyle * rest of SDK checkstyle * checkstyle gesture library * checkstyle test * finished rest of test checkstyle * resolved all checkstyle errors * fixed class name * removed old test file * fixed camera postion test * fixed native crash
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java222
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java237
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java274
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.java198
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java922
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTestActivity.java108
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.java152
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.java321
9 files changed, 1233 insertions, 1215 deletions
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
index 65af3365ec..1d90511888 100644
--- 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
@@ -8,7 +8,9 @@ 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 timber.log.Timber;
+
import android.view.MenuItem;
import android.view.View;
@@ -33,120 +35,120 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
*/
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 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))
- );
-
- // 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);
- }
- }
- });
- }
- });
- }
+ private MapboxMap mapboxMap;
+ private MapView mapView;
+ private Layer circleLayer;
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_circlelayer);
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
- @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);
- }
+ 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 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))
+ );
+
+ // 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);
+ }
+ }
+ });
+ }
+ });
+ }
+
+ @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
+ 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/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java
index 96c74bfcd3..d68872a5ba 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java
@@ -8,7 +8,9 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+
import timber.log.Timber;
+
import android.view.MenuItem;
import android.view.View;
@@ -32,126 +34,133 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
* Example to add a sprite image and use it in a Symbol Layer
*/
public class CustomSpriteActivity extends AppCompatActivity {
- private static final String CUSTOM_ICON = "custom-icon";
-
- private MapboxMap mapboxMap;
- private MapView mapView;
- private Layer layer;
- private GeoJsonSource source;
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_add_sprite);
-
- 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;
- final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
- fab.setOnClickListener(new View.OnClickListener() {
- private Point point;
-
- @Override
- public void onClick(View view) {
- if (point == null) {
- Timber.i("First click -> Car");
- // Add an icon to reference later
- mapboxMap.addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
-
- //Add a source with a geojson point
- point = Point.fromCoordinates(Position.fromCoordinates(13.400972d, 52.519003d));
- source = new GeoJsonSource("point", FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)}));
- mapboxMap.addSource(source);
-
- //Add a symbol layer that references that point source
- layer = new SymbolLayer("layer", "point");
- layer.setProperties(
- //Set the id of the sprite to use
- iconImage(CUSTOM_ICON)
- );
-
- // lets add a circle below labels!
- mapboxMap.addLayer(layer, "waterway-label");
-
- fab.setImageResource(R.drawable.ic_directions_car_black_24dp);
- } else {
- //Update point
- point = Point.fromCoordinates(Position.fromCoordinates(point.getCoordinates().getLongitude() + 0.001, point.getCoordinates().getLatitude() + 0.001));
- source.setGeoJson(FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)}));
-
- //Move the camera as well
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(point.getCoordinates().getLatitude(), point.getCoordinates().getLongitude())));
- }
- }
- });
- }
- });
- }
+ private static final String CUSTOM_ICON = "custom-icon";
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
+ private MapboxMap mapboxMap;
+ private MapView mapView;
+ private Layer layer;
+ private GeoJsonSource source;
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_add_sprite);
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
- @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);
- }
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull final MapboxMap map) {
+ mapboxMap = map;
+ final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
+ fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
+ fab.setOnClickListener(new View.OnClickListener() {
+ private Point point;
+
+ @Override
+ public void onClick(View view) {
+ if (point == null) {
+ Timber.i("First click -> Car");
+ // Add an icon to reference later
+ mapboxMap.addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
+
+ //Add a source with a geojson point
+ point = Point.fromCoordinates(Position.fromCoordinates(13.400972d, 52.519003d));
+ source = new GeoJsonSource(
+ "point",
+ FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
+ );
+ mapboxMap.addSource(source);
+
+ //Add a symbol layer that references that point source
+ layer = new SymbolLayer("layer", "point");
+ layer.setProperties(
+ //Set the id of the sprite to use
+ iconImage(CUSTOM_ICON)
+ );
+
+ // lets add a circle below labels!
+ mapboxMap.addLayer(layer, "waterway-label");
+
+ fab.setImageResource(R.drawable.ic_directions_car_black_24dp);
+ } else {
+ //Update point
+ point = Point.fromCoordinates(
+ Position.fromCoordinates(point.getCoordinates().getLongitude() + 0.001,
+ point.getCoordinates().getLatitude() + 0.001)
+ );
+ source.setGeoJson(FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)}));
+
+ //Move the camera as well
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
+ point.getCoordinates().getLatitude(), point.getCoordinates().getLongitude())));
+ }
+ }
+ });
+ }
+ });
+ }
+
+ @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
+ 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/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java
index 0c25c91cdc..33fc7f60a6 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java
@@ -6,7 +6,9 @@ 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 timber.log.Timber;
+
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
@@ -38,150 +40,150 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize;
*/
public class GeoJsonClusteringActivity extends AppCompatActivity {
- private MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_geojson_clustering);
-
- setupActionBar();
-
- //Initialize map as normal
- mapView = (MapView) findViewById(R.id.mapView);
- //noinspection ConstantConditions
- mapView.onCreate(savedInstanceState);
-
- mapView.getMapAsync(new OnMapReadyCallback() {
- @Override
- public void onMapReady(MapboxMap map) {
- mapboxMap = map;
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7749, 122.4194), 0));
-
- //Add a clustered source with some layers
- addClusteredGeoJsonSource();
- }
- });
+ private MapView mapView;
+ private MapboxMap mapboxMap;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_geojson_clustering);
+
+ setupActionBar();
+
+ //Initialize map as normal
+ mapView = (MapView) findViewById(R.id.mapView);
+ //noinspection ConstantConditions
+ mapView.onCreate(savedInstanceState);
+
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(MapboxMap map) {
+ mapboxMap = map;
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7749, 122.4194), 0));
+
+ //Add a clustered source with some layers
+ addClusteredGeoJsonSource();
+ }
+ });
+ }
+
+ @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();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
+ }
+
+ private void addClusteredGeoJsonSource() {
+ //Add a clustered source
+ try {
+ mapboxMap.addSource(
+ new GeoJsonSource("earthquakes",
+ new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"),
+ new GeoJsonOptions()
+ .withCluster(true)
+ .withClusterMaxZoom(14)
+ .withClusterRadius(50)
+ )
+ );
+ } catch (MalformedURLException malformedUrlException) {
+ Timber.e("That's not an url... " + malformedUrlException.getMessage());
}
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
+ //Add unclustered layer
+ int[][] layers = new int[][] {
+ new int[] {150, ResourcesCompat.getColor(getResources(), R.color.red_accent, getTheme())},
+ new int[] {20, ResourcesCompat.getColor(getResources(), R.color.green_accent, getTheme())},
+ new int[] {0, ResourcesCompat.getColor(getResources(), R.color.blue_accent, getTheme())}
+ };
+
+ SymbolLayer unclustered = new SymbolLayer("unclustered-points", "earthquakes");
+ unclustered.setProperties(iconImage("marker-15"));
+ mapboxMap.addLayer(unclustered);
+
+ for (int i = 0; i < layers.length; i++) {
+ //Add some nice circles
+ CircleLayer circles = new CircleLayer("cluster-" + i, "earthquakes");
+ circles.setProperties(
+ circleColor(layers[i][1]),
+ circleRadius(18f)
+ );
+ circles.setFilter(
+ i == 0
+ ? gte("point_count", layers[i][0]) :
+ all(gte("point_count", layers[i][0]), lt("point_count", layers[i - 1][0]))
+ );
+ mapboxMap.addLayer(circles);
}
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
+ //Add the count labels
+ SymbolLayer count = new SymbolLayer("count", "earthquakes");
+ count.setProperties(
+ textField("{point_count}"),
+ textSize(12f),
+ textColor(Color.WHITE)
+ );
+ mapboxMap.addLayer(count);
- @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();
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
- private void addClusteredGeoJsonSource() {
- //Add a clustered source
- try {
- mapboxMap.addSource(
- new GeoJsonSource("earthquakes",
- new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"),
- new GeoJsonOptions()
- .withCluster(true)
- .withClusterMaxZoom(14)
- .withClusterRadius(50)
- )
- );
- } catch (MalformedURLException malformedUrlException) {
- Timber.e("That's not an url... " + malformedUrlException.getMessage());
- }
-
- //Add unclustered layer
- int[][] layers = new int[][]{
- new int[]{150, ResourcesCompat.getColor(getResources(), R.color.red_accent, getTheme())},
- new int[]{20, ResourcesCompat.getColor(getResources(), R.color.green_accent, getTheme())},
- new int[]{0, ResourcesCompat.getColor(getResources(), R.color.blue_accent, getTheme())}
- };
-
- SymbolLayer unclustered = new SymbolLayer("unclustered-points", "earthquakes");
- unclustered.setProperties(iconImage("marker-15"));
- mapboxMap.addLayer(unclustered);
-
- for (int i = 0; i < layers.length; i++) {
- //Add some nice circles
- CircleLayer circles = new CircleLayer("cluster-" + i, "earthquakes");
- circles.setProperties(
- circleColor(layers[i][1]),
- circleRadius(18f)
- );
- circles.setFilter(
- i == 0
- ? gte("point_count", layers[i][0]) :
- all(gte("point_count", layers[i][0]), lt("point_count", layers[i - 1][0]))
- );
- mapboxMap.addLayer(circles);
- }
-
- //Add the count labels
- SymbolLayer count = new SymbolLayer("count", "earthquakes");
- count.setProperties(
- textField("{point_count}"),
- textSize(12f),
- textColor(Color.WHITE)
- );
- mapboxMap.addLayer(count);
-
-
- //Zoom out to start
- mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1));
- }
+ //Zoom out to start
+ mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1));
+ }
- private void setupActionBar() {
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
+ private void setupActionBar() {
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setDisplayShowHomeEnabled(true);
- }
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.java
index e995613c96..fad4f9714d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.java
@@ -6,7 +6,9 @@ import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+
import timber.log.Timber;
+
import android.view.MenuItem;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -29,119 +31,119 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
*/
public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapReadyCallback {
- private final static String ID_GEOJSON_LAYER = "wanderdrone";
- private final static String ID_GEOJSON_SOURCE = ID_GEOJSON_LAYER;
- private final static String URL_GEOJSON_SOURCE = "https://wanderdrone.appspot.com/";
+ private static final String ID_GEOJSON_LAYER = "wanderdrone";
+ private static final String ID_GEOJSON_SOURCE = ID_GEOJSON_LAYER;
+ private static final String URL_GEOJSON_SOURCE = "https://wanderdrone.appspot.com/";
- private MapView mapView;
- private MapboxMap mapboxMap;
+ private MapView mapView;
+ private MapboxMap mapboxMap;
- private Handler handler;
- private Runnable runnable;
+ private Handler handler;
+ private Runnable runnable;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_default);
-
- 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(this);
- }
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_default);
- @Override
- public void onMapReady(@NonNull final MapboxMap map) {
- mapboxMap = map;
-
- // add source
- try {
- mapboxMap.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
- }catch (MalformedURLException e){
- Timber.e("Invalid URL", e);
- }
-
- // add layer
- SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
- layer.setProperties(iconImage("rocket-15"));
- mapboxMap.addLayer(layer);
-
- // loop refresh geojson
- handler = new Handler();
- runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
- handler.postDelayed(runnable, 2000);
- }
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
- @Override
- public void onResume() {
- super.onResume();
- mapView.onResume();
- }
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(this);
+ }
- @Override
- public void onPause() {
- super.onPause();
- mapView.onPause();
- }
+ @Override
+ public void onMapReady(@NonNull final MapboxMap map) {
+ mapboxMap = map;
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- handler.removeCallbacks(runnable);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
+ // add source
+ try {
+ mapboxMap.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
+ } catch (MalformedURLException malformedUrlException) {
+ Timber.e("Invalid URL", malformedUrlException);
}
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
+ // add layer
+ SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
+ layer.setProperties(iconImage("rocket-15"));
+ mapboxMap.addLayer(layer);
+
+ // loop refresh geojson
+ handler = new Handler();
+ runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
+ handler.postDelayed(runnable, 2000);
+ }
+
+ @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
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ handler.removeCallbacks(runnable);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mapView.onDestroy();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
+ }
- private static class RefreshGeoJsonRunnable implements Runnable {
+ private static class RefreshGeoJsonRunnable implements Runnable {
- private MapboxMap mapboxMap;
- private Handler handler;
+ private MapboxMap mapboxMap;
+ private Handler handler;
- RefreshGeoJsonRunnable(MapboxMap mapboxMap, Handler handler) {
- this.mapboxMap = mapboxMap;
- this.handler = handler;
- }
+ RefreshGeoJsonRunnable(MapboxMap mapboxMap, Handler handler) {
+ this.mapboxMap = mapboxMap;
+ this.handler = handler;
+ }
- @Override
- public void run() {
- ((GeoJsonSource) mapboxMap.getSource(ID_GEOJSON_SOURCE)).setUrl(URL_GEOJSON_SOURCE);
- handler.postDelayed(this, 2000);
- }
+ @Override
+ public void run() {
+ ((GeoJsonSource) mapboxMap.getSource(ID_GEOJSON_SOURCE)).setUrl(URL_GEOJSON_SOURCE);
+ handler.postDelayed(this, 2000);
}
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
index 8143efb03d..2ac3a6fb00 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
@@ -7,7 +7,6 @@ import android.support.annotation.RawRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
-import timber.log.Timber;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@@ -44,7 +43,8 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import static android.os.Looper.getMainLooper;
+import timber.log.Timber;
+
import static com.mapbox.mapboxsdk.style.layers.Filter.all;
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
import static com.mapbox.mapboxsdk.style.layers.Filter.gte;
@@ -75,508 +75,512 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
*/
public class RuntimeStyleActivity extends AppCompatActivity {
- private MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_runtime_style);
-
- setupActionBar();
-
- //Initialize map as normal
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
-
-
- mapView.getMapAsync(new OnMapReadyCallback() {
- @Override
- public void onMapReady(MapboxMap map) {
- //Store for later
- mapboxMap = map;
-
- //Center and Zoom (Amsterdam, zoomed to streets)
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
- }
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_runtime_style, menu);
+ private MapView mapView;
+ private MapboxMap mapboxMap;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_runtime_style);
+
+ setupActionBar();
+
+ //Initialize map as normal
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+
+
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(MapboxMap map) {
+ //Store for later
+ mapboxMap = map;
+
+ //Center and Zoom (Amsterdam, zoomed to streets)
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_runtime_style, menu);
+ return true;
+ }
+
+ @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();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+ case R.id.action_water_color:
+ setWaterColor();
+ return true;
+ case R.id.action_background_opacity:
+ setBackgroundOpacity();
+ return true;
+ case R.id.action_road_avoid_edges:
+ setRoadSymbolPlacement();
+ return true;
+ case R.id.action_layer_visibility:
+ setLayerInvisible();
+ return true;
+ case R.id.action_remove_layer:
+ removeBuildings();
+ return true;
+ case R.id.action_add_parks_layer:
+ addParksLayer();
+ return true;
+ case R.id.action_add_dynamic_parks_layer:
+ addDynamicParksLayer();
+ return true;
+ case R.id.action_add_terrain_layer:
+ addTerrainLayer();
+ return true;
+ case R.id.action_add_satellite_layer:
+ addSatelliteLayer();
+ return true;
+ case R.id.action_update_water_color_on_zoom:
+ updateWaterColorOnZoom();
return true;
+ case R.id.action_add_custom_tiles:
+ addCustomTileSource();
+ return true;
+ case R.id.action_fill_filter:
+ styleFillFilterLayer();
+ return true;
+ case R.id.action_line_filter:
+ styleLineFilterLayer();
+ return true;
+ case R.id.action_numeric_filter:
+ styleNumericFillLayer();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
+ }
+
+ private void setLayerInvisible() {
+ String[] roadLayers = new String[] {"water"};
+ for (String roadLayer : roadLayers) {
+ Layer layer = mapboxMap.getLayer(roadLayer);
+ if (layer != null) {
+ layer.setProperties(visibility(NONE));
+ }
}
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
+ }
+
+ private void setRoadSymbolPlacement() {
+ //Zoom so that the labels are visible first
+ mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(14), new DefaultCallback() {
+ @Override
+ public void onFinish() {
+ String[] roadLayers = new String[] {"road-label-small", "road-label-medium", "road-label-large"};
+ for (String roadLayer : roadLayers) {
+ Layer layer = mapboxMap.getLayer(roadLayer);
+ if (layer != null) {
+ layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT));
+ }
+ }
+ }
+ });
+ }
+
+ private void setBackgroundOpacity() {
+ Layer background = mapboxMap.getLayer("background");
+ if (background != null) {
+ background.setProperties(backgroundOpacity(0.2f));
}
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
+ }
+
+ private void setWaterColor() {
+ Layer water = mapboxMap.getLayer("water");
+ if (water != null) {
+ water.setProperties(
+ visibility(VISIBLE),
+ fillColor(Color.RED)
+ );
+ } else {
+ Toast.makeText(RuntimeStyleActivity.this, "No water layer in this style", Toast.LENGTH_SHORT).show();
}
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
+ }
+
+ private void removeBuildings() {
+ //Zoom to see buildings first
+ try {
+ mapboxMap.removeLayer("building");
+ } catch (NoSuchLayerException noSuchLayerException) {
+ Toast.makeText(RuntimeStyleActivity.this, noSuchLayerException.getMessage(), Toast.LENGTH_SHORT).show();
}
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
+ }
+
+ private void addParksLayer() {
+ //Add a source
+ Source source;
+ try {
+ source = new GeoJsonSource("amsterdam-spots", readRawResource(R.raw.amsterdam));
+ } catch (IOException ioException) {
+ Toast.makeText(
+ RuntimeStyleActivity.this,
+ "Couldn't add source: " + ioException.getMessage(),
+ Toast.LENGTH_SHORT).show();
+ return;
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
+ mapboxMap.addSource(source);
+
+ FillLayer layer = new FillLayer("parksLayer", "amsterdam-spots");
+ layer.setProperties(
+ fillColor(Color.RED),
+ fillOutlineColor(Color.BLUE),
+ fillOpacity(0.3f),
+ fillAntialias(true)
+ );
+
+ //Only show me parks (except westerpark with stroke-width == 3)
+ layer.setFilter(all(eq("type", "park"), eq("stroke-width", 2)));
+
+ mapboxMap.addLayer(layer, "building");
+ //layer.setPaintProperty(fillColor(Color.RED)); //XXX But not after the object is attached
+
+ //Or get the object later and set it. It's all good.
+ mapboxMap.getLayer("parksLayer").setProperties(fillColor(Color.RED));
+
+ //You can get a typed layer, if you're sure it's of that type. Use with care
+ layer = mapboxMap.getLayerAs("parksLayer");
+ //And get some properties
+ PropertyValue<Boolean> fillAntialias = layer.getFillAntialias();
+ Timber.d("Fill anti alias: " + fillAntialias.getValue());
+ layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP));
+ PropertyValue<String> fillTranslateAnchor = layer.getFillTranslateAnchor();
+ Timber.d("Fill translate anchor: " + fillTranslateAnchor.getValue());
+ PropertyValue<String> visibility = layer.getVisibility();
+ Timber.d("Visibility: " + visibility.getValue());
+
+ //Get a good look at it all
+ mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
+ }
+
+ private void addDynamicParksLayer() {
+ //Load some data
+ FeatureCollection parks;
+ try {
+ String json = readRawResource(R.raw.amsterdam);
+ parks = FeatureCollection.fromJson(json);
+ } catch (IOException ioException) {
+ Toast.makeText(
+ RuntimeStyleActivity.this,
+ "Couldn't add source: " + ioException.getMessage(),
+ Toast.LENGTH_SHORT
+ ).show();
+ return;
}
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
+ //Add an empty source
+ mapboxMap.addSource(new GeoJsonSource("dynamic-park-source"));
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- case R.id.action_water_color:
- setWaterColor();
- return true;
- case R.id.action_background_opacity:
- setBackgroundOpacity();
- return true;
- case R.id.action_road_avoid_edges:
- setRoadSymbolPlacement();
- return true;
- case R.id.action_layer_visibility:
- setLayerInvisible();
- return true;
- case R.id.action_remove_layer:
- removeBuildings();
- return true;
- case R.id.action_add_parks_layer:
- addParksLayer();
- return true;
- case R.id.action_add_dynamic_parks_layer:
- addDynamicParksLayer();
- return true;
- case R.id.action_add_terrain_layer:
- addTerrainLayer();
- return true;
- case R.id.action_add_satellite_layer:
- addSatelliteLayer();
- return true;
- case R.id.action_update_water_color_on_zoom:
- updateWaterColorOnZoom();
- return true;
- case R.id.action_add_custom_tiles:
- addCustomTileSource();
- return true;
- case R.id.action_fill_filter:
- styleFillFilterLayer();
- return true;
- case R.id.action_line_filter:
- styleLineFilterLayer();
- return true;
- case R.id.action_numeric_filter:
- styleNumericFillLayer();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
+ FillLayer layer = new FillLayer("dynamic-parks-layer", "dynamic-park-source");
+ layer.setProperties(
+ fillColor(Color.GREEN),
+ fillOutlineColor(Color.GREEN),
+ fillOpacity(0.8f),
+ fillAntialias(true)
+ );
- private void setLayerInvisible() {
- String[] roadLayers = new String[]{"water"};
- for (String roadLayer : roadLayers) {
- Layer layer = mapboxMap.getLayer(roadLayer);
- if (layer != null) {
- layer.setProperties(visibility(NONE));
- }
- }
- }
+ //Only show me parks
+ layer.setFilter(all(eq("type", "park")));
- private void setRoadSymbolPlacement() {
- //Zoom so that the labels are visible first
- mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(14), new DefaultCallback() {
- @Override
- public void onFinish() {
- String[] roadLayers = new String[]{"road-label-small", "road-label-medium", "road-label-large"};
- for (String roadLayer : roadLayers) {
- Layer layer = mapboxMap.getLayer(roadLayer);
- if (layer != null) {
- layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT));
- }
- }
- }
- });
- }
+ mapboxMap.addLayer(layer);
- private void setBackgroundOpacity() {
- Layer background = mapboxMap.getLayer("background");
- if (background != null) {
- background.setProperties(backgroundOpacity(0.2f));
- }
- }
+ //Get a good look at it all
+ mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
- private void setWaterColor() {
- Layer water = mapboxMap.getLayer("water");
- if (water != null) {
- water.setProperties(
- visibility(VISIBLE),
- fillColor(Color.RED)
- );
- } else {
- Toast.makeText(RuntimeStyleActivity.this, "No water layer in this style", Toast.LENGTH_SHORT).show();
- }
- }
+ //Animate the parks source
+ animateParksSource(parks, 0);
+ }
- private void removeBuildings() {
- //Zoom to see buildings first
- try {
- mapboxMap.removeLayer("building");
- } catch (NoSuchLayerException noSuchLayerException) {
- Toast.makeText(RuntimeStyleActivity.this, noSuchLayerException.getMessage(), Toast.LENGTH_SHORT).show();
+ private void animateParksSource(final FeatureCollection parks, final int counter) {
+ Handler handler = new Handler(getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (mapboxMap == null) {
+ return;
}
- }
- private void addParksLayer() {
- //Add a source
- Source source;
- try {
- source = new GeoJsonSource("amsterdam-spots", readRawResource(R.raw.amsterdam));
- } catch (IOException ioException) {
- Toast.makeText(
- RuntimeStyleActivity.this,
- "Couldn't add source: " + ioException.getMessage(),
- Toast.LENGTH_SHORT).show();
- return;
- }
+ Timber.d("Updating parks source");
+ //change the source
+ int park = counter < parks.getFeatures().size() - 1 ? counter : 0;
- mapboxMap.addSource(source);
-
- FillLayer layer = new FillLayer("parksLayer", "amsterdam-spots");
- layer.setProperties(
- fillColor(Color.RED),
- fillOutlineColor(Color.BLUE),
- fillOpacity(0.3f),
- fillAntialias(true)
- );
-
- //Only show me parks (except westerpark with stroke-width == 3)
- layer.setFilter(all(eq("type", "park"), eq("stroke-width", 2)));
-
- mapboxMap.addLayer(layer, "building");
- //layer.setPaintProperty(fillColor(Color.RED)); //XXX But not after the object is attached
-
- //Or get the object later and set it. It's all good.
- mapboxMap.getLayer("parksLayer").setProperties(fillColor(Color.RED));
-
- //You can get a typed layer, if you're sure it's of that type. Use with care
- layer = mapboxMap.getLayerAs("parksLayer");
- //And get some properties
- PropertyValue<Boolean> fillAntialias = layer.getFillAntialias();
- Timber.d("Fill anti alias: " + fillAntialias.getValue());
- layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP));
- PropertyValue<String> fillTranslateAnchor = layer.getFillTranslateAnchor();
- Timber.d("Fill translate anchor: " + fillTranslateAnchor.getValue());
- PropertyValue<String> visibility = layer.getVisibility();
- Timber.d("Visibility: " + visibility.getValue());
-
- //Get a good look at it all
- mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
- }
+ GeoJsonSource source = mapboxMap.getSourceAs("dynamic-park-source");
- private void addDynamicParksLayer() {
- //Load some data
- FeatureCollection parks;
- try {
- String json = readRawResource(R.raw.amsterdam);
- parks = FeatureCollection.fromJson(json);
- } catch (IOException e) {
- Toast.makeText(RuntimeStyleActivity.this, "Couldn't add source: " + e.getMessage(), Toast.LENGTH_SHORT).show();
- return;
+ if (source == null) {
+ Timber.e("Source not found");
+ Toast.makeText(RuntimeStyleActivity.this, "Source not found", Toast.LENGTH_SHORT).show();
+ return;
}
- //Add an empty source
- mapboxMap.addSource(new GeoJsonSource("dynamic-park-source"));
-
- FillLayer layer = new FillLayer("dynamic-parks-layer", "dynamic-park-source");
- layer.setProperties(
- fillColor(Color.GREEN),
- fillOutlineColor(Color.GREEN),
- fillOpacity(0.8f),
- fillAntialias(true)
- );
-
- //Only show me parks
- layer.setFilter(all(eq("type", "park")));
-
- mapboxMap.addLayer(layer);
-
- //Get a good look at it all
- mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
-
- //Animate the parks source
- animateParksSource(parks, 0);
+ List<Feature> features = new ArrayList<>();
+ features.add(parks.getFeatures().get(park));
+ source.setGeoJson(FeatureCollection.fromFeatures(features));
+
+ //Re-post
+ animateParksSource(parks, park + 1);
+ }
+ }, counter == 0 ? 100 : 1000);
+ }
+
+ private void addTerrainLayer() {
+ //Add a source
+ Source source = new VectorSource("my-terrain-source", "mapbox://mapbox.mapbox-terrain-v2");
+ mapboxMap.addSource(source);
+
+ LineLayer layer = new LineLayer("terrainLayer", "my-terrain-source");
+ layer.setSourceLayer("contour");
+ layer.setProperties(
+ lineJoin(Property.LINE_JOIN_ROUND),
+ lineCap(Property.LINE_CAP_ROUND),
+ lineColor(Color.RED),
+ lineWidth(20f)
+ );
+
+ mapboxMap.addLayer(layer);
+
+ //Need to get a fresh handle
+ layer = mapboxMap.getLayerAs("terrainLayer");
+
+ //Make sure it's also applied after the fact
+ layer.setMinZoom(10);
+ layer.setMaxZoom(15);
+
+ layer = (LineLayer) mapboxMap.getLayer("terrainLayer");
+ Toast.makeText(this, String.format(
+ "Set min/max zoom to %s - %s", layer.getMinZoom(), layer.getMaxZoom()), Toast.LENGTH_SHORT).show();
+ }
+
+ private void addSatelliteLayer() {
+ //Add a source
+ Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite", 512);
+ mapboxMap.addSource(source);
+
+ //Add a layer
+ mapboxMap.addLayer(new RasterLayer("satellite-layer", "my-raster-source"));
+ }
+
+ private void updateWaterColorOnZoom() {
+ FillLayer layer = mapboxMap.getLayerAs("water");
+ if (layer == null) {
+ return;
}
- private void animateParksSource(final FeatureCollection parks, final int counter) {
- Handler handler = new Handler(getMainLooper());
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mapboxMap == null) {
- return;
- }
-
- Timber.d("Updating parks source");
- //change the source
- int park = counter < parks.getFeatures().size() - 1 ? counter : 0;
-
- GeoJsonSource source = mapboxMap.getSourceAs("dynamic-park-source");
-
- if (source == null) {
- Timber.e("Source not found");
- Toast.makeText(RuntimeStyleActivity.this, "Source not found", Toast.LENGTH_SHORT).show();
- return;
- }
-
- List<Feature> features = new ArrayList<>();
- features.add(parks.getFeatures().get(park));
- source.setGeoJson(FeatureCollection.fromFeatures(features));
-
- //Re-post
- animateParksSource(parks, park + 1);
- }
- }, counter == 0 ? 100 : 1000);
+ //Set a zoom function to update the color of the water
+ layer.setProperties(fillColor(zoom(0.8f,
+ stop(1, fillColor(Color.GREEN)),
+ stop(4, fillColor(Color.BLUE)),
+ stop(12, fillColor(Color.RED)),
+ stop(20, fillColor(Color.BLACK))
+ )));
+
+ //do some animations to show it off properly
+ mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1), 1500);
+
+ PropertyValue<String> fillColor = layer.getFillColor();
+ Function<String> function = fillColor.getFunction();
+ if (function != null) {
+ Timber.d("Fill color base: " + function.getBase());
+ Timber.d("Fill color #stops: " + function.getStops().length);
+ if (function.getStops() != null) {
+ for (Stop stop : function.getStops()) {
+ Timber.d("Fill color #stops: " + stop);
+ }
+ }
+ }
+ }
+
+ private String readRawResource(@RawRes int rawResource) throws IOException {
+ InputStream is = getResources().openRawResource(rawResource);
+ Writer writer = new StringWriter();
+ char[] buffer = new char[1024];
+ try {
+ Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ int numRead;
+ while ((numRead = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, numRead);
+ }
+ } finally {
+ is.close();
}
- private void addTerrainLayer() {
- //Add a source
- Source source = new VectorSource("my-terrain-source", "mapbox://mapbox.mapbox-terrain-v2");
- mapboxMap.addSource(source);
-
- LineLayer layer = new LineLayer("terrainLayer", "my-terrain-source");
- layer.setSourceLayer("contour");
- layer.setProperties(
- lineJoin(Property.LINE_JOIN_ROUND),
- lineCap(Property.LINE_CAP_ROUND),
- lineColor(Color.RED),
- lineWidth(20f)
- );
-
- mapboxMap.addLayer(layer);
-
- //Need to get a fresh handle
- layer = mapboxMap.getLayerAs("terrainLayer");
+ return writer.toString();
+ }
- //Make sure it's also applied after the fact
- layer.setMinZoom(10);
- layer.setMaxZoom(15);
+ private void setupActionBar() {
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- layer = (LineLayer) mapboxMap.getLayer("terrainLayer");
- Toast.makeText(this, String.format(
- "Set min/max zoom to %s - %s", layer.getMinZoom(), layer.getMaxZoom()), Toast.LENGTH_SHORT).show();
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
+ }
+
+ private void addCustomTileSource() {
+ //Add a source
+ Source source = new VectorSource("custom-tile-source", new TileSet("2.1.0", "https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=vector-tiles-LM25tq4"));
+ mapboxMap.addSource(source);
+
+ //Add a layer
+ mapboxMap.addLayer(
+ new FillLayer("custom-tile-layers", "custom-tile-source")
+ .withSourceLayer("water")
+ );
+ }
+
+ private void styleFillFilterLayer() {
+ mapboxMap.setStyleUrl("asset://fill_filter_style.json");
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3));
+
+ Handler handler = new Handler(getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (mapboxMap == null) {
+ return;
+ }
- private void addSatelliteLayer() {
- //Add a source
- Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite", 512);
- mapboxMap.addSource(source);
+ Timber.d("Styling filtered fill layer");
- //Add a layer
- mapboxMap.addLayer(new RasterLayer("satellite-layer", "my-raster-source"));
- }
+ FillLayer states = (FillLayer) mapboxMap.getLayer("states");
- private void updateWaterColorOnZoom() {
- FillLayer layer = mapboxMap.getLayerAs("water");
- if (layer == null) {
- return;
- }
+ if (states != null) {
+ states.setFilter(eq("name", "Texas"));
- //Set a zoom function to update the color of the water
- layer.setProperties(fillColor(zoom(0.8f,
- stop(1, fillColor(Color.GREEN)),
- stop(4, fillColor(Color.BLUE)),
- stop(12, fillColor(Color.RED)),
- stop(20, fillColor(Color.BLACK))
- )));
-
- //do some animations to show it off properly
- mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1), 1500);
-
- PropertyValue<String> fillColor = layer.getFillColor();
- Function<String> function = fillColor.getFunction();
- if (function != null) {
- Timber.d("Fill color base: " + function.getBase());
- Timber.d("Fill color #stops: " + function.getStops().length);
- if (function.getStops() != null) {
- for (Stop stop : function.getStops()) {
- Timber.d("Fill color #stops: " + stop);
- }
- }
+ states.setProperties(
+ fillColor(Color.RED),
+ fillOpacity(0.25f)
+ );
+ } else {
+ Toast.makeText(RuntimeStyleActivity.this, "No states layer in this style", Toast.LENGTH_SHORT).show();
}
- }
-
- private String readRawResource(@RawRes int rawResource) throws IOException {
- InputStream is = getResources().openRawResource(rawResource);
- Writer writer = new StringWriter();
- char[] buffer = new char[1024];
- try {
- Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- int n;
- while ((n = reader.read(buffer)) != -1) {
- writer.write(buffer, 0, n);
- }
- } finally {
- is.close();
+ }
+ }, 2000);
+ }
+
+ private void styleLineFilterLayer() {
+ mapboxMap.setStyleUrl("asset://line_filter_style.json");
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
+
+ Handler handler = new Handler(getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (mapboxMap == null) {
+ return;
}
- return writer.toString();
- }
+ Timber.d("Styling filtered line layer");
- private void setupActionBar() {
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
+ LineLayer counties = (LineLayer) mapboxMap.getLayer("counties");
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setDisplayShowHomeEnabled(true);
- }
- }
+ if (counties != null) {
+ counties.setFilter(eq("NAME10", "Washington"));
- private void addCustomTileSource() {
- //Add a source
- Source source = new VectorSource("custom-tile-source", new TileSet("2.1.0", "https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=vector-tiles-LM25tq4"));
- mapboxMap.addSource(source);
+ counties.setProperties(
+ lineColor(Color.RED),
+ lineOpacity(0.75f),
+ lineWidth(5f)
+ );
+ } else {
+ Toast.makeText(RuntimeStyleActivity.this, "No counties layer in this style", Toast.LENGTH_SHORT).show();
+ }
+ }
+ }, 2000);
+ }
+
+ private void styleNumericFillLayer() {
+ mapboxMap.setStyleUrl("asset://numeric_filter_style.json");
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
+
+ Handler handler = new Handler(getMainLooper());
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (mapboxMap == null) {
+ return;
+ }
- //Add a layer
- mapboxMap.addLayer(
- new FillLayer("custom-tile-layers", "custom-tile-source")
- .withSourceLayer("water")
- );
- }
+ Timber.d("Styling numeric fill layer");
- private void styleFillFilterLayer() {
- mapboxMap.setStyleUrl("asset://fill_filter_style.json");
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3));
-
- Handler handler = new Handler(getMainLooper());
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mapboxMap == null) {
- return;
- }
-
- Timber.d("Styling filtered fill layer");
-
- FillLayer states = (FillLayer) mapboxMap.getLayer("states");
-
- if (states != null) {
- states.setFilter(eq("name", "Texas"));
-
- states.setProperties(
- fillColor(Color.RED),
- fillOpacity(0.25f)
- );
- } else {
- Toast.makeText(RuntimeStyleActivity.this, "No states layer in this style", Toast.LENGTH_SHORT).show();
- }
- }
- }, 2000);
- }
+ FillLayer regions = (FillLayer) mapboxMap.getLayer("regions");
- private void styleLineFilterLayer() {
- mapboxMap.setStyleUrl("asset://line_filter_style.json");
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
-
- Handler handler = new Handler(getMainLooper());
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mapboxMap == null) {
- return;
- }
-
- Timber.d("Styling filtered line layer");
-
- LineLayer counties = (LineLayer) mapboxMap.getLayer("counties");
-
- if (counties != null) {
- counties.setFilter(eq("NAME10", "Washington"));
-
- counties.setProperties(
- lineColor(Color.RED),
- lineOpacity(0.75f),
- lineWidth(5f)
- );
- } else {
- Toast.makeText(RuntimeStyleActivity.this, "No counties layer in this style", Toast.LENGTH_SHORT).show();
- }
- }
- }, 2000);
- }
+ if (regions != null) {
+ regions.setFilter(all(gte("HRRNUM", 200), lt("HRRNUM", 300)));
- private void styleNumericFillLayer() {
- mapboxMap.setStyleUrl("asset://numeric_filter_style.json");
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
-
- Handler handler = new Handler(getMainLooper());
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mapboxMap == null) {
- return;
- }
-
- Timber.d("Styling numeric fill layer");
-
- FillLayer regions = (FillLayer) mapboxMap.getLayer("regions");
-
- if (regions != null) {
- regions.setFilter(all(gte("HRRNUM", 200), lt("HRRNUM", 300)));
-
- regions.setProperties(
- fillColor(Color.BLUE),
- fillOpacity(0.5f)
- );
- } else {
- Toast.makeText(RuntimeStyleActivity.this, "No regions layer in this style", Toast.LENGTH_SHORT).show();
- }
- }
- }, 2000);
- }
+ regions.setProperties(
+ fillColor(Color.BLUE),
+ fillOpacity(0.5f)
+ );
+ } else {
+ Toast.makeText(RuntimeStyleActivity.this, "No regions layer in this style", Toast.LENGTH_SHORT).show();
+ }
+ }
+ }, 2000);
+ }
- private static class DefaultCallback implements MapboxMap.CancelableCallback {
+ private static class DefaultCallback implements MapboxMap.CancelableCallback {
- @Override
- public void onCancel() {
- //noop
- }
+ @Override
+ public void onCancel() {
+ //noop
+ }
- @Override
- public void onFinish() {
- //noop
- }
+ @Override
+ public void onFinish() {
+ //noop
}
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTestActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTestActivity.java
index 841bf12ed8..1d242359bc 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTestActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTestActivity.java
@@ -13,68 +13,68 @@ import com.mapbox.mapboxsdk.testapp.R;
*/
public class RuntimeStyleTestActivity extends AppCompatActivity {
- public MapView mapView;
- private MapboxMap mapboxMap;
+ public MapView mapView;
+ private MapboxMap mapboxMap;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_runtime_style);
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_runtime_style);
- //Initialize map as normal
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(new OnMapReadyCallback() {
- @Override
- public void onMapReady(MapboxMap mapboxMap) {
- RuntimeStyleTestActivity.this.mapboxMap = mapboxMap;
- }
- });
- }
+ //Initialize map as normal
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ RuntimeStyleTestActivity.this.mapboxMap = mapboxMap;
+ }
+ });
+ }
- public MapboxMap getMapboxMap() {
- return mapboxMap;
- }
+ public MapboxMap getMapboxMap() {
+ return mapboxMap;
+ }
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mapView.onStart();
+ }
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mapView.onResume();
+ }
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mapView.onPause();
+ }
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ }
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
+ }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mapView.onDestroy();
+ }
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mapView.onLowMemory();
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.java
index b633698cc1..c57bc0069a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.java
@@ -21,80 +21,80 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
*/
public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
- public MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_runtime_style);
-
- //Initialize map as normal
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(new OnMapReadyCallback() {
- @Override
- public void onMapReady(MapboxMap mapboxMap) {
- RuntimeStyleTimingTestActivity.this.mapboxMap = mapboxMap;
- VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
- mapboxMap.addSource(museums);
-
- CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
- museumsLayer.setSourceLayer("museum-cusco");
- museumsLayer.setProperties(
- visibility(VISIBLE),
- circleRadius(8f),
- circleColor(Color.argb(1, 55, 148, 179))
- );
-
- mapboxMap.addLayer(museumsLayer);
- }
- });
- }
-
- public MapboxMap getMapboxMap() {
- return mapboxMap;
- }
-
- @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();
- }
+ public MapView mapView;
+ private MapboxMap mapboxMap;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_runtime_style);
+
+ //Initialize map as normal
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ RuntimeStyleTimingTestActivity.this.mapboxMap = mapboxMap;
+ VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
+ mapboxMap.addSource(museums);
+
+ CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
+ museumsLayer.setSourceLayer("museum-cusco");
+ museumsLayer.setProperties(
+ visibility(VISIBLE),
+ circleRadius(8f),
+ circleColor(Color.argb(1, 55, 148, 179))
+ );
+
+ mapboxMap.addLayer(museumsLayer);
+ }
+ });
+ }
+
+ public MapboxMap getMapboxMap() {
+ return mapboxMap;
+ }
+
+ @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();
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.java
index 2634401407..73e6bc985a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.java
@@ -9,7 +9,6 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
-import timber.log.Timber;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
@@ -30,8 +29,7 @@ import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
-import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
-import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
+import timber.log.Timber;
/**
* Example on how to use a file:// resource for the style.json
@@ -88,10 +86,10 @@ public class StyleFileActivity extends AppCompatActivity {
cacheStyleFile.createNewFile();
Timber.i("Writing style file to: " + cacheStyleFile.getAbsolutePath());
writeToFile(cacheStyleFile, readRawResource(R.raw.local_style));
- } catch (Exception e) {
+ } catch (Exception exception) {
Toast.makeText(StyleFileActivity.this, "Could not create style file in cache dir", Toast.LENGTH_SHORT).show();
}
- return 1l;
+ return 1L;
}
protected void onPostExecute(Long result) {
@@ -105,9 +103,9 @@ public class StyleFileActivity extends AppCompatActivity {
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- int n;
- while ((n = reader.read(buffer)) != -1) {
- writer.write(buffer, 0, n);
+ int numRead;
+ while ((numRead = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, numRead);
}
} finally {
is.close();
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.java
index ae4f6042ce..be71e58eba 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.java
@@ -18,7 +18,6 @@ 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.Layer;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.testapp.R;
@@ -29,8 +28,6 @@ import com.mapbox.services.commons.geojson.Point;
import java.util.Arrays;
import java.util.List;
-import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
-import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize;
@@ -44,171 +41,175 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize;
*/
public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.OnMapClickListener {
- public static final String MARKER_SOURCE = "marker-source";
- public static final String MARKER_LAYER = "marker-layer";
- private MapboxMap mapboxMap;
- private MapView mapView;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_symbollayer);
-
- 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;
-
- //Add a image for the makers
- mapboxMap.addImage("my-marker-image", BitmapFactory.decodeResource(SymbolLayerActivity.this.getResources(), R.drawable.mapbox_marker_icon_default));
-
- //Add a source
- FeatureCollection markers = FeatureCollection.fromFeatures(new Feature[]{
- Feature.fromGeometry(Point.fromCoordinates(new double[]{4.91638, 52.35673}), featureProperties("Marker 1")),
- Feature.fromGeometry(Point.fromCoordinates(new double[]{4.91638, 52.34673}), featureProperties("Marker 2"))
- });
- mapboxMap.addSource(new GeoJsonSource(MARKER_SOURCE, markers));
-
- //Add the symbol-layer
- mapboxMap.addLayer(
- new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
- .withProperties(
- iconImage("my-marker-image"),
- iconAllowOverlap(true),
- textField("{title}"),
- textColor(Color.RED),
- textSize(10f)
- )
- );
-
- //Show
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.35273, 4.91638), 14));
-
- //Set a click-listener so we can manipulate the map
- mapboxMap.setOnMapClickListener(SymbolLayerActivity.this);
- }
- });
- }
-
- @Override
- public void onMapClick(@NonNull LatLng point) {
- //Query which features are clicked
- PointF screenLoc = mapboxMap.getProjection().toScreenLocation(point);
- List<Feature> features = mapboxMap.queryRenderedFeatures(screenLoc, MARKER_LAYER);
-
- SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
- if (features.size() == 0) {
- //Reset
- layer.setProperties(iconSize(1f));
- } else {
- layer.setProperties(iconSize(3f));
- }
- }
-
- private void toggleTextSize() {
- SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
- layer.setProperties(layer.getTextSize().getValue() > 10 ? textSize(10f) : textSize(20f));
- }
-
- private void toggleTextField() {
- SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
- layer.setProperties("{title}".equals(layer.getTextField().getValue()) ? textField("āA") : textField("{title}"));
- }
-
- private void toggleTextFont() {
- SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
+ public static final String MARKER_SOURCE = "marker-source";
+ public static final String MARKER_LAYER = "marker-layer";
+ private MapboxMap mapboxMap;
+ private MapView mapView;
- String[] fonts = layer.getTextFont().getValue();
- if (fonts == null || fonts.length == 0 || Arrays.asList(fonts).contains("Arial Unicode MS Regular")) {
- layer.setProperties(textFont(new String[]{"DIN Offc Pro Bold", "Arial Unicode MS Bold"}));
- } else {
- layer.setProperties(textFont(new String[]{"DIN Offc Pro Medium", "Arial Unicode MS Regular"}));
- }
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_symbollayer);
- private JsonObject featureProperties(String title) {
- JsonObject object = new JsonObject();
- object.add("title", new JsonPrimitive(title));
- return object;
- }
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
}
- @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
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull final MapboxMap map) {
+ mapboxMap = map;
+
+ //Add a image for the makers
+ mapboxMap.addImage(
+ "my-marker-image",
+ BitmapFactory.decodeResource(SymbolLayerActivity.this.getResources(),
+ R.drawable.mapbox_marker_icon_default)
+ );
+
+ //Add a source
+ FeatureCollection markers = FeatureCollection.fromFeatures(new Feature[] {
+ Feature.fromGeometry(Point.fromCoordinates(new double[] {4.91638, 52.35673}), featureProperties("Marker 1")),
+ Feature.fromGeometry(Point.fromCoordinates(new double[] {4.91638, 52.34673}), featureProperties("Marker 2"))
+ });
+ mapboxMap.addSource(new GeoJsonSource(MARKER_SOURCE, markers));
+
+ //Add the symbol-layer
+ mapboxMap.addLayer(
+ new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
+ .withProperties(
+ iconImage("my-marker-image"),
+ iconAllowOverlap(true),
+ textField("{title}"),
+ textColor(Color.RED),
+ textSize(10f)
+ )
+ );
+
+ //Show
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.35273, 4.91638), 14));
+
+ //Set a click-listener so we can manipulate the map
+ mapboxMap.setOnMapClickListener(SymbolLayerActivity.this);
+ }
+ });
+ }
+
+ @Override
+ public void onMapClick(@NonNull LatLng point) {
+ //Query which features are clicked
+ PointF screenLoc = mapboxMap.getProjection().toScreenLocation(point);
+ List<Feature> features = mapboxMap.queryRenderedFeatures(screenLoc, MARKER_LAYER);
+
+ SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
+ if (features.size() == 0) {
+ //Reset
+ layer.setProperties(iconSize(1f));
+ } else {
+ layer.setProperties(iconSize(3f));
}
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
+ }
+
+ private void toggleTextSize() {
+ SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
+ layer.setProperties(layer.getTextSize().getValue() > 10 ? textSize(10f) : textSize(20f));
+ }
+
+ private void toggleTextField() {
+ SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
+ layer.setProperties("{title}".equals(layer.getTextField().getValue()) ? textField("āA") : textField("{title}"));
+ }
+
+ private void toggleTextFont() {
+ SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
+
+ String[] fonts = layer.getTextFont().getValue();
+ if (fonts == null || fonts.length == 0 || Arrays.asList(fonts).contains("Arial Unicode MS Regular")) {
+ layer.setProperties(textFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Bold"}));
+ } else {
+ layer.setProperties(textFont(new String[] {"DIN Offc Pro Medium", "Arial Unicode MS Regular"}));
}
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_symbol_layer, menu);
+ }
+
+ private JsonObject featureProperties(String title) {
+ JsonObject object = new JsonObject();
+ object.add("title", new JsonPrimitive(title));
+ return object;
+ }
+
+ @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
+ 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 onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_symbol_layer, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
return true;
+ case R.id.action_toggle_text_size:
+ toggleTextSize();
+ return true;
+ case R.id.action_toggle_text_field:
+ toggleTextField();
+ return true;
+ case R.id.action_toggle_text_font:
+ toggleTextFont();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- case R.id.action_toggle_text_size:
- toggleTextSize();
- return true;
- case R.id.action_toggle_text_field:
- toggleTextField();
- return true;
- case R.id.action_toggle_text_font:
- toggleTextFont();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
+ }
} \ No newline at end of file