4040import com .google .android .gms .maps .model .FeatureStyle ;
4141import com .google .android .gms .maps .model .FeatureType ;
4242import com .google .android .gms .maps .model .LatLng ;
43+ import com .google .android .gms .maps .model .LatLngBounds ;
4344import com .google .android .gms .maps .model .MapCapabilities ;
4445
4546import java .util .List ;
@@ -58,8 +59,7 @@ public class DataDrivenDatasetStylingActivity extends SamplesBaseActivity implem
5859 private record DataSet (
5960 String label ,
6061 String datasetId ,
61- LatLng location ,
62- float zoomLevel ,
62+ LatLngBounds bounds ,
6363 DataDrivenDatasetStylingActivity .DataSet .StylingCallback callback ) {
6464 public interface StylingCallback {
6565 void styleDatasetLayer ();
@@ -71,25 +71,19 @@ public interface StylingCallback {
7171 * Each DataSet contains:
7272 * - A human-readable name (e.g., "Boulder", "New York").
7373 * - A unique Dataset ID, which should correspond to a dataset id in the Datasets console tab.
74- * - The central latitude and longitude coordinates (LatLng) of the location .
74+ * - The LatLngBounds of the dataset area .
7575 * - A styling function (method reference) that defines how to style the data from that dataset on a map.
76- * <p>
77- * This array is used to configure which datasets are available for display and how they should be presented.
78- * Each element of the array should be a new DataSet object.
79- * Modify the constructor arguments of each DataSet to define your specific data and styles.
80- * The styling function will receive a `Layer` to which it can add elements.
81- * <p>
82- * Example:
83- * - `new DataSet("Boulder", "Boulder-DataSet-Id", new LatLng(40.0150, -105.2705), this::styleBoulderDatasetLayer)`
84- * This creates a DataSet for Boulder, identified by "Boulder-DataSet-Id", centered on the given coordinates,
85- * and styled using the `styleBoulderDatasetLayer` method.
86- * <p>
87- * Note: We have use the secrets plugin to allow us to configure the Dataset IDs in our secrets.properties file.
8876 */
8977 private final DataSet [] dataSets = new DataSet [] {
90- new DataSet ("Boulder" , BuildConfig .BOULDER_DATASET_ID , new LatLng (40.0150 , -105.2705 ), 11f , this ::styleBoulderDatasetLayer ),
91- new DataSet ("New York" , BuildConfig .NEW_YORK_DATASET_ID , new LatLng (40.786244 , -73.962684 ), 14f , this ::styleNYCDatasetLayer ),
92- new DataSet ("Kyoto" , BuildConfig .KYOTO_DATASET_ID , new LatLng (35.005081 , 135.764385 ), 13.5f , this ::styleKyotoDatasetsLayer ),
78+ new DataSet ("Boulder" , BuildConfig .BOULDER_DATASET_ID ,
79+ new LatLngBounds (new LatLng (39.920 , -105.340 ), new LatLng (40.090 , -105.210 )),
80+ this ::styleBoulderDatasetLayer ),
81+ new DataSet ("New York" , BuildConfig .NEW_YORK_DATASET_ID ,
82+ new LatLngBounds (new LatLng (40.7640 , -73.9820 ), new LatLng (40.8000 , -73.9490 )),
83+ this ::styleNYCDatasetLayer ),
84+ new DataSet ("Kyoto" , BuildConfig .KYOTO_DATASET_ID ,
85+ new LatLngBounds (new LatLng (34.9700 , 135.7200 ), new LatLng (35.0400 , 135.8000 )),
86+ this ::styleKyotoDatasetsLayer ),
9387 };
9488
9589 private DataSet findDataSetByLabel (String label ) {
@@ -176,14 +170,19 @@ private void switchDataSet(String label) {
176170 .build ()
177171 );
178172 dataSet .callback .styleDatasetLayer ();
179- centerMapOnLocation (dataSet .location (), dataSet . zoomLevel ());
173+ centerMapOnBounds (dataSet .bounds ());
180174 }
181175 }
182176
183177 @ Override
184178 public void onMapReady (@ NonNull GoogleMap googleMap ) {
185179 this .map = googleMap ;
186180
181+ googleMap .setOnCameraIdleListener (() -> {
182+ com .google .android .gms .maps .model .CameraPosition cp = googleMap .getCameraPosition ();
183+ Log .i (TAG , "CAMERA_PARAMS: target=LatLng(" + cp .target .latitude + ", " + cp .target .longitude + "), zoom=" + cp .zoom + "f, tilt=" + cp .tilt + "f, bearing=" + cp .bearing + "f" );
184+ });
185+
187186 MapCapabilities capabilities = map .getMapCapabilities ();
188187 Log .d (TAG , "Data-driven Styling is available: " + capabilities .isDataDrivenStylingAvailable ());
189188 if (!capabilities .isDataDrivenStylingAvailable ()) {
@@ -364,8 +363,8 @@ private void styleBoulderDatasetLayer() {
364363 }
365364
366365
367- private void centerMapOnLocation ( LatLng location , float zoomLevel ) {
368- map .moveCamera (CameraUpdateFactory .newLatLngZoom ( location , zoomLevel ));
366+ private void centerMapOnBounds ( LatLngBounds bounds ) {
367+ map .animateCamera (CameraUpdateFactory .newLatLngBounds ( bounds , 80 ));
369368 }
370369
371370 @ Override
0 commit comments