[android] remove layers first when clearing the style
This commit is contained in:
committed by
Łukasz Paczos
parent
e582a329ef
commit
dabf5d0c3a
@@ -518,13 +518,6 @@ public class Style {
|
||||
*/
|
||||
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();
|
||||
@@ -532,6 +525,13 @@ public class Style {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user