diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 0a27cd34a..834f872e8 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -348,6 +348,14 @@ android:name="@string/category" android:value="@string/category_style" /> + + + 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)); + mapboxMap.addSource(new GeoJsonSource("point", FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)}))); + + //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)); + GeoJsonSource source = mapboxMap.getSourceAs("point"); + 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 + 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_add_sprite.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_add_sprite.xml new file mode 100644 index 000000000..086b18fea --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_add_sprite.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index f3ff51840..128ac715a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -65,6 +65,7 @@ Count features in box Highlight features in box Add Circle + Add Custom Sprite Android SDK View integration Video View @@ -107,6 +108,7 @@ Use SupportMapFragments in a ViewPager Adopt the map style on the fly Use GeoJson source to show a circle + Use a custom sprite in a Symbol Layer Use GeoJson sources and dynamic layers to cluster information Shows how to print a map Test animation of Android SDK View components