Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Remove layers first when clearing the style #15191

Merged
merged 1 commit into from
Jul 22, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,20 @@ public Light getLight() {
*/
void clear() {
fullyLoaded = false;
for (Source source : sources.values()) {
if (source != null) {
source.setDetached();
nativeMap.removeSource(source);
}
}

for (Layer layer : layers.values()) {
if (layer != null) {
layer.setDetached();
nativeMap.removeLayer(layer);
}
}

for (Source source : sources.values()) {
if (source != null) {
source.setDetached();
nativeMap.removeSource(source);
}
}

for (Map.Entry<String, Bitmap> bitmapEntry : images.entrySet()) {
nativeMap.removeImage(bitmapEntry.getKey());
bitmapEntry.getValue().recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import io.mockk.*
import org.junit.Assert
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -408,4 +405,22 @@ class StyleTest {
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
}
}

@Test
fun testClearRemovesSourcesFirst() {
val source1 = mockk<GeoJsonSource>(relaxed = true)
every { source1.id } returns "source1"
val layer1 = mockk<SymbolLayer>(relaxed = true)
every { layer1.id } returns "layer1"

val builder = Style.Builder().withLayer(layer1).withSource(source1)
mapboxMap.setStyle(builder)
mapboxMap.notifyStyleLoaded()
mapboxMap.setStyle(Style.MAPBOX_STREETS)

verifyOrder {
nativeMapView.removeLayer(layer1)
nativeMapView.removeSource(source1)
}
}
}