diff options
author | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2016-09-21 11:04:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-21 11:04:32 +0200 |
commit | eb97dbe383ca7697feab5860995b97181c39c607 (patch) | |
tree | 70bdd7b6ebea32aec132413fa703e92a2a0f63d0 /platform/android/MapboxGLAndroidSDKTestApp | |
parent | 3b546b964609d0f596dac32e155b1489bb85645e (diff) | |
download | qtlocation-mapboxgl-eb97dbe383ca7697feab5860995b97181c39c607.tar.gz |
[android] Sources: peer model, mutability (#6054)
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp')
3 files changed, 86 insertions, 5 deletions
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 ca4460eac2..9d13ee165d 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 @@ -16,6 +16,7 @@ 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.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.testapp.R; @@ -110,10 +111,13 @@ public class GeoJsonClusteringActivity extends AppCompatActivity { //Add a clustered source try { mapboxMap.addSource( - new GeoJsonSource("earthquakes", new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")) - .withCluster(true) - .withClusterMaxZoom(14) - .withClusterRadius(50) + 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) { Log.e(TAG, "That's not an url... " + malformedUrlException.getMessage()); 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 d8a82168fd..84467b3aee 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 @@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp.activity.style; import android.graphics.Color; import android.os.Bundle; +import android.os.Handler; import android.support.annotation.RawRes; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -30,6 +31,8 @@ import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.mapboxsdk.style.sources.TileSet; import com.mapbox.mapboxsdk.style.sources.VectorSource; import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.services.commons.geojson.Feature; +import com.mapbox.services.commons.geojson.FeatureCollection; import java.io.BufferedReader; import java.io.IOException; @@ -38,6 +41,8 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter; import java.io.Writer; +import java.util.ArrayList; +import java.util.List; import static com.mapbox.mapboxsdk.style.layers.Filter.all; import static com.mapbox.mapboxsdk.style.layers.Filter.eq; @@ -154,6 +159,9 @@ public class RuntimeStyleActivity extends AppCompatActivity { 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; @@ -272,6 +280,71 @@ public class RuntimeStyleActivity extends AppCompatActivity { 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 e) { + Toast.makeText(RuntimeStyleActivity.this, "Couldn't add source: " + e.getMessage(), 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); + } + + 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; + } + + Log.d(TAG, "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) { + Log.e(TAG, "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); + } + private void addTerrainLayer() { //Add a source Source source = new VectorSource("my-terrain-source", "mapbox://mapbox.mapbox-terrain-v2"); @@ -302,7 +375,7 @@ public class RuntimeStyleActivity extends AppCompatActivity { private void addSatelliteLayer() { //Add a source - Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite").withTileSize(512); + Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite", 512); mapboxMap.addSource(source); //Add a layer diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml index 16713ae147..81e808e93c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml @@ -23,6 +23,10 @@ android:title="Add a parks layer" mapbox:showAsAction="never" /> <item + android:id="@+id/action_add_dynamic_parks_layer" + android:title="Add a dynamic geojson source" + mapbox:showAsAction="never" /> + <item android:id="@+id/action_remove_layer" android:title="Remove buildings layer" mapbox:showAsAction="never" /> |