From 97722e755527339f0b16eb5dbd052d8e4f10342a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Wed, 13 Nov 2019 14:30:03 +0100 Subject: [PATCH] add collection and style smooth reload example --- .../src/main/AndroidManifest.xml | 11 ++ .../style/CollectionUpdateOnStyleChange.kt | 135 ++++++++++++++++++ ...vity_collection_update_on_style_change.xml | 24 ++++ .../src/main/res/values/descriptions.xml | 1 + .../src/main/res/values/titles.xml | 1 + 5 files changed, 172 insertions(+) create mode 100644 MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CollectionUpdateOnStyleChange.kt create mode 100644 MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_collection_update_on_style_change.xml diff --git a/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 73c9b97f2..e29f6e74c 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -484,6 +484,17 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity" /> + + + + (R.id.fabStyles) + fabStyles.setOnClickListener { + currentStyleIndex++ + if (currentStyleIndex == STYLES.size) { + currentStyleIndex = 0 + } + mapboxMap.setStyle(Style.Builder().fromUri(STYLES[currentStyleIndex]), this) + } + } + + override fun onStart() { + super.onStart() + mapView.onStart() + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onStop() { + super.onStop() + mapView.onStop() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } + + override fun onLowMemory() { + super.onLowMemory() + mapView.onLowMemory() + } + + companion object { + + private val STYLES = arrayOf(Style.MAPBOX_STREETS, Style.OUTDOORS, Style.LIGHT, Style.DARK, Style.SATELLITE, Style.SATELLITE_STREETS, Style.TRAFFIC_DAY, Style.TRAFFIC_NIGHT) + + private val featureCollection: FeatureCollection + + init { + val bounds = LatLngBounds.from(60.0, 100.0, -60.0, -100.0) + val points = ArrayList() + for (i in 0 until 1000) { + val latLng = getLatLngInBounds(bounds) + points.add(Point.fromLngLat(latLng.longitude, latLng.latitude)) + } + featureCollection = FeatureCollection.fromFeature(Feature.fromGeometry(LineString.fromLngLats(points))) + } + + private fun getLatLngInBounds(bounds: LatLngBounds): LatLng { + val generator = Random() + val randomLat = bounds.latSouth + generator.nextDouble() * (bounds.latNorth - bounds.latSouth) + val randomLon = bounds.lonWest + generator.nextDouble() * (bounds.lonEast - bounds.lonWest) + return LatLng(randomLat, randomLon) + } + } +} \ No newline at end of file diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_collection_update_on_style_change.xml b/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_collection_update_on_style_change.xml new file mode 100644 index 000000000..22f99c1e6 --- /dev/null +++ b/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_collection_update_on_style_change.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index 7f018a43f..075949be5 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -50,6 +50,7 @@ Use a local file as the style Display a map inside a dialog fragment Show bus stops and route in Singapore + Verify that updating the GeoJsonSource across style changes allows for smooth transitions Transform urls on the fly Control the cache management with FileSource API Limit viewport to Iceland diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 90baaed28..0a0166945 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -34,6 +34,7 @@ Gradient line layer Data Driven Style Circle layer + Collection updates on style changes Local Style file GeoJson Clustering Add live realtime data