From ea19c08dbbcf65246aa1884f63f822cf3b372f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Lo=CC=81pez=20Man=CC=83as?= Date: Tue, 11 Aug 2026 21:33:52 +0700 Subject: [PATCH] fix: restore isLayerOnMap() as abstract member of Layer The v5 rewrite dropped isLayerOnMap() from the Layer base class while keeping it as separate identical implementations in GeoJsonLayer and KmlLayer, so callers holding a Layer reference lost access to it. Fixes #1746 --- .../com/google/maps/android/data/Layer.kt | 2 + .../maps/android/data/geojson/GeoJsonLayer.kt | 2 +- .../google/maps/android/data/kml/KmlLayer.kt | 2 +- .../data/geojson/GeoJsonLayerOnMapTest.kt | 57 +++++++++++++++++ .../android/data/kml/KmlLayerOnMapTest.kt | 64 +++++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 data/src/test/java/com/google/maps/android/data/geojson/GeoJsonLayerOnMapTest.kt create mode 100644 data/src/test/java/com/google/maps/android/data/kml/KmlLayerOnMapTest.kt diff --git a/data/src/main/java/com/google/maps/android/data/Layer.kt b/data/src/main/java/com/google/maps/android/data/Layer.kt index 0ae01ff74..2c1cb85aa 100644 --- a/data/src/main/java/com/google/maps/android/data/Layer.kt +++ b/data/src/main/java/com/google/maps/android/data/Layer.kt @@ -41,6 +41,8 @@ public abstract class Layer { public abstract fun removeLayerFromMap() + public abstract fun isLayerOnMap(): Boolean + public fun interface OnFeatureClickListener { public fun onFeatureClick(feature: Feature) } diff --git a/data/src/main/java/com/google/maps/android/data/geojson/GeoJsonLayer.kt b/data/src/main/java/com/google/maps/android/data/geojson/GeoJsonLayer.kt index 51bebf846..7de77a530 100644 --- a/data/src/main/java/com/google/maps/android/data/geojson/GeoJsonLayer.kt +++ b/data/src/main/java/com/google/maps/android/data/geojson/GeoJsonLayer.kt @@ -457,7 +457,7 @@ public class GeoJsonLayer : Layer { public fun getBoundingBox(): LatLngBounds? = mBoundingBox - public fun isLayerOnMap(): Boolean = mIsLayerOnMap + override fun isLayerOnMap(): Boolean = mIsLayerOnMap override fun toString(): String = StringBuilder("Collection{") diff --git a/data/src/main/java/com/google/maps/android/data/kml/KmlLayer.kt b/data/src/main/java/com/google/maps/android/data/kml/KmlLayer.kt index f6bcf221c..9097cb690 100644 --- a/data/src/main/java/com/google/maps/android/data/kml/KmlLayer.kt +++ b/data/src/main/java/com/google/maps/android/data/kml/KmlLayer.kt @@ -509,7 +509,7 @@ public class KmlLayer : Layer { override val features: Iterable get() = mPlacemarks - public fun isLayerOnMap(): Boolean = mIsLayerOnMap + override fun isLayerOnMap(): Boolean = mIsLayerOnMap override fun setOnFeatureClickListener(listener: OnFeatureClickListener) { mFeatureClickListener = listener diff --git a/data/src/test/java/com/google/maps/android/data/geojson/GeoJsonLayerOnMapTest.kt b/data/src/test/java/com/google/maps/android/data/geojson/GeoJsonLayerOnMapTest.kt new file mode 100644 index 000000000..32e54b979 --- /dev/null +++ b/data/src/test/java/com/google/maps/android/data/geojson/GeoJsonLayerOnMapTest.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.maps.android.data.geojson + +import com.google.android.gms.maps.GoogleMap +import com.google.maps.android.data.Layer +import io.mockk.mockk +import org.json.JSONObject +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +/** Regression test for https://github.com/googlemaps/android-maps-utils/issues/1746. */ +@RunWith(RobolectricTestRunner::class) +class GeoJsonLayerOnMapTest { + private val emptyFeatureCollection = + JSONObject( + """ + { "type": "FeatureCollection", "features": [] } + """.trimIndent(), + ) + + @Test + fun isLayerOnMap_isExposedThroughLayerBaseClass() { + val layer: Layer = GeoJsonLayer(mockk(relaxed = true), emptyFeatureCollection) + + assertFalse(layer.isLayerOnMap()) + } + + @Test + fun isLayerOnMap_reflectsAddAndRemove() { + val layer = GeoJsonLayer(mockk(relaxed = true), emptyFeatureCollection) + + assertFalse(layer.isLayerOnMap()) + + layer.addLayerToMap() + assertTrue(layer.isLayerOnMap()) + + layer.removeLayerFromMap() + assertFalse(layer.isLayerOnMap()) + } +} diff --git a/data/src/test/java/com/google/maps/android/data/kml/KmlLayerOnMapTest.kt b/data/src/test/java/com/google/maps/android/data/kml/KmlLayerOnMapTest.kt new file mode 100644 index 000000000..16effa6ec --- /dev/null +++ b/data/src/test/java/com/google/maps/android/data/kml/KmlLayerOnMapTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.maps.android.data.kml + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import com.google.android.gms.maps.GoogleMap +import com.google.maps.android.data.Layer +import io.mockk.mockk +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +/** Regression test for https://github.com/googlemaps/android-maps-utils/issues/1746. */ +@RunWith(RobolectricTestRunner::class) +class KmlLayerOnMapTest { + private val emptyKml = + """ + + + + + """.trimIndent() + + private fun newLayer(): KmlLayer { + val context = ApplicationProvider.getApplicationContext() + return KmlLayer(mockk(relaxed = true), emptyKml.byteInputStream(), context) + } + + @Test + fun isLayerOnMap_isExposedThroughLayerBaseClass() { + val layer: Layer = newLayer() + + assertFalse(layer.isLayerOnMap()) + } + + @Test + fun isLayerOnMap_reflectsAddAndRemove() { + val layer = newLayer() + + assertFalse(layer.isLayerOnMap()) + + layer.addLayerToMap() + assertTrue(layer.isLayerOnMap()) + + layer.removeLayerFromMap() + assertFalse(layer.isLayerOnMap()) + } +}