Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/src/main/java/com/google/maps/android/data/Layer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public class KmlLayer : Layer {
override val features: Iterable<KmlPlacemark>
get() = mPlacemarks

public fun isLayerOnMap(): Boolean = mIsLayerOnMap
override fun isLayerOnMap(): Boolean = mIsLayerOnMap

override fun setOnFeatureClickListener(listener: OnFeatureClickListener) {
mFeatureClickListener = listener
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GoogleMap>(relaxed = true), emptyFeatureCollection)

assertFalse(layer.isLayerOnMap())
}

@Test
fun isLayerOnMap_reflectsAddAndRemove() {
val layer = GeoJsonLayer(mockk<GoogleMap>(relaxed = true), emptyFeatureCollection)

assertFalse(layer.isLayerOnMap())

layer.addLayerToMap()
assertTrue(layer.isLayerOnMap())

layer.removeLayerFromMap()
assertFalse(layer.isLayerOnMap())
}
}
Original file line number Diff line number Diff line change
@@ -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 =
"""
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document/>
</kml>
""".trimIndent()

private fun newLayer(): KmlLayer {
val context = ApplicationProvider.getApplicationContext<Context>()
return KmlLayer(mockk<GoogleMap>(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())
}
}