Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #5852 - example
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Aug 3, 2016
1 parent 956bbe9 commit 7959277
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.FillLayer;
import com.mapbox.mapboxsdk.style.layers.Function;
import com.mapbox.mapboxsdk.style.layers.Layer;
Expand All @@ -24,6 +25,7 @@
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.style.sources.RasterSource;
import com.mapbox.mapboxsdk.style.sources.Source;
Expand All @@ -38,6 +40,11 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import static com.mapbox.mapboxsdk.style.layers.Filter.*;
import static com.mapbox.mapboxsdk.style.layers.Function.*;
Expand Down Expand Up @@ -149,6 +156,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_add_custom_tiles:
addCustomTileSource();
return true;
case R.id.action_add_clustered_points:
addClusteredGeoJsonSource();
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -252,6 +262,58 @@ private void addParksLayer() {
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
}

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"))
.withCluster(true)
.withClusterMaxZoom(14)
.withClusterRadius(50)
);
} catch (MalformedURLException e) {
Log.e(TAG, "That's not an url... " + e.getMessage());
}

//Add unclustered layer
int[][] layers = new int[][]{
new int[]{150, Color.RED},
new int[]{20, Color.GREEN},
new int[]{0, Color.BLUE}
};

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)
);
mapboxMap.addLayer(count);


//Zoom out to start
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1));
}

private void addTerrainLayer() {
//Add a source
Source source = new VectorSource("my-terrain-source", "mapbox://mapbox.mapbox-terrain-v2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@
android:id="@+id/action_add_custom_tiles"
android:title="Custom tiles"
mapbox:showAsAction="never"/>
<item
android:id="@+id/action_add_clustered_points"
android:title="Clustered GeoJson source"
mapbox:showAsAction="never"/>
</menu>

0 comments on commit 7959277

Please sign in to comment.